constant_variable.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. ///<reference path="../../headers/common.d.ts" />
  2. import _ from 'lodash';
  3. import {Variable, assignModelProperties, variableTypes} from './variable';
  4. import {VariableSrv} 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. variableTypes['constant'] = {
  39. name: 'Constant',
  40. ctor: ConstantVariable,
  41. description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' ,
  42. };