thresholds_form.ts 3.9 KB

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