2019-10-31 04:59:30 -05:00
|
|
|
import {
|
|
|
|
assignModelProperties,
|
|
|
|
ConstantVariableModel,
|
|
|
|
VariableActions,
|
|
|
|
VariableHide,
|
|
|
|
VariableOption,
|
|
|
|
VariableType,
|
|
|
|
variableTypes,
|
|
|
|
} from './variable';
|
2019-07-16 04:35:42 -05:00
|
|
|
import { VariableSrv } from './all';
|
2016-09-17 08:27:53 -05:00
|
|
|
|
2019-10-31 04:59:30 -05:00
|
|
|
export class ConstantVariable implements ConstantVariableModel, VariableActions {
|
|
|
|
type: VariableType;
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
hide: VariableHide;
|
2018-07-11 12:06:36 -05:00
|
|
|
skipUrlSync: boolean;
|
2019-10-31 04:59:30 -05:00
|
|
|
query: string;
|
|
|
|
options: VariableOption[];
|
|
|
|
current: VariableOption;
|
2016-09-17 08:27:53 -05:00
|
|
|
|
2019-10-31 04:59:30 -05:00
|
|
|
defaults: ConstantVariableModel = {
|
2017-12-20 05:33:33 -06:00
|
|
|
type: 'constant',
|
|
|
|
name: '',
|
2019-10-31 04:59:30 -05:00
|
|
|
hide: VariableHide.hideLabel,
|
2017-12-20 05:33:33 -06:00
|
|
|
label: '',
|
|
|
|
query: '',
|
2019-10-31 04:59:30 -05:00
|
|
|
current: {} as VariableOption,
|
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 */
|
2019-07-16 04:35:42 -05:00
|
|
|
constructor(private model: any, private variableSrv: 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
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
setValue(option: any) {
|
2016-09-17 08:27:53 -05:00
|
|
|
this.variableSrv.setOptionAsCurrent(this, option);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateOptions() {
|
2019-10-31 04:59:30 -05:00
|
|
|
this.options = [{ text: this.query.trim(), value: this.query.trim(), selected: false }];
|
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
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
dependsOn(variable: any) {
|
2016-09-17 08:27:53 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
setValueFromUrl(urlValue: string) {
|
2016-09-17 08:27:53 -05:00
|
|
|
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
|
|
|
};
|