mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
changed var to const (#13061)
This commit is contained in:
committed by
Torkel Ödegaard
parent
9423e3e124
commit
5e0d0c5816
@@ -1,7 +1,7 @@
|
||||
import _ from 'lodash';
|
||||
import { QueryPartDef, QueryPart } from 'app/core/components/query_part/query_part';
|
||||
|
||||
var alertQueryDef = new QueryPartDef({
|
||||
const alertQueryDef = new QueryPartDef({
|
||||
type: 'query',
|
||||
params: [
|
||||
{ name: 'queryRefId', type: 'string', dynamicLookup: true },
|
||||
@@ -15,9 +15,9 @@ var alertQueryDef = new QueryPartDef({
|
||||
defaultParams: ['#A', '15m', 'now', 'avg'],
|
||||
});
|
||||
|
||||
var conditionTypes = [{ text: 'Query', value: 'query' }];
|
||||
const conditionTypes = [{ text: 'Query', value: 'query' }];
|
||||
|
||||
var alertStateSortScore = {
|
||||
const alertStateSortScore = {
|
||||
alerting: 1,
|
||||
no_data: 2,
|
||||
pending: 3,
|
||||
@@ -25,7 +25,7 @@ var alertStateSortScore = {
|
||||
paused: 5,
|
||||
};
|
||||
|
||||
var evalFunctions = [
|
||||
const evalFunctions = [
|
||||
{ text: 'IS ABOVE', value: 'gt' },
|
||||
{ text: 'IS BELOW', value: 'lt' },
|
||||
{ text: 'IS OUTSIDE RANGE', value: 'outside_range' },
|
||||
@@ -33,9 +33,9 @@ var evalFunctions = [
|
||||
{ text: 'HAS NO VALUE', value: 'no_value' },
|
||||
];
|
||||
|
||||
var evalOperators = [{ text: 'OR', value: 'or' }, { text: 'AND', value: 'and' }];
|
||||
const evalOperators = [{ text: 'OR', value: 'or' }, { text: 'AND', value: 'and' }];
|
||||
|
||||
var reducerTypes = [
|
||||
const reducerTypes = [
|
||||
{ text: 'avg()', value: 'avg' },
|
||||
{ text: 'min()', value: 'min' },
|
||||
{ text: 'max()', value: 'max' },
|
||||
@@ -48,17 +48,17 @@ var reducerTypes = [
|
||||
{ text: 'count_non_null()', value: 'count_non_null' },
|
||||
];
|
||||
|
||||
var noDataModes = [
|
||||
const noDataModes = [
|
||||
{ text: 'Alerting', value: 'alerting' },
|
||||
{ text: 'No Data', value: 'no_data' },
|
||||
{ text: 'Keep Last State', value: 'keep_state' },
|
||||
{ text: 'Ok', value: 'ok' },
|
||||
];
|
||||
|
||||
var executionErrorModes = [{ text: 'Alerting', value: 'alerting' }, { text: 'Keep Last State', value: 'keep_state' }];
|
||||
const executionErrorModes = [{ text: 'Alerting', value: 'alerting' }, { text: 'Keep Last State', value: 'keep_state' }];
|
||||
|
||||
function createReducerPart(model) {
|
||||
var def = new QueryPartDef({ type: model.type, defaultParams: [] });
|
||||
const def = new QueryPartDef({ type: model.type, defaultParams: [] });
|
||||
return new QueryPart(model, def);
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ export class AlertTabCtrl {
|
||||
this.addNotificationSegment = this.uiSegmentSrv.newPlusButton();
|
||||
|
||||
// subscribe to graph threshold handle changes
|
||||
var thresholdChangedEventHandler = this.graphThresholdChanged.bind(this);
|
||||
const thresholdChangedEventHandler = this.graphThresholdChanged.bind(this);
|
||||
this.panelCtrl.events.on('threshold-changed', thresholdChangedEventHandler);
|
||||
|
||||
// set panel alert edit mode
|
||||
@@ -129,7 +129,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
notificationAdded() {
|
||||
var model = _.find(this.notifications, {
|
||||
const model = _.find(this.notifications, {
|
||||
name: this.addNotificationSegment.value,
|
||||
});
|
||||
if (!model) {
|
||||
@@ -154,7 +154,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
initModel() {
|
||||
var alert = (this.alert = this.panel.alert);
|
||||
const alert = (this.alert = this.panel.alert);
|
||||
if (!alert) {
|
||||
return;
|
||||
}
|
||||
@@ -170,7 +170,7 @@ export class AlertTabCtrl {
|
||||
alert.handler = alert.handler || 1;
|
||||
alert.notifications = alert.notifications || [];
|
||||
|
||||
var defaultName = this.panel.title + ' alert';
|
||||
const defaultName = this.panel.title + ' alert';
|
||||
alert.name = alert.name || defaultName;
|
||||
|
||||
this.conditionModels = _.reduce(
|
||||
@@ -185,7 +185,7 @@ export class AlertTabCtrl {
|
||||
ThresholdMapper.alertToGraphThresholds(this.panel);
|
||||
|
||||
for (const addedNotification of alert.notifications) {
|
||||
var model = _.find(this.notifications, { id: addedNotification.id });
|
||||
const model = _.find(this.notifications, { id: addedNotification.id });
|
||||
if (model && model.isDefault === false) {
|
||||
model.iconClass = this.getNotificationIcon(model.type);
|
||||
this.alertNotifications.push(model);
|
||||
@@ -205,7 +205,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
graphThresholdChanged(evt) {
|
||||
for (var condition of this.alert.conditions) {
|
||||
for (const condition of this.alert.conditions) {
|
||||
if (condition.type === 'query') {
|
||||
condition.evaluator.params[evt.handleIndex] = evt.threshold.value;
|
||||
this.evaluatorParamsChanged();
|
||||
@@ -232,12 +232,12 @@ export class AlertTabCtrl {
|
||||
let firstTarget;
|
||||
let foundTarget = null;
|
||||
|
||||
for (var condition of this.alert.conditions) {
|
||||
for (const condition of this.alert.conditions) {
|
||||
if (condition.type !== 'query') {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var target of this.panel.targets) {
|
||||
for (const target of this.panel.targets) {
|
||||
if (!firstTarget) {
|
||||
firstTarget = target;
|
||||
}
|
||||
@@ -256,7 +256,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
}
|
||||
|
||||
var datasourceName = foundTarget.datasource || this.panel.datasource;
|
||||
const datasourceName = foundTarget.datasource || this.panel.datasource;
|
||||
this.datasourceSrv.get(datasourceName).then(ds => {
|
||||
if (!ds.meta.alerting) {
|
||||
this.error = 'The datasource does not support alerting queries';
|
||||
@@ -270,7 +270,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
buildConditionModel(source) {
|
||||
var cm: any = { source: source, type: source.type };
|
||||
const cm: any = { source: source, type: source.type };
|
||||
|
||||
cm.queryPart = new QueryPart(source.query, alertDef.alertQueryDef);
|
||||
cm.reducerPart = alertDef.createReducerPart(source.reducer);
|
||||
@@ -292,7 +292,7 @@ export class AlertTabCtrl {
|
||||
this.validateModel();
|
||||
}
|
||||
case 'get-param-options': {
|
||||
var result = this.panel.targets.map(target => {
|
||||
const result = this.panel.targets.map(target => {
|
||||
return this.uiSegmentSrv.newSegment({ value: target.refId });
|
||||
});
|
||||
|
||||
@@ -309,8 +309,8 @@ export class AlertTabCtrl {
|
||||
break;
|
||||
}
|
||||
case 'get-part-actions': {
|
||||
var result = [];
|
||||
for (var type of alertDef.reducerTypes) {
|
||||
const result = [];
|
||||
for (const type of alertDef.reducerTypes) {
|
||||
if (type.value !== conditionModel.source.reducer.type) {
|
||||
result.push(type);
|
||||
}
|
||||
@@ -321,7 +321,7 @@ export class AlertTabCtrl {
|
||||
}
|
||||
|
||||
addCondition(type) {
|
||||
var condition = this.buildDefaultCondition();
|
||||
const condition = this.buildDefaultCondition();
|
||||
// add to persited model
|
||||
this.alert.conditions.push(condition);
|
||||
// add to view model
|
||||
@@ -406,7 +406,7 @@ export class AlertTabCtrl {
|
||||
this.testing = true;
|
||||
this.testResult = false;
|
||||
|
||||
var payload = {
|
||||
const payload = {
|
||||
dashboard: this.dashboardSrv.getCurrent().getSaveModelClone(),
|
||||
panelId: this.panelCtrl.panel.id,
|
||||
};
|
||||
|
||||
@@ -6,8 +6,8 @@ export class ThresholdMapper {
|
||||
continue;
|
||||
}
|
||||
|
||||
var evaluator = condition.evaluator;
|
||||
var thresholds = (panel.thresholds = []);
|
||||
const evaluator = condition.evaluator;
|
||||
const thresholds = (panel.thresholds = []);
|
||||
|
||||
switch (evaluator.type) {
|
||||
case 'gt': {
|
||||
@@ -51,13 +51,13 @@ export class ThresholdMapper {
|
||||
break;
|
||||
}
|
||||
|
||||
for (var t of panel.thresholds) {
|
||||
for (const t of panel.thresholds) {
|
||||
t.fill = true;
|
||||
t.line = true;
|
||||
t.colorMode = 'critical';
|
||||
}
|
||||
|
||||
var updated = true;
|
||||
const updated = true;
|
||||
return updated;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user