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

77 lines
1.6 KiB
TypeScript
Raw Normal View History

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