grafana/public/app/features/templating/constant_variable.ts

58 lines
1.2 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import { Variable, assignModelProperties, variableTypes } from './variable';
export class ConstantVariable implements Variable {
query: string;
options: any[];
current: any;
skipUrlSync: boolean;
defaults = {
2017-12-20 05:33:33 -06:00
type: 'constant',
name: '',
hide: 2,
2017-12-20 05:33:33 -06:00
label: '',
query: '',
current: {},
2017-12-20 05:33:33 -06:00
options: [],
skipUrlSync: false,
};
/** @ngInject */
constructor(private model, private variableSrv) {
assignModelProperties(this, model, this.defaults);
}
getSaveModel() {
assignModelProperties(this.model, this, this.defaults);
return this.model;
}
setValue(option) {
this.variableSrv.setOptionAsCurrent(this, option);
}
updateOptions() {
this.options = [{ text: this.query.trim(), value: this.query.trim() }];
this.setValue(this.options[0]);
return Promise.resolve();
}
dependsOn(variable) {
return false;
}
setValueFromUrl(urlValue) {
return this.variableSrv.setOptionFromUrl(this, urlValue);
}
getValueForUrl() {
return this.current.value;
}
}
2017-12-20 05:33:33 -06:00
variableTypes['constant'] = {
name: 'Constant',
ctor: ConstantVariable,
description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share',
};