constant_variable.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Variable, assignModelProperties, variableTypes } from './variable';
  2. export class ConstantVariable implements Variable {
  3. query: string;
  4. options: any[];
  5. current: any;
  6. defaults = {
  7. type: 'constant',
  8. name: '',
  9. hide: 2,
  10. label: '',
  11. query: '',
  12. current: {},
  13. options: [],
  14. };
  15. /** @ngInject **/
  16. constructor(private model, private variableSrv) {
  17. assignModelProperties(this, model, this.defaults);
  18. }
  19. getSaveModel() {
  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. getValueForUrl() {
  38. return this.current.value;
  39. }
  40. }
  41. variableTypes['constant'] = {
  42. name: 'Constant',
  43. ctor: ConstantVariable,
  44. description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share',
  45. };