2017-12-21 01:39:31 -06:00
|
|
|
import coreModule from 'app/core/core_module';
|
2019-03-19 08:28:15 -05:00
|
|
|
import config from 'app/core/config';
|
|
|
|
import tinycolor from 'tinycolor2';
|
2016-08-12 06:19:06 -05:00
|
|
|
export class ThresholdFormCtrl {
|
|
|
|
panelCtrl: any;
|
|
|
|
panel: any;
|
|
|
|
disabled: boolean;
|
|
|
|
|
|
|
|
/** @ngInject */
|
|
|
|
constructor($scope) {
|
|
|
|
this.panel = this.panelCtrl.panel;
|
|
|
|
|
2016-09-30 10:37:47 -05:00
|
|
|
if (this.panel.alert) {
|
2016-08-12 06:19:06 -05:00
|
|
|
this.disabled = true;
|
|
|
|
}
|
|
|
|
|
2018-08-29 07:27:29 -05:00
|
|
|
const unbindDestroy = $scope.$on('$destroy', () => {
|
2016-08-12 06:19:06 -05:00
|
|
|
this.panelCtrl.editingThresholds = false;
|
|
|
|
this.panelCtrl.render();
|
2016-10-30 09:14:18 -05:00
|
|
|
unbindDestroy();
|
2016-08-12 06:19:06 -05:00
|
|
|
});
|
|
|
|
|
|
|
|
this.panelCtrl.editingThresholds = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
addThreshold() {
|
2017-12-19 09:06:54 -06:00
|
|
|
this.panel.thresholds.push({
|
|
|
|
value: undefined,
|
2017-12-21 01:39:31 -06:00
|
|
|
colorMode: 'critical',
|
|
|
|
op: 'gt',
|
2017-12-19 09:06:54 -06:00
|
|
|
fill: true,
|
2017-12-21 01:39:31 -06:00
|
|
|
line: true,
|
2018-02-08 01:53:02 -06:00
|
|
|
yaxis: 'left',
|
2017-12-19 09:06:54 -06:00
|
|
|
});
|
2016-08-12 06:19:06 -05:00
|
|
|
this.panelCtrl.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
removeThreshold(index) {
|
|
|
|
this.panel.thresholds.splice(index, 1);
|
|
|
|
this.panelCtrl.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
|
|
this.panelCtrl.render();
|
|
|
|
}
|
2017-10-09 06:54:14 -05:00
|
|
|
|
|
|
|
onFillColorChange(index) {
|
2017-12-19 09:06:54 -06:00
|
|
|
return newColor => {
|
2017-10-09 06:54:14 -05:00
|
|
|
this.panel.thresholds[index].fillColor = newColor;
|
|
|
|
this.render();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
onLineColorChange(index) {
|
2017-12-19 09:06:54 -06:00
|
|
|
return newColor => {
|
2017-10-09 06:54:14 -05:00
|
|
|
this.panel.thresholds[index].lineColor = newColor;
|
|
|
|
this.render();
|
|
|
|
};
|
|
|
|
}
|
2019-03-19 08:28:15 -05:00
|
|
|
|
|
|
|
onThresholdTypeChange(index) {
|
|
|
|
// Because of the ng-model binding, threshold's color mode is already set here
|
|
|
|
if (this.panel.thresholds[index].colorMode === 'custom') {
|
|
|
|
this.panel.thresholds[index].fillColor = tinycolor(config.theme.colors.blueBase)
|
|
|
|
.setAlpha(0.2)
|
|
|
|
.toRgbString();
|
|
|
|
this.panel.thresholds[index].lineColor = tinycolor(config.theme.colors.blueShade)
|
|
|
|
.setAlpha(0.6)
|
|
|
|
.toRgbString();
|
|
|
|
}
|
|
|
|
this.panelCtrl.render();
|
|
|
|
}
|
2016-08-12 06:19:06 -05:00
|
|
|
}
|
|
|
|
|
2018-09-04 07:27:03 -05:00
|
|
|
coreModule.directive('graphThresholdForm', () => {
|
2016-08-12 06:19:06 -05:00
|
|
|
return {
|
2017-12-21 01:39:31 -06:00
|
|
|
restrict: 'E',
|
2018-06-21 07:41:47 -05:00
|
|
|
templateUrl: 'public/app/plugins/panel/graph/thresholds_form.html',
|
2016-08-12 06:19:06 -05:00
|
|
|
controller: ThresholdFormCtrl,
|
|
|
|
bindToController: true,
|
2017-12-21 01:39:31 -06:00
|
|
|
controllerAs: 'ctrl',
|
2016-08-12 06:19:06 -05:00
|
|
|
scope: {
|
2017-12-21 01:39:31 -06:00
|
|
|
panelCtrl: '=',
|
|
|
|
},
|
2016-08-12 06:19:06 -05:00
|
|
|
};
|
|
|
|
});
|