thresholds_form.ts 4.2 KB

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