settings.ts 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import {coreModule, appEvents} 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'},
  11. {title: 'Annotations', id: 'annotations'},
  12. {title: 'Templating', id: 'templating'},
  13. {title: 'Versions', id: 'versions'},
  14. ];
  15. /** @ngInject */
  16. constructor($scope, private $location, private $rootScope) {
  17. const params = this.$location.search();
  18. const url = $location.path();
  19. for (let section of this.sections) {
  20. const sectionParams = _.defaults({editview: section.id}, params);
  21. section.url = url + '?' + $.param(sectionParams);
  22. console.log(section.url);
  23. }
  24. this.viewId = params.editview;
  25. $rootScope.onAppEvent("$routeUpdate", this.onRouteUpdated.bind(this), $scope);
  26. }
  27. onRouteUpdated() {
  28. console.log('settings route updated');
  29. this.viewId = this.$location.search().editview;
  30. }
  31. hideSettings() {
  32. var urlParams = this.$location.search();
  33. delete urlParams.editview;
  34. setTimeout(() => {
  35. this.$rootScope.$apply(() => {
  36. this.$location.search(urlParams);
  37. });
  38. });
  39. }
  40. }
  41. export function dashboardSettings() {
  42. return {
  43. restrict: 'E',
  44. templateUrl: 'public/app/features/dashboard/settings/settings.html',
  45. controller: SettingsCtrl,
  46. bindToController: true,
  47. controllerAs: 'ctrl',
  48. transclude: true,
  49. scope: { dashboard: "=" }
  50. };
  51. }
  52. coreModule.directive('dashboardSettings', dashboardSettings);