refactor: use constants instead magic values

This commit is contained in:
Alexander Zobnin
2017-06-08 13:53:02 +03:00
parent 3eb5dc49e6
commit fe455113d5
12 changed files with 158 additions and 46 deletions

View File

@@ -1,9 +1,9 @@
'use strict';
System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
System.register(['app/plugins/sdk', 'angular', 'lodash', './constants', './utils', './metricFunctions', './migrations', './add-metric-function.directive', './metric-function-editor.directive', './css/query-editor.css!'], function (_export, _context) {
"use strict";
var QueryCtrl, angular, _, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
var QueryCtrl, angular, _, c, utils, metricFunctions, migrations, _createClass, ZabbixQueryController;
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
@@ -42,6 +42,8 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
angular = _angular.default;
}, function (_lodash) {
_ = _lodash.default;
}, function (_constants) {
c = _constants;
}, function (_utils) {
utils = _utils;
}, function (_metricFunctions) {
@@ -84,9 +86,9 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
_this.templateSrv = templateSrv;
_this.editorModes = {
0: { value: 'num', text: 'Metrics', mode: 0 },
1: { value: 'itservice', text: 'IT Services', mode: 1 },
2: { value: 'text', text: 'Text', mode: 2 }
0: { value: 'num', text: 'Metrics', mode: c.MODE_METRICS },
1: { value: 'itservice', text: 'IT Services', mode: c.MODE_ITSERVICE },
2: { value: 'text', text: 'Text', mode: c.MODE_TEXT }
};
// Map functions for bs-typeahead
@@ -120,7 +122,7 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
// Load default values
var targetDefaults = {
mode: 0,
mode: c.MODE_METRICS,
group: { filter: "" },
host: { filter: "" },
application: { filter: "" },
@@ -137,12 +139,12 @@ System.register(['app/plugins/sdk', 'angular', 'lodash', './utils', './metricFun
return metricFunctions.createFuncInstance(func.def, func.params);
});
if (target.mode === 0 || target.mode === 2) {
if (target.mode === c.MODE_METRICS || target.mode === c.MODE_TEXT) {
this.downsampleFunctionList = [{ name: "avg", value: "avg" }, { name: "min", value: "min" }, { name: "max", value: "max" }, { name: "sum", value: "sum" }, { name: "count", value: "count" }];
this.initFilters();
} else if (target.mode === 1) {
} else if (target.mode === c.MODE_ITSERVICE) {
this.slaPropertyList = [{ name: "Status", property: "status" }, { name: "SLA", property: "sla" }, { name: "OK time", property: "okTime" }, { name: "Problem time", property: "problemTime" }, { name: "Down time", property: "downtimeTime" }];
this.itserviceList = [{ name: "test" }];
this.updateITServiceList();