Files
grafana/public/app/features/styleguide/styleguide.ts

67 lines
1.6 KiB
TypeScript
Raw Normal View History

2016-02-18 16:05:15 +01:00
import coreModule from 'app/core/core_module';
import config from 'app/core/config';
import _ from 'lodash';
2016-02-18 16:05:15 +01:00
class StyleGuideCtrl {
colors: any = [];
theme: string;
2016-02-20 11:05:06 +01:00
buttonNames = ['primary', 'secondary', 'inverse', 'success', 'warning', 'danger'];
buttonSizes = ['btn-small', '', 'btn-large'];
buttonVariants = ['-', '-outline-'];
2017-05-02 15:50:10 +03:00
icons: any = [];
2016-02-20 11:32:50 +01:00
page: any;
pages = ['colors', 'buttons', 'icons', 'plugins'];
navModel: any;
/** @ngInject **/
constructor(private $http, private $routeParams, private backendSrv, navModelSrv) {
2017-08-16 11:28:52 +02:00
this.navModel = navModelSrv.getNav('cfg', 'admin', 'styleguide');
this.theme = config.bootData.user.lightTheme ? 'light': 'dark';
2016-02-20 11:32:50 +01:00
this.page = {};
2016-02-20 11:32:50 +01:00
if ($routeParams.page) {
this.page[$routeParams.page] = 1;
} else {
this.page.colors = true;
}
if (this.page.colors) {
this.loadColors();
}
2017-05-02 15:50:10 +03:00
if (this.page.icons) {
this.loadIcons();
}
2016-02-20 11:32:50 +01:00
}
loadColors() {
this.$http.get('public/build/styleguide.json').then(res => {
this.colors = _.map(res.data[this.theme], (value, key) => {
return {name: key, value: value};
});
});
}
2016-02-18 16:05:15 +01:00
2017-05-02 15:50:10 +03:00
loadIcons() {
this.$http.get('public/sass/icons.json').then(res => {
this.icons = res.data;
});
}
2016-02-18 16:05:15 +01:00
switchTheme() {
this.$routeParams.theme = this.theme === 'dark' ? 'light' : 'dark';
2017-05-02 16:45:34 +03:00
var cmd = {
theme: this.$routeParams.theme
};
this.backendSrv.put('/api/user/preferences', cmd).then(() => {
window.location.href = window.location.href;
});
2016-02-18 16:05:15 +01:00
}
}
coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);