settings.ts 1.6 KB

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