grafana/public/app/features/templating/TextBoxVariable.ts
Roman Khavronenko 532abe2fc2 Templating: Do not copy hide option (#16696)
* Do not override default `hide` value of variables

Some variables like `constant` are configured to
be hidden by default and this setting must be
treated with respect.

* make textBox variable visible by default

Fixes #16695
2019-04-22 13:11:05 +02:00

59 lines
1.2 KiB
TypeScript

import { Variable, assignModelProperties, variableTypes } from './variable';
export class TextBoxVariable implements Variable {
query: string;
current: any;
options: any[];
skipUrlSync: boolean;
defaults = {
type: 'textbox',
name: '',
hide: 0,
label: '',
query: '',
current: {},
options: [],
skipUrlSync: false,
};
/** @ngInject */
constructor(private model, private variableSrv) {
assignModelProperties(this, model, this.defaults);
}
getSaveModel() {
assignModelProperties(this.model, this, this.defaults);
return this.model;
}
setValue(option) {
this.variableSrv.setOptionAsCurrent(this, option);
}
updateOptions() {
this.options = [{ text: this.query.trim(), value: this.query.trim() }];
this.current = this.options[0];
return Promise.resolve();
}
dependsOn(variable) {
return false;
}
setValueFromUrl(urlValue) {
this.query = urlValue;
return this.variableSrv.setOptionFromUrl(this, urlValue);
}
getValueForUrl() {
return this.current.value;
}
}
variableTypes['textbox'] = {
name: 'Text box',
ctor: TextBoxVariable,
description: 'Define a textbox variable, where users can enter any arbitrary string',
};