ZabbixQueryController: migrate to TS
This commit is contained in:
@@ -306,6 +306,7 @@ class FuncInstance {
|
|||||||
def: any;
|
def: any;
|
||||||
params: any;
|
params: any;
|
||||||
text: string;
|
text: string;
|
||||||
|
added: boolean;
|
||||||
|
|
||||||
constructor(funcDef, params) {
|
constructor(funcDef, params) {
|
||||||
this.def = funcDef;
|
this.def = funcDef;
|
||||||
@@ -408,7 +409,7 @@ class FuncInstance {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createFuncInstance(funcDef, params) {
|
export function createFuncInstance(funcDef, params?) {
|
||||||
if (_.isString(funcDef)) {
|
if (_.isString(funcDef)) {
|
||||||
if (!index[funcDef]) {
|
if (!index[funcDef]) {
|
||||||
throw { message: 'Method not found ' + name };
|
throw { message: 'Method not found ' + name };
|
||||||
|
|||||||
@@ -58,6 +58,32 @@ function getSeverityOptions() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export class ZabbixQueryController extends QueryCtrl {
|
export class ZabbixQueryController extends QueryCtrl {
|
||||||
|
static templateUrl: string;
|
||||||
|
|
||||||
|
zabbix: any;
|
||||||
|
replaceTemplateVars: any;
|
||||||
|
templateSrv: any;
|
||||||
|
editorModes: Array<{ value: string; text: string; queryType: number; }>;
|
||||||
|
slaPropertyList: Array<{ name: string; property: string; }>;
|
||||||
|
slaIntervals: Array<{ text: string; value: string; }>;
|
||||||
|
ackFilters: Array<{ text: string; value: number; }>;
|
||||||
|
problemAckFilters: string[];
|
||||||
|
sortByFields: Array<{ text: string; value: string; }>;
|
||||||
|
showEventsFields: Array<{ text: string; value: number[]; } | { text: string; value: number; }>;
|
||||||
|
showProblemsOptions: Array<{ text: string; value: string; }>;
|
||||||
|
resultFormats: Array<{ text: string; value: string; }>;
|
||||||
|
severityOptions: Array<{ val: number; text: string; }>;
|
||||||
|
getGroupNames: (...args: any[]) => any;
|
||||||
|
getHostNames: (...args: any[]) => any;
|
||||||
|
getApplicationNames: (...args: any[]) => any;
|
||||||
|
getItemNames: (...args: any[]) => any;
|
||||||
|
getITServices: (...args: any[]) => any;
|
||||||
|
getProxyNames: (...args: any[]) => any;
|
||||||
|
getVariables: (...args: any[]) => any;
|
||||||
|
init: () => void;
|
||||||
|
queryOptionsText: string;
|
||||||
|
metric: any;
|
||||||
|
showQueryOptions: boolean;
|
||||||
|
|
||||||
/** @ngInject */
|
/** @ngInject */
|
||||||
constructor($scope, $injector, $rootScope, $sce, templateSrv) {
|
constructor($scope, $injector, $rootScope, $sce, templateSrv) {
|
||||||
@@ -156,12 +182,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
});
|
});
|
||||||
|
|
||||||
this.init = function() {
|
this.init = function() {
|
||||||
var target = this.target;
|
let target = this.target;
|
||||||
|
|
||||||
// Migrate old targets
|
// Migrate old targets
|
||||||
target = migrations.migrate(target);
|
target = migrations.migrate(target);
|
||||||
|
|
||||||
var scopeDefaults = {
|
const scopeDefaults = {
|
||||||
metric: {},
|
metric: {},
|
||||||
oldTarget: _.cloneDeep(this.target),
|
oldTarget: _.cloneDeep(this.target),
|
||||||
queryOptionsText: this.renderQueryOptionsText()
|
queryOptionsText: this.renderQueryOptionsText()
|
||||||
@@ -177,7 +203,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create function instances from saved JSON
|
// Create function instances from saved JSON
|
||||||
target.functions = _.map(target.functions, function(func) {
|
target.functions = _.map(target.functions, func => {
|
||||||
return metricFunctions.createFuncInstance(func.def, func.params);
|
return metricFunctions.createFuncInstance(func.def, func.params);
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -204,8 +230,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
initFilters() {
|
initFilters() {
|
||||||
let itemtype = _.find(this.editorModes, {'queryType': this.target.queryType});
|
const mode = _.find(this.editorModes, {'queryType': this.target.queryType});
|
||||||
itemtype = itemtype ? itemtype.value : null;
|
const itemtype = mode ? mode.value : null;
|
||||||
const promises = [
|
const promises = [
|
||||||
this.suggestGroups(),
|
this.suggestGroups(),
|
||||||
this.suggestHosts(),
|
this.suggestHosts(),
|
||||||
@@ -222,7 +248,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
|
|
||||||
// Get list of metric names for bs-typeahead directive
|
// Get list of metric names for bs-typeahead directive
|
||||||
getMetricNames(metricList, addAllValue) {
|
getMetricNames(metricList, addAllValue) {
|
||||||
let metrics = _.uniq(_.map(this.metric[metricList], 'name'));
|
const metrics = _.uniq(_.map(this.metric[metricList], 'name'));
|
||||||
|
|
||||||
// Add template variables
|
// Add template variables
|
||||||
_.forEach(this.templateSrv.variables, variable => {
|
_.forEach(this.templateSrv.variables, variable => {
|
||||||
@@ -251,7 +277,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suggestHosts() {
|
suggestHosts() {
|
||||||
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
const groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
||||||
return this.zabbix.getAllHosts(groupFilter)
|
return this.zabbix.getAllHosts(groupFilter)
|
||||||
.then(hosts => {
|
.then(hosts => {
|
||||||
this.metric.hostList = hosts;
|
this.metric.hostList = hosts;
|
||||||
@@ -260,8 +286,8 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suggestApps() {
|
suggestApps() {
|
||||||
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
const groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
||||||
let hostFilter = this.replaceTemplateVars(this.target.host.filter);
|
const hostFilter = this.replaceTemplateVars(this.target.host.filter);
|
||||||
return this.zabbix.getAllApps(groupFilter, hostFilter)
|
return this.zabbix.getAllApps(groupFilter, hostFilter)
|
||||||
.then(apps => {
|
.then(apps => {
|
||||||
this.metric.appList = apps;
|
this.metric.appList = apps;
|
||||||
@@ -270,10 +296,10 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
suggestItems(itemtype = 'num') {
|
suggestItems(itemtype = 'num') {
|
||||||
let groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
const groupFilter = this.replaceTemplateVars(this.target.group.filter);
|
||||||
let hostFilter = this.replaceTemplateVars(this.target.host.filter);
|
const hostFilter = this.replaceTemplateVars(this.target.host.filter);
|
||||||
let appFilter = this.replaceTemplateVars(this.target.application.filter);
|
const appFilter = this.replaceTemplateVars(this.target.application.filter);
|
||||||
let options = {
|
const options = {
|
||||||
itemtype: itemtype,
|
itemtype: itemtype,
|
||||||
showDisabledItems: this.target.options.showDisabledItems
|
showDisabledItems: this.target.options.showDisabledItems
|
||||||
};
|
};
|
||||||
@@ -312,12 +338,15 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onTargetBlur() {
|
onTargetBlur() {
|
||||||
var newTarget = _.cloneDeep(this.target);
|
const newTarget = _.cloneDeep(this.target);
|
||||||
if (!_.isEqual(this.oldTarget, this.target)) {
|
if (!_.isEqual(this.oldTarget, this.target)) {
|
||||||
this.oldTarget = newTarget;
|
this.oldTarget = newTarget;
|
||||||
this.targetChanged();
|
this.targetChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
oldTarget(oldTarget: any, target: any) {
|
||||||
|
throw new Error("Method not implemented.");
|
||||||
|
}
|
||||||
|
|
||||||
onVariableChange() {
|
onVariableChange() {
|
||||||
if (this.isContainsVariables()) {
|
if (this.isContainsVariables()) {
|
||||||
@@ -354,7 +383,7 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
addFunction(funcDef) {
|
addFunction(funcDef) {
|
||||||
var newFunc = metricFunctions.createFuncInstance(funcDef);
|
const newFunc = metricFunctions.createFuncInstance(funcDef);
|
||||||
newFunc.added = true;
|
newFunc.added = true;
|
||||||
this.target.functions.push(newFunc);
|
this.target.functions.push(newFunc);
|
||||||
|
|
||||||
@@ -373,12 +402,12 @@ export class ZabbixQueryController extends QueryCtrl {
|
|||||||
|
|
||||||
moveFunction(func, offset) {
|
moveFunction(func, offset) {
|
||||||
const index = this.target.functions.indexOf(func);
|
const index = this.target.functions.indexOf(func);
|
||||||
_.move(this.target.functions, index, index + offset);
|
(_ as any).move(this.target.functions, index, index + offset);
|
||||||
this.targetChanged();
|
this.targetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
moveAliasFuncLast() {
|
moveAliasFuncLast() {
|
||||||
var aliasFunc = _.find(this.target.functions, func => {
|
const aliasFunc = _.find(this.target.functions, func => {
|
||||||
return func.def.category === 'Alias';
|
return func.def.category === 'Alias';
|
||||||
});
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user