repeat_option.ts 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. import {coreModule} from 'app/core/core';
  2. var 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({text: 'No template variables found', value: null});
  23. }
  24. scope.variables.unshift({text: 'Disabled', value: null});
  25. // if repeat is set and no direction set to horizontal
  26. if (scope.panel.repeat && !scope.panel.repeatDirection) {
  27. scope.panel.repeatDirection = 'h';
  28. }
  29. scope.optionChanged = function() {
  30. if (scope.panel.repeat) {
  31. scope.panel.repeatDirection = 'h';
  32. }
  33. };
  34. }
  35. };
  36. }
  37. coreModule.directive('dashRepeatOption', dashRepeatOptionDirective);