constant_variable.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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. current: any;
  9. defaults = {
  10. type: 'constant',
  11. name: '',
  12. hide: 2,
  13. label: '',
  14. query: '',
  15. current: {},
  16. };
  17. /** @ngInject */
  18. constructor(private model, private variableSrv) {
  19. assignModelProperties(this, model, this.defaults);
  20. }
  21. getModel() {
  22. assignModelProperties(this.model, this, this.defaults);
  23. return this.model;
  24. }
  25. setValue(option) {
  26. this.variableSrv.setOptionAsCurrent(this, option);
  27. }
  28. updateOptions() {
  29. this.options = [{text: this.query.trim(), value: this.query.trim()}];
  30. this.setValue(this.options[0]);
  31. return Promise.resolve();
  32. }
  33. dependsOn(variable) {
  34. return false;
  35. }
  36. setValueFromUrl(urlValue) {
  37. return this.variableSrv.setOptionFromUrl(this, urlValue);
  38. }
  39. getValueForUrl() {
  40. return this.current.value;
  41. }
  42. }
  43. variableTypes['constant'] = {
  44. name: 'Constant',
  45. ctor: ConstantVariable,
  46. description: 'Define a hidden constant variable, useful for metric prefixes in dashboards you want to share' ,
  47. };