mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 00:55:47 -06:00
* Refactor: Adds typings and changes AdHocVariable to conform to new typings * Refactor: Adds typings to ConstantVariable * Refactor: Adds typings to IntervalVariable * Refactor: Adds typings to QueryVariable * Refactor: Adds typings to TextBoxVariable * Refactor: Adds typings to CustomVariable
72 lines
1.6 KiB
TypeScript
72 lines
1.6 KiB
TypeScript
import {
|
|
assignModelProperties,
|
|
TextBoxVariableModel,
|
|
VariableActions,
|
|
VariableHide,
|
|
VariableOption,
|
|
VariableType,
|
|
variableTypes,
|
|
} from './variable';
|
|
import { VariableSrv } from './variable_srv';
|
|
|
|
export class TextBoxVariable implements TextBoxVariableModel, VariableActions {
|
|
type: VariableType;
|
|
name: string;
|
|
label: string;
|
|
hide: VariableHide;
|
|
skipUrlSync: boolean;
|
|
query: string;
|
|
current: VariableOption;
|
|
options: VariableOption[];
|
|
|
|
defaults: TextBoxVariableModel = {
|
|
type: 'textbox',
|
|
name: '',
|
|
label: '',
|
|
hide: VariableHide.dontHide,
|
|
query: '',
|
|
current: {} as VariableOption,
|
|
options: [],
|
|
skipUrlSync: false,
|
|
};
|
|
|
|
/** @ngInject */
|
|
constructor(private model: any, private variableSrv: VariableSrv) {
|
|
assignModelProperties(this, model, this.defaults);
|
|
}
|
|
|
|
getSaveModel() {
|
|
assignModelProperties(this.model, this, this.defaults);
|
|
return this.model;
|
|
}
|
|
|
|
setValue(option: any) {
|
|
this.variableSrv.setOptionAsCurrent(this, option);
|
|
}
|
|
|
|
updateOptions() {
|
|
this.options = [{ text: this.query.trim(), value: this.query.trim(), selected: false }];
|
|
this.current = this.options[0];
|
|
return Promise.resolve();
|
|
}
|
|
|
|
dependsOn(variable: any) {
|
|
return false;
|
|
}
|
|
|
|
setValueFromUrl(urlValue: string) {
|
|
this.query = urlValue;
|
|
return this.variableSrv.setOptionFromUrl(this, urlValue);
|
|
}
|
|
|
|
getValueForUrl() {
|
|
return this.current.value;
|
|
}
|
|
}
|
|
// @ts-ignore
|
|
variableTypes['textbox'] = {
|
|
name: 'Text box',
|
|
ctor: TextBoxVariable,
|
|
description: 'Define a textbox variable, where users can enter any arbitrary string',
|
|
};
|