repeat_option.ts 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import { coreModule } from 'app/core/core';
  2. const template = `
  3. <div class="gf-form-select-wrapper max-width-18">
  4. <select class="gf-form-input" ng-model="panel.repeat" ng-options="f.value as f.text for f in variables" ng-change="optionChanged()">
  5. <option value=""></option>
  6. </div>
  7. `;
  8. /** @ngInject */
  9. function dashRepeatOptionDirective(variableSrv) {
  10. return {
  11. restrict: 'E',
  12. template: template,
  13. scope: {
  14. panel: '=',
  15. },
  16. link: function(scope, element) {
  17. element.css({ display: 'block', width: '100%' });
  18. scope.variables = variableSrv.variables.map(item => {
  19. return { text: item.name, value: item.name };
  20. });
  21. if (scope.variables.length === 0) {
  22. scope.variables.unshift({
  23. text: 'No template variables found',
  24. value: null,
  25. });
  26. }
  27. scope.variables.unshift({ text: 'Disabled', value: null });
  28. // if repeat is set and no direction set to horizontal
  29. if (scope.panel.repeat && !scope.panel.repeatDirection) {
  30. scope.panel.repeatDirection = 'h';
  31. }
  32. scope.optionChanged = function() {
  33. if (scope.panel.repeat) {
  34. scope.panel.repeatDirection = 'h';
  35. }
  36. };
  37. },
  38. };
  39. }
  40. coreModule.directive('dashRepeatOption', dashRepeatOptionDirective);