thresholds_form.ts 4.2 KB

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