thresholds_form.ts 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import coreModule from 'app/core/core_module';
  2. import config from 'app/core/config';
  3. import tinycolor from 'tinycolor2';
  4. export class ThresholdFormCtrl {
  5. panelCtrl: any;
  6. panel: any;
  7. disabled: boolean;
  8. /** @ngInject */
  9. constructor($scope) {
  10. this.panel = this.panelCtrl.panel;
  11. if (this.panel.alert) {
  12. this.disabled = true;
  13. }
  14. const unbindDestroy = $scope.$on('$destroy', () => {
  15. this.panelCtrl.editingThresholds = false;
  16. this.panelCtrl.render();
  17. unbindDestroy();
  18. });
  19. this.panelCtrl.editingThresholds = true;
  20. }
  21. addThreshold() {
  22. this.panel.thresholds.push({
  23. value: undefined,
  24. colorMode: 'critical',
  25. op: 'gt',
  26. fill: true,
  27. line: true,
  28. yaxis: 'left',
  29. });
  30. this.panelCtrl.render();
  31. }
  32. removeThreshold(index) {
  33. this.panel.thresholds.splice(index, 1);
  34. this.panelCtrl.render();
  35. }
  36. render() {
  37. this.panelCtrl.render();
  38. }
  39. onFillColorChange(index) {
  40. return newColor => {
  41. this.panel.thresholds[index].fillColor = newColor;
  42. this.render();
  43. };
  44. }
  45. onLineColorChange(index) {
  46. return newColor => {
  47. this.panel.thresholds[index].lineColor = newColor;
  48. this.render();
  49. };
  50. }
  51. onThresholdTypeChange(index) {
  52. // Because of the ng-model binding, threshold's color mode is already set here
  53. if (this.panel.thresholds[index].colorMode === 'custom') {
  54. this.panel.thresholds[index].fillColor = tinycolor(config.theme.colors.blueBase)
  55. .setAlpha(0.2)
  56. .toRgbString();
  57. this.panel.thresholds[index].lineColor = tinycolor(config.theme.colors.blueShade)
  58. .setAlpha(0.6)
  59. .toRgbString();
  60. }
  61. this.panelCtrl.render();
  62. }
  63. }
  64. coreModule.directive('graphThresholdForm', () => {
  65. return {
  66. restrict: 'E',
  67. templateUrl: 'public/app/plugins/panel/graph/thresholds_form.html',
  68. controller: ThresholdFormCtrl,
  69. bindToController: true,
  70. controllerAs: 'ctrl',
  71. scope: {
  72. panelCtrl: '=',
  73. },
  74. };
  75. });