TextBoxVariable.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. import { Variable, assignModelProperties, variableTypes } from './variable';
  2. import { VariableSrv } from './variable_srv';
  3. export class TextBoxVariable implements Variable {
  4. query: string;
  5. current: any;
  6. options: any[];
  7. skipUrlSync: boolean;
  8. defaults: any = {
  9. type: 'textbox',
  10. name: '',
  11. hide: 0,
  12. label: '',
  13. query: '',
  14. current: {},
  15. options: [],
  16. skipUrlSync: false,
  17. };
  18. /** @ngInject */
  19. constructor(private model: any, private variableSrv: VariableSrv) {
  20. assignModelProperties(this, model, this.defaults);
  21. }
  22. getSaveModel() {
  23. assignModelProperties(this.model, this, this.defaults);
  24. return this.model;
  25. }
  26. setValue(option: any) {
  27. this.variableSrv.setOptionAsCurrent(this, option);
  28. }
  29. updateOptions() {
  30. this.options = [{ text: this.query.trim(), value: this.query.trim() }];
  31. this.current = this.options[0];
  32. return Promise.resolve();
  33. }
  34. dependsOn(variable: any) {
  35. return false;
  36. }
  37. setValueFromUrl(urlValue: string) {
  38. this.query = urlValue;
  39. return this.variableSrv.setOptionFromUrl(this, urlValue);
  40. }
  41. getValueForUrl() {
  42. return this.current.value;
  43. }
  44. }
  45. // @ts-ignore
  46. variableTypes['textbox'] = {
  47. name: 'Text box',
  48. ctor: TextBoxVariable,
  49. description: 'Define a textbox variable, where users can enter any arbitrary string',
  50. };