thresholds_form.ts 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. import coreModule from 'app/core/core_module';
  2. export class ThresholdFormCtrl {
  3. panelCtrl: any;
  4. panel: any;
  5. disabled: boolean;
  6. /** @ngInject */
  7. constructor($scope) {
  8. this.panel = this.panelCtrl.panel;
  9. if (this.panel.alert) {
  10. this.disabled = true;
  11. }
  12. const unbindDestroy = $scope.$on('$destroy', () => {
  13. this.panelCtrl.editingThresholds = false;
  14. this.panelCtrl.render();
  15. unbindDestroy();
  16. });
  17. this.panelCtrl.editingThresholds = true;
  18. }
  19. addThreshold() {
  20. this.panel.thresholds.push({
  21. value: undefined,
  22. colorMode: 'critical',
  23. op: 'gt',
  24. fill: true,
  25. line: true,
  26. yaxis: 'left',
  27. });
  28. this.panelCtrl.render();
  29. }
  30. removeThreshold(index) {
  31. this.panel.thresholds.splice(index, 1);
  32. this.panelCtrl.render();
  33. }
  34. render() {
  35. this.panelCtrl.render();
  36. }
  37. onFillColorChange(index) {
  38. return newColor => {
  39. this.panel.thresholds[index].fillColor = newColor;
  40. this.render();
  41. };
  42. }
  43. onLineColorChange(index) {
  44. return newColor => {
  45. this.panel.thresholds[index].lineColor = newColor;
  46. this.render();
  47. };
  48. }
  49. }
  50. coreModule.directive('graphThresholdForm', () => {
  51. return {
  52. restrict: 'E',
  53. templateUrl: 'public/app/plugins/panel/graph/thresholds_form.html',
  54. controller: ThresholdFormCtrl,
  55. bindToController: true,
  56. controllerAs: 'ctrl',
  57. scope: {
  58. panelCtrl: '=',
  59. },
  60. };
  61. });