settings.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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($scope, private $location, private $rootScope) {
  21. // temp hack
  22. $scope.dashboard = this.dashboard;
  23. const params = this.$location.search();
  24. const url = $location.path();
  25. for (let section of this.sections) {
  26. const sectionParams = _.defaults({editview: section.id}, params);
  27. section.url = url + '?' + $.param(sectionParams);
  28. console.log(section.url);
  29. }
  30. this.viewId = params.editview;
  31. $rootScope.onAppEvent("$routeUpdate", this.onRouteUpdated.bind(this), $scope);
  32. }
  33. onRouteUpdated() {
  34. console.log('settings route updated');
  35. this.viewId = this.$location.search().editview;
  36. }
  37. hideSettings() {
  38. var urlParams = this.$location.search();
  39. delete urlParams.editview;
  40. setTimeout(() => {
  41. this.$rootScope.$apply(() => {
  42. this.$location.search(urlParams);
  43. });
  44. });
  45. }
  46. }
  47. export function dashboardSettings() {
  48. return {
  49. restrict: 'E',
  50. templateUrl: 'public/app/features/dashboard/settings/settings.html',
  51. controller: SettingsCtrl,
  52. bindToController: true,
  53. controllerAs: 'ctrl',
  54. transclude: true,
  55. scope: { dashboard: "=" }
  56. };
  57. }
  58. coreModule.directive('dashboardSettings', dashboardSettings);