thresholds_form.ts 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. ///<reference path="../../../headers/common.d.ts" />
  2. import coreModule from 'app/core/core_module';
  3. export class ThresholdFormCtrl {
  4. panelCtrl: any;
  5. panel: any;
  6. disabled: boolean;
  7. /** @ngInject */
  8. constructor($scope) {
  9. this.panel = this.panelCtrl.panel;
  10. if (this.panel.alert) {
  11. this.disabled = true;
  12. }
  13. var unbindDestroy = $scope.$on("$destroy", () => {
  14. this.panelCtrl.editingThresholds = false;
  15. this.panelCtrl.render();
  16. unbindDestroy();
  17. });
  18. this.panelCtrl.editingThresholds = true;
  19. }
  20. addThreshold() {
  21. this.panel.thresholds.push({value: undefined, colorMode: "critical", op: 'gt', fill: true, line: true});
  22. this.panelCtrl.render();
  23. }
  24. removeThreshold(index) {
  25. this.panel.thresholds.splice(index, 1);
  26. this.panelCtrl.render();
  27. }
  28. render() {
  29. this.panelCtrl.render();
  30. }
  31. }
  32. var template = `
  33. <div class="gf-form-group">
  34. <h5>Thresholds</h5>
  35. <p class="muted" ng-show="ctrl.disabled">
  36. Visual thresholds options <strong>disabled.</strong>
  37. Visit the Alert tab update your thresholds. <br>
  38. To re-enable thresholds, the alert rule must be deleted from this panel.
  39. </p>
  40. <div ng-class="{'thresholds-form-disabled': ctrl.disabled}">
  41. <div class="gf-form-inline" ng-repeat="threshold in ctrl.panel.thresholds">
  42. <div class="gf-form">
  43. <label class="gf-form-label">T{{$index+1}}</label>
  44. </div>
  45. <div class="gf-form">
  46. <div class="gf-form-select-wrapper">
  47. <select class="gf-form-input" ng-model="threshold.op"
  48. ng-options="f for f in ['gt', 'lt']" ng-change="ctrl.render()" ng-disabled="ctrl.disabled"></select>
  49. </div>
  50. <input type="number" ng-model="threshold.value" class="gf-form-input width-8"
  51. ng-change="ctrl.render()" placeholder="value" ng-disabled="ctrl.disabled">
  52. </div>
  53. <div class="gf-form">
  54. <label class="gf-form-label">Color</label>
  55. <div class="gf-form-select-wrapper">
  56. <select class="gf-form-input" ng-model="threshold.colorMode"
  57. ng-options="f for f in ['custom', 'critical', 'warning', 'ok']" ng-change="ctrl.render()" ng-disabled="ctrl.disabled">
  58. </select>
  59. </div>
  60. </div>
  61. <gf-form-switch class="gf-form" label="Fill" checked="threshold.fill"
  62. on-change="ctrl.render()" ng-disabled="ctrl.disabled"></gf-form-switch>
  63. <div class="gf-form" ng-if="threshold.fill && threshold.colorMode === 'custom'">
  64. <label class="gf-form-label">Fill color</label>
  65. <span class="gf-form-label">
  66. <spectrum-picker ng-model="threshold.fillColor" ng-change="ctrl.render()" ></spectrum-picker>
  67. </span>
  68. </div>
  69. <gf-form-switch class="gf-form" label="Line" checked="threshold.line"
  70. on-change="ctrl.render()" ng-disabled="ctrl.disabled"></gf-form-switch>
  71. <div class="gf-form" ng-if="threshold.line && threshold.colorMode === 'custom'">
  72. <label class="gf-form-label">Line color</label>
  73. <span class="gf-form-label">
  74. <spectrum-picker ng-model="threshold.lineColor" ng-change="ctrl.render()" ></spectrum-picker>
  75. </span>
  76. </div>
  77. <div class="gf-form">
  78. <label class="gf-form-label">
  79. <a class="pointer" ng-click="ctrl.removeThreshold($index)" ng-disabled="ctrl.disabled">
  80. <i class="fa fa-trash"></i>
  81. </a>
  82. </label>
  83. </div>
  84. </div>
  85. <div class="gf-form-button-row">
  86. <button class="btn btn-inverse" ng-click="ctrl.addThreshold()" ng-disabled="ctrl.disabled">
  87. <i class="fa fa-plus"></i>&nbsp;Add Threshold
  88. </button>
  89. </div>
  90. </div>
  91. </div>
  92. `;
  93. coreModule.directive('graphThresholdForm', function() {
  94. return {
  95. restrict: 'E',
  96. template: template,
  97. controller: ThresholdFormCtrl,
  98. bindToController: true,
  99. controllerAs: 'ctrl',
  100. scope: {
  101. panelCtrl: "="
  102. }
  103. };
  104. });