constant_variable.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. ///<reference path="../../headers/common.d.ts" />
  2. import {Variable, assignModelProperties, variableTypes} from './variable';
  3. export class ConstantVariable implements Variable {
  4. query: string;
  5. options: any[];
  6. current: any;
  7. defaults = {
  8. type: 'constant',
  9. name: '',
  10. hide: 2,
  11. label: '',
  12. query: '',
  13. current: {},
  14. options: [],
  15. };
  16. /** @ngInject **/
  17. constructor(private model, private variableSrv) {
  18. assignModelProperties(this, model, this.defaults);
  19. }
  20. getSaveModel() {
  21. assignModelProperties(this.model, this, this.defaults);
  22. return this.model;
  23. }
  24. setValue(option) {
  25. this.variableSrv.setOptionAsCurrent(this, option);
  26. }
  27. updateOptions() {
  28. this.options = [{text: this.query.trim(), value: this.query.trim()}];
  29. this.setValue(this.options[0]);
  30. return Promise.resolve();
  31. }
  32. dependsOn(variable) {
  33. return false;
  34. }
  35. setValueFromUrl(urlValue) {
  36. return this.variableSrv.setOptionFromUrl(this, urlValue);
  37. }
  38. getValueForUrl() {
  39. return this.current.value;
  40. }
  41. }
  42. variableTypes['constant'] = {
  43. name: 'Constant',
  44. ctor: ConstantVariable,
  45. description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' ,
  46. };