grafana/public/app/features/panel/repeat_option.ts
2019-01-27 17:33:13 +01:00

49 lines
1.3 KiB
TypeScript

import { coreModule } from 'app/core/core';
const template = `
<div class="gf-form-select-wrapper max-width-18">
<select class="gf-form-input" ng-model="panel.repeat" ng-options="f.value as f.text for f in variables" ng-change="optionChanged()">
<option value=""></option>
</div>
`;
/** @ngInject */
function dashRepeatOptionDirective(variableSrv) {
return {
restrict: 'E',
template: template,
scope: {
panel: '=',
},
link: (scope, element) => {
element.css({ display: 'block', width: '100%' });
scope.variables = variableSrv.variables.map(item => {
return { text: item.name, value: item.name };
});
if (scope.variables.length === 0) {
scope.variables.unshift({
text: 'No template variables found',
value: null,
});
}
scope.variables.unshift({ text: 'Disabled', value: null });
// if repeat is set and no direction set to horizontal
if (scope.panel.repeat && !scope.panel.repeatDirection) {
scope.panel.repeatDirection = 'h';
}
scope.optionChanged = () => {
if (scope.panel.repeat) {
scope.panel.repeatDirection = 'h';
}
};
},
};
}
coreModule.directive('dashRepeatOption', dashRepeatOptionDirective);