styleguide.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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'];
  13. /** @ngInject **/
  14. constructor(private $http, private $routeParams, private $location) {
  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. this.$location.search(this.$routeParams);
  44. setTimeout(() => {
  45. window.location.href = window.location.href;
  46. });
  47. }
  48. }
  49. coreModule.controller('StyleGuideCtrl', StyleGuideCtrl);