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 {
|
2016-02-19 00:25:11 +08:00
|
|
|
colors: any = [];
|
|
|
|
|
theme: string;
|
2017-12-19 23:06:54 +08:00
|
|
|
buttonNames = [
|
2017-12-20 19:33:33 +08:00
|
|
|
'primary',
|
|
|
|
|
'secondary',
|
|
|
|
|
'inverse',
|
|
|
|
|
'success',
|
|
|
|
|
'warning',
|
|
|
|
|
'danger',
|
2017-12-19 23:06:54 +08:00
|
|
|
];
|
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'];
|
2017-06-02 20:00:42 +08:00
|
|
|
navModel: any;
|
2016-02-19 00:25:11 +08:00
|
|
|
|
|
|
|
|
/** @ngInject **/
|
2017-12-19 23:06:54 +08:00
|
|
|
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-19 00:25:11 +08:00
|
|
|
|
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();
|
|
|
|
|
}
|
2017-12-19 23:06:54 +08:00
|
|
|
}
|
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 => {
|
2016-02-19 00:25:11 +08:00
|
|
|
this.colors = _.map(res.data[this.theme], (value, key) => {
|
2017-12-19 23:06:54 +08:00
|
|
|
return { name: key, value: value };
|
2016-02-19 00:25:11 +08:00
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
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(() => {
|
2016-09-21 15:10:25 +08:00
|
|
|
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);
|