styleguide.ts 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import coreModule from 'app/core/core_module';
  2. import config from 'app/core/config';
  3. import _ from 'lodash';
  4. class StyleGuideCtrl {
  5. colors: any = [];
  6. theme: string;
  7. buttonNames = ['primary', 'secondary', 'inverse', 'success', 'warning', 'danger'];
  8. buttonSizes = ['btn-small', '', 'btn-large'];
  9. buttonVariants = ['-', '-outline-'];
  10. icons: any = [];
  11. page: any;
  12. pages = ['colors', 'buttons', 'icons', 'plugins'];
  13. navModel: any;
  14. /** @ngInject **/
  15. constructor(private $http, private $routeParams, private backendSrv, navModelSrv) {
  16. this.navModel = navModelSrv.getAdminNav();
  17. this.theme = config.bootData.user.lightTheme ? 'light': 'dark';
  18. this.page = {};
  19. if ($routeParams.page) {
  20. this.page[$routeParams.page] = 1;
  21. } else {
  22. this.page.colors = true;
  23. }
  24. if (this.page.colors) {
  25. this.loadColors();
  26. }
  27. if (this.page.icons) {
  28. this.loadIcons();
  29. }
  30. }
  31. loadColors() {
  32. this.$http.get('public/build/styleguide.json').then(res => {
  33. this.colors = _.map(res.data[this.theme], (value, key) => {
  34. return {name: key, value: value};
  35. });
  36. });
  37. }
  38. loadIcons() {
  39. this.$http.get('public/sass/icons.json').then(res => {
  40. this.icons = res.data;
  41. });
  42. }
  43. switchTheme() {
  44. this.$routeParams.theme = this.theme === 'dark' ? 'light' : 'dark';
  45. var cmd = {
  46. theme: this.$routeParams.theme
  47. };
  48. this.backendSrv.put('/api/user/preferences', cmd).then(() => {
  49. window.location.href = window.location.href;
  50. });
  51. }
  52. }
  53. coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);