thresholds_form.ts 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. var 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. var template = `
  51. <div class="gf-form-group">
  52. <h5>Thresholds</h5>
  53. <p class="muted" ng-show="ctrl.disabled">
  54. Visual thresholds options <strong>disabled.</strong>
  55. Visit the Alert tab update your thresholds. <br>
  56. To re-enable thresholds, the alert rule must be deleted from this panel.
  57. </p>
  58. <div ng-class="{'thresholds-form-disabled': ctrl.disabled}">
  59. <div class="gf-form-inline" ng-repeat="threshold in ctrl.panel.thresholds">
  60. <div class="gf-form">
  61. <label class="gf-form-label">T{{$index+1}}</label>
  62. </div>
  63. <div class="gf-form">
  64. <div class="gf-form-select-wrapper">
  65. <select class="gf-form-input" ng-model="threshold.op"
  66. ng-options="f for f in ['gt', 'lt']" ng-change="ctrl.render()" ng-disabled="ctrl.disabled"></select>
  67. </div>
  68. <input type="number" ng-model="threshold.value" class="gf-form-input width-8"
  69. ng-change="ctrl.render()" placeholder="value" ng-disabled="ctrl.disabled">
  70. </div>
  71. <div class="gf-form">
  72. <label class="gf-form-label">Color</label>
  73. <div class="gf-form-select-wrapper">
  74. <select class="gf-form-input" ng-model="threshold.colorMode"
  75. ng-options="f for f in ['custom', 'critical', 'warning', 'ok']" ng-change="ctrl.render()" ng-disabled="ctrl.disabled">
  76. </select>
  77. </div>
  78. </div>
  79. <gf-form-switch class="gf-form" label="Fill" checked="threshold.fill"
  80. on-change="ctrl.render()" ng-disabled="ctrl.disabled"></gf-form-switch>
  81. <div class="gf-form" ng-if="threshold.fill && threshold.colorMode === 'custom'">
  82. <label class="gf-form-label">Fill color</label>
  83. <span class="gf-form-label">
  84. <color-picker color="threshold.fillColor" onChange="ctrl.onFillColorChange($index)"></color-picker>
  85. </span>
  86. </div>
  87. <gf-form-switch class="gf-form" label="Line" checked="threshold.line"
  88. on-change="ctrl.render()" ng-disabled="ctrl.disabled"></gf-form-switch>
  89. <div class="gf-form" ng-if="threshold.line && threshold.colorMode === 'custom'">
  90. <label class="gf-form-label">Line color</label>
  91. <span class="gf-form-label">
  92. <color-picker color="threshold.lineColor" onChange="ctrl.onLineColorChange($index)"></color-picker>
  93. </span>
  94. </div>
  95. <div class="gf-form">
  96. <label class="gf-form-label">Y-axis</label>
  97. <div class="gf-form-select-wrapper">
  98. <select class="gf-form-input" ng-model="threshold.yaxis"
  99. ng-options="f for f in ['left', 'right']" ng-change="ctrl.render()" ng-disabled="ctrl.disabled">
  100. </select>
  101. </div>
  102. </div>
  103. <div class="gf-form">
  104. <label class="gf-form-label">
  105. <a class="pointer" ng-click="ctrl.removeThreshold($index)" ng-disabled="ctrl.disabled">
  106. <i class="fa fa-trash"></i>
  107. </a>
  108. </label>
  109. </div>
  110. </div>
  111. <div class="gf-form-button-row">
  112. <button class="btn btn-inverse" ng-click="ctrl.addThreshold()" ng-disabled="ctrl.disabled">
  113. <i class="fa fa-plus"></i>&nbsp;Add Threshold
  114. </button>
  115. </div>
  116. </div>
  117. </div>
  118. `;
  119. coreModule.directive('graphThresholdForm', function() {
  120. return {
  121. restrict: 'E',
  122. template: template,
  123. controller: ThresholdFormCtrl,
  124. bindToController: true,
  125. controllerAs: 'ctrl',
  126. scope: {
  127. panelCtrl: '=',
  128. },
  129. };
  130. });