2016-09-17 15:27:53 +02:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
2016-09-19 18:32:09 +02:00
|
|
|
import {Variable, assignModelProperties, variableTypes} from './variable';
|
2016-09-17 15:27:53 +02:00
|
|
|
|
|
|
|
|
export class ConstantVariable implements Variable {
|
|
|
|
|
query: string;
|
|
|
|
|
options: any[];
|
2016-09-20 11:57:43 +02:00
|
|
|
current: any;
|
2016-09-17 15:27:53 +02:00
|
|
|
|
2016-09-19 15:15:15 +02:00
|
|
|
defaults = {
|
|
|
|
|
type: 'constant',
|
|
|
|
|
name: '',
|
|
|
|
|
hide: 2,
|
2016-09-19 17:03:29 +02:00
|
|
|
label: '',
|
|
|
|
|
query: '',
|
2016-09-20 11:57:43 +02:00
|
|
|
current: {},
|
2016-11-04 04:41:39 -06:00
|
|
|
options: [],
|
2016-09-19 15:15:15 +02:00
|
|
|
};
|
|
|
|
|
|
2016-09-22 10:22:16 +02:00
|
|
|
/** @ngInject **/
|
2016-09-17 15:27:53 +02:00
|
|
|
constructor(private model, private variableSrv) {
|
2016-09-19 15:15:15 +02:00
|
|
|
assignModelProperties(this, model, this.defaults);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-17 11:28:33 +01:00
|
|
|
getSaveModel() {
|
2016-09-19 15:15:15 +02:00
|
|
|
assignModelProperties(this.model, this, this.defaults);
|
|
|
|
|
return this.model;
|
2016-09-17 15:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setValue(option) {
|
|
|
|
|
this.variableSrv.setOptionAsCurrent(this, option);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
updateOptions() {
|
|
|
|
|
this.options = [{text: this.query.trim(), value: this.query.trim()}];
|
|
|
|
|
this.setValue(this.options[0]);
|
2016-09-19 17:03:29 +02:00
|
|
|
return Promise.resolve();
|
2016-09-17 15:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
dependsOn(variable) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setValueFromUrl(urlValue) {
|
|
|
|
|
return this.variableSrv.setOptionFromUrl(this, urlValue);
|
|
|
|
|
}
|
2016-09-20 11:57:43 +02:00
|
|
|
|
|
|
|
|
getValueForUrl() {
|
|
|
|
|
return this.current.value;
|
|
|
|
|
}
|
|
|
|
|
|
2016-09-17 15:27:53 +02:00
|
|
|
}
|
|
|
|
|
|
2016-09-19 18:32:09 +02:00
|
|
|
variableTypes['constant'] = {
|
|
|
|
|
name: 'Constant',
|
|
|
|
|
ctor: ConstantVariable,
|
|
|
|
|
description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' ,
|
|
|
|
|
};
|