constant_variable.ts 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {Variable, assignModelProperties} from './variable';
  4. import {VariableSrv, variableConstructorMap} from './variable_srv';
  5. export class ConstantVariable implements Variable {
  6. query: string;
  7. options: any[];
  8. defaults = {
  9. type: 'constant',
  10. name: '',
  11. hide: 2,
  12. label: '',
  13. query: '',
  14. };
  15. /** @ngInject */
  16. constructor(private model, private variableSrv) {
  17. assignModelProperties(this, model, this.defaults);
  18. }
  19. getModel() {
  20. assignModelProperties(this.model, this, this.defaults);
  21. return this.model;
  22. }
  23. setValue(option) {
  24. this.variableSrv.setOptionAsCurrent(this, option);
  25. }
  26. updateOptions() {
  27. this.options = [{text: this.query.trim(), value: this.query.trim()}];
  28. this.setValue(this.options[0]);
  29. return Promise.resolve();
  30. }
  31. dependsOn(variable) {
  32. return false;
  33. }
  34. setValueFromUrl(urlValue) {
  35. return this.variableSrv.setOptionFromUrl(this, urlValue);
  36. }
  37. }
  38. variableConstructorMap['constant'] = ConstantVariable;