submenu.ts 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import angular from 'angular';
  3. import _ from 'lodash';
  4. export class SubmenuCtrl {
  5. annotations: any;
  6. variables: any;
  7. dashboard: any;
  8. /** @ngInject */
  9. constructor(private $rootScope,
  10. private templateValuesSrv,
  11. private templateSrv,
  12. private dynamicDashboardSrv,
  13. private $location) {
  14. this.annotations = this.dashboard.templating.list;
  15. this.variables = this.dashboard.templating.list;
  16. }
  17. disableAnnotation(annotation) {
  18. annotation.enable = !annotation.enable;
  19. this.$rootScope.$broadcast('refresh');
  20. }
  21. getValuesForTag(variable, tagKey) {
  22. return this.templateValuesSrv.getValuesForTag(variable, tagKey);
  23. }
  24. updateUrlParamsWithCurrentVariables() {
  25. // update url
  26. var params = this.$location.search();
  27. // remove variable params
  28. _.each(params, function(value, key) {
  29. if (key.indexOf('var-') === 0) {
  30. delete params[key];
  31. }
  32. });
  33. // add new values
  34. this.templateSrv.fillVariableValuesForUrl(params);
  35. // update url
  36. this.$location.search(params);
  37. }
  38. variableUpdated(variable) {
  39. this.templateValuesSrv.variableUpdated(variable).then(() => {
  40. this.updateUrlParamsWithCurrentVariables();
  41. this.dynamicDashboardSrv.update(this.dashboard);
  42. this.$rootScope.$emit('template-variable-value-updated');
  43. this.$rootScope.$broadcast('refresh');
  44. });
  45. }
  46. }
  47. export function submenuDirective() {
  48. return {
  49. restrict: 'E',
  50. templateUrl: 'public/app/features/dashboard/submenu/submenu.html',
  51. controller: SubmenuCtrl,
  52. bindToController: true,
  53. controllerAs: 'ctrl',
  54. scope: {
  55. dashboard: "=",
  56. }
  57. };
  58. }
  59. angular.module('grafana.directives').directive('dashboardSubmenu', submenuDirective);