settings.ts 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import {coreModule} from 'app/core/core';
  2. import {DashboardModel} from '../dashboard_model';
  3. import $ from 'jquery';
  4. import _ from 'lodash';
  5. export class SettingsCtrl {
  6. dashboard: DashboardModel;
  7. isOpen: boolean;
  8. viewId: string;
  9. sections: any[] = [
  10. {title: 'General', id: 'settings', icon: "fa fa-fw fa-sliders"},
  11. {title: 'Annotations', id: 'annotations', icon: "fa fa-fw fa-comment-o"},
  12. {title: 'Variables', id: 'templating', icon: "fa fa-fw fa-dollar"},
  13. {title: 'Links', id: 'links', icon: "fa fa-fw fa-external-link"},
  14. {title: 'Versions', id: 'versions', icon: "fa fa-fw fa-history"},
  15. {title: 'View JSON', id: 'view_json', icon: "fa fa-fw fa-code"},
  16. {title: 'Save As', id: 'save_as', icon: "fa fa-fw fa-copy"},
  17. {title: 'Delete', id: 'delete', icon: "fa fa-fw fa-trash"},
  18. ];
  19. /** @ngInject */
  20. constructor(private $scope, private $location, private $rootScope) {
  21. // temp hack for annotations and variables editors
  22. // that rely on inherited scope
  23. $scope.dashboard = this.dashboard;
  24. const params = this.$location.search();
  25. const url = $location.path();
  26. for (let section of this.sections) {
  27. const sectionParams = _.defaults({editview: section.id}, params);
  28. section.url = url + '?' + $.param(sectionParams);
  29. console.log(section.url);
  30. }
  31. this.viewId = params.editview;
  32. $rootScope.onAppEvent("$routeUpdate", this.onRouteUpdated.bind(this), $scope);
  33. this.$scope.$on('$destroy', () => {
  34. this.dashboard.updateSubmenuVisibility();
  35. this.$rootScope.$broadcast("refresh");
  36. });
  37. }
  38. onRouteUpdated() {
  39. console.log('settings route updated');
  40. this.viewId = this.$location.search().editview;
  41. }
  42. hideSettings() {
  43. var urlParams = this.$location.search();
  44. delete urlParams.editview;
  45. setTimeout(() => {
  46. this.$rootScope.$apply(() => {
  47. this.$location.search(urlParams);
  48. });
  49. });
  50. }
  51. onFolderChange(folder) {
  52. this.dashboard.folderId = folder.id;
  53. this.dashboard.meta.folderId = folder.id;
  54. this.dashboard.meta.folderTitle= folder.title;
  55. }
  56. }
  57. export function dashboardSettings() {
  58. return {
  59. restrict: 'E',
  60. templateUrl: 'public/app/features/dashboard/settings/settings.html',
  61. controller: SettingsCtrl,
  62. bindToController: true,
  63. controllerAs: 'ctrl',
  64. transclude: true,
  65. scope: { dashboard: "=" }
  66. };
  67. }
  68. coreModule.directive('dashboardSettings', dashboardSettings);