styleguide.ts 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. /** @ngInject **/
  14. constructor(private $http, private $routeParams, private $location, private backendSrv) {
  15. this.theme = config.bootData.user.lightTheme ? 'light': 'dark';
  16. this.page = {};
  17. if ($routeParams.page) {
  18. this.page[$routeParams.page] = 1;
  19. } else {
  20. this.page.colors = true;
  21. }
  22. if (this.page.colors) {
  23. this.loadColors();
  24. }
  25. if (this.page.icons) {
  26. this.loadIcons();
  27. }
  28. }
  29. loadColors() {
  30. this.$http.get('public/sass/styleguide.json').then(res => {
  31. this.colors = _.map(res.data[this.theme], (value, key) => {
  32. return {name: key, value: value};
  33. });
  34. });
  35. }
  36. loadIcons() {
  37. this.$http.get('public/sass/icons.json').then(res => {
  38. this.icons = res.data;
  39. });
  40. }
  41. switchTheme() {
  42. this.$routeParams.theme = this.theme === 'dark' ? 'light' : 'dark';
  43. var cmd = {
  44. theme: this.$routeParams.theme
  45. };
  46. this.backendSrv.put('/api/user/preferences', cmd).then(() => {
  47. window.location.href = window.location.href;
  48. });
  49. }
  50. }
  51. coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);