2016-09-17 08:27:53 -05:00
|
|
|
///<reference path="../../headers/common.d.ts" />
|
|
|
|
|
|
|
|
import _ from 'lodash';
|
2016-09-19 11:32:09 -05:00
|
|
|
import {Variable, assignModelProperties, variableTypes} from './variable';
|
|
|
|
import {VariableSrv} from './variable_srv';
|
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;
|
2016-09-17 08:27:53 -05:00
|
|
|
|
2016-09-19 08:15:15 -05:00
|
|
|
defaults = {
|
|
|
|
type: 'constant',
|
|
|
|
name: '',
|
|
|
|
hide: 2,
|
2016-09-19 10:03:29 -05:00
|
|
|
label: '',
|
|
|
|
query: '',
|
2016-09-20 04:57:43 -05:00
|
|
|
current: {},
|
2016-11-04 05:41:39 -05:00
|
|
|
options: [],
|
2016-09-19 08:15:15 -05:00
|
|
|
};
|
|
|
|
|
2016-09-22 03:22:16 -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() {
|
|
|
|
this.options = [{text: this.query.trim(), value: this.query.trim()}];
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2016-09-19 11:32:09 -05:00
|
|
|
variableTypes['constant'] = {
|
|
|
|
name: 'Constant',
|
|
|
|
ctor: ConstantVariable,
|
|
|
|
description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' ,
|
|
|
|
};
|