2019-10-31 04:59:30 -05:00
|
|
|
import {
|
|
|
|
assignModelProperties,
|
|
|
|
TextBoxVariableModel,
|
|
|
|
VariableActions,
|
|
|
|
VariableHide,
|
|
|
|
VariableOption,
|
|
|
|
VariableType,
|
|
|
|
variableTypes,
|
|
|
|
} from './variable';
|
2019-07-16 04:35:42 -05:00
|
|
|
import { VariableSrv } from './variable_srv';
|
2018-09-12 08:17:15 -05:00
|
|
|
|
2019-10-31 04:59:30 -05:00
|
|
|
export class TextBoxVariable implements TextBoxVariableModel, VariableActions {
|
|
|
|
type: VariableType;
|
|
|
|
name: string;
|
|
|
|
label: string;
|
|
|
|
hide: VariableHide;
|
2018-09-12 08:17:15 -05:00
|
|
|
skipUrlSync: boolean;
|
2019-10-31 04:59:30 -05:00
|
|
|
query: string;
|
|
|
|
current: VariableOption;
|
|
|
|
options: VariableOption[];
|
2018-09-12 08:17:15 -05:00
|
|
|
|
2019-10-31 04:59:30 -05:00
|
|
|
defaults: TextBoxVariableModel = {
|
2018-09-27 07:50:14 -05:00
|
|
|
type: 'textbox',
|
2018-09-12 08:17:15 -05:00
|
|
|
name: '',
|
|
|
|
label: '',
|
2019-10-31 04:59:30 -05:00
|
|
|
hide: VariableHide.dontHide,
|
2018-09-12 08:17:15 -05:00
|
|
|
query: '',
|
2019-10-31 04:59:30 -05:00
|
|
|
current: {} as VariableOption,
|
2018-09-12 08:17:15 -05:00
|
|
|
options: [],
|
|
|
|
skipUrlSync: false,
|
|
|
|
};
|
|
|
|
|
|
|
|
/** @ngInject */
|
2019-07-16 04:35:42 -05:00
|
|
|
constructor(private model: any, private variableSrv: VariableSrv) {
|
2018-09-12 08:17:15 -05:00
|
|
|
assignModelProperties(this, model, this.defaults);
|
|
|
|
}
|
|
|
|
|
|
|
|
getSaveModel() {
|
|
|
|
assignModelProperties(this.model, this, this.defaults);
|
|
|
|
return this.model;
|
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
setValue(option: any) {
|
2018-09-12 08:17:15 -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 }];
|
2018-09-12 08:17:15 -05:00
|
|
|
this.current = this.options[0];
|
|
|
|
return Promise.resolve();
|
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
dependsOn(variable: any) {
|
2018-09-12 08:17:15 -05:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-07-16 04:35:42 -05:00
|
|
|
setValueFromUrl(urlValue: string) {
|
2018-09-12 08:17:15 -05:00
|
|
|
this.query = urlValue;
|
|
|
|
return this.variableSrv.setOptionFromUrl(this, urlValue);
|
|
|
|
}
|
|
|
|
|
|
|
|
getValueForUrl() {
|
|
|
|
return this.current.value;
|
|
|
|
}
|
|
|
|
}
|
2019-07-16 04:35:42 -05:00
|
|
|
// @ts-ignore
|
2018-09-27 07:50:14 -05:00
|
|
|
variableTypes['textbox'] = {
|
|
|
|
name: 'Text box',
|
|
|
|
ctor: TextBoxVariable,
|
2018-09-12 08:17:15 -05:00
|
|
|
description: 'Define a textbox variable, where users can enter any arbitrary string',
|
|
|
|
};
|