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

71 lines
1.6 KiB
TypeScript
Raw Normal View History

import {
assignModelProperties,
ConstantVariableModel,
VariableActions,
VariableHide,
VariableOption,
VariableType,
variableTypes,
} from './variable';
import { VariableSrv } from './all';
export class ConstantVariable implements ConstantVariableModel, VariableActions {
type: VariableType;
name: string;
label: string;
hide: VariableHide;
skipUrlSync: boolean;
query: string;
options: VariableOption[];
current: VariableOption;
defaults: ConstantVariableModel = {
2017-12-20 05:33:33 -06:00
type: 'constant',
name: '',
hide: VariableHide.hideLabel,
2017-12-20 05:33:33 -06:00
label: '',
query: '',
current: {} as VariableOption,
2017-12-20 05:33:33 -06:00
options: [],
skipUrlSync: false,
};
/** @ngInject */
constructor(private model: any, private variableSrv: VariableSrv) {
assignModelProperties(this, model, this.defaults);
}
getSaveModel() {
assignModelProperties(this.model, this, this.defaults);
return this.model;
}
setValue(option: any) {
this.variableSrv.setOptionAsCurrent(this, option);
}
updateOptions() {
this.options = [{ text: this.query.trim(), value: this.query.trim(), selected: false }];
this.setValue(this.options[0]);
return Promise.resolve();
}
dependsOn(variable: any) {
return false;
}
setValueFromUrl(urlValue: string) {
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',
};