2017-12-20 05:33:33 -06:00
|
|
|
import { Variable, assignModelProperties, variableTypes } from './variable';
|
2016-09-17 08:27:53 -05:00
|
|
|
|
|
|
|
export class ConstantVariable implements Variable {
|
|
|
|
query: string;
|
|
|
|
options: any[];
|
2016-09-20 04:57:43 -05:00
|
|
|
current: any;
|
2018-07-11 12:06:36 -05:00
|
|
|
skipUrlSync: boolean;
|
2016-09-17 08:27:53 -05:00
|
|
|
|
2016-09-19 08:15:15 -05:00
|
|
|
defaults = {
|
2017-12-20 05:33:33 -06:00
|
|
|
type: 'constant',
|
|
|
|
name: '',
|
2016-09-19 08:15:15 -05:00
|
|
|
hide: 2,
|
2017-12-20 05:33:33 -06:00
|
|
|
label: '',
|
|
|
|
query: '',
|
2016-09-20 04:57:43 -05:00
|
|
|
current: {},
|
2017-12-20 05:33:33 -06:00
|
|
|
options: [],
|
2018-07-11 12:06:36 -05:00
|
|
|
skipUrlSync: false,
|
2016-09-19 08:15:15 -05:00
|
|
|
};
|
|
|
|
|
2018-08-31 09:40:43 -05:00
|
|
|
/** @ngInject */
|
2016-09-17 08:27:53 -05:00
|
|
|
constructor(private model, private variableSrv) {
|
2016-09-19 08:15:15 -05:00
|
|
|
assignModelProperties(this, model, this.defaults);
|
|
|
|
}
|
|
|
|
|
2016-11-17 04:28:33 -06:00
|
|
|
getSaveModel() {
|
2016-09-19 08:15:15 -05:00
|
|
|
assignModelProperties(this.model, this, this.defaults);
|
|
|
|
return this.model;
|
2016-09-17 08:27:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
setValue(option) {
|
|
|
|
this.variableSrv.setOptionAsCurrent(this, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateOptions() {
|
2017-12-19 09:06:54 -06:00
|
|
|
this.options = [{ text: this.query.trim(), value: this.query.trim() }];
|
2016-09-17 08:27:53 -05:00
|
|
|
this.setValue(this.options[0]);
|
2016-09-19 10:03:29 -05:00
|
|
|
return Promise.resolve();
|
2016-09-17 08:27:53 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
dependsOn(variable) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
setValueFromUrl(urlValue) {
|
|
|
|
return this.variableSrv.setOptionFromUrl(this, urlValue);
|
|
|
|
}
|
2016-09-20 04:57:43 -05:00
|
|
|
|
|
|
|
getValueForUrl() {
|
|
|
|
return this.current.value;
|
|
|
|
}
|
2016-09-17 08:27:53 -05:00
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
variableTypes['constant'] = {
|
|
|
|
name: 'Constant',
|
2016-09-19 11:32:09 -05:00
|
|
|
ctor: ConstantVariable,
|
2017-12-21 01:39:31 -06:00
|
|
|
description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share',
|
2016-09-19 11:32:09 -05:00
|
|
|
};
|