2017-12-20 12:33:33 +01:00
|
|
|
import { coreModule } from 'app/core/core';
|
2016-11-01 13:43:05 +01:00
|
|
|
|
2018-08-26 20:19:23 +02:00
|
|
|
const template = `
|
2017-12-13 12:42:50 +01:00
|
|
|
<div class="gf-form-select-wrapper max-width-18">
|
2017-10-24 20:13:34 +02:00
|
|
|
<select class="gf-form-input" ng-model="panel.repeat" ng-options="f.value as f.text for f in variables" ng-change="optionChanged()">
|
2017-10-13 13:51:05 +02:00
|
|
|
<option value=""></option>
|
2016-11-01 13:43:05 +01:00
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
|
2018-08-31 16:40:43 +02:00
|
|
|
/** @ngInject */
|
2017-10-01 20:02:25 +02:00
|
|
|
function dashRepeatOptionDirective(variableSrv) {
|
2016-11-01 13:43:05 +01:00
|
|
|
return {
|
2017-12-20 12:33:33 +01:00
|
|
|
restrict: 'E',
|
2016-11-01 13:43:05 +01:00
|
|
|
template: template,
|
|
|
|
|
scope: {
|
2017-12-20 12:33:33 +01:00
|
|
|
panel: '=',
|
2016-11-01 13:43:05 +01:00
|
|
|
},
|
2018-09-05 07:47:30 +02:00
|
|
|
link: (scope, element) => {
|
2017-12-20 12:33:33 +01:00
|
|
|
element.css({ display: 'block', width: '100%' });
|
2016-11-01 13:43:05 +01:00
|
|
|
|
|
|
|
|
scope.variables = variableSrv.variables.map(item => {
|
2017-12-19 16:06:54 +01:00
|
|
|
return { text: item.name, value: item.name };
|
2016-11-01 13:43:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if (scope.variables.length === 0) {
|
2017-12-19 16:06:54 +01:00
|
|
|
scope.variables.unshift({
|
2017-12-20 12:33:33 +01:00
|
|
|
text: 'No template variables found',
|
|
|
|
|
value: null,
|
2017-12-19 16:06:54 +01:00
|
|
|
});
|
2016-11-01 13:43:05 +01:00
|
|
|
}
|
|
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
scope.variables.unshift({ text: 'Disabled', value: null });
|
2017-10-13 13:51:05 +02:00
|
|
|
|
|
|
|
|
// if repeat is set and no direction set to horizontal
|
|
|
|
|
if (scope.panel.repeat && !scope.panel.repeatDirection) {
|
2017-12-20 12:33:33 +01:00
|
|
|
scope.panel.repeatDirection = 'h';
|
2017-10-13 13:51:05 +02:00
|
|
|
}
|
|
|
|
|
|
2018-09-05 07:47:30 +02:00
|
|
|
scope.optionChanged = () => {
|
2017-10-13 13:51:05 +02:00
|
|
|
if (scope.panel.repeat) {
|
2017-12-20 12:33:33 +01:00
|
|
|
scope.panel.repeatDirection = 'h';
|
2017-10-13 13:51:05 +02:00
|
|
|
}
|
|
|
|
|
};
|
2017-12-20 12:33:33 +01:00
|
|
|
},
|
2016-11-01 13:43:05 +01:00
|
|
|
};
|
2017-10-01 20:02:25 +02:00
|
|
|
}
|
2016-11-01 13:43:05 +01:00
|
|
|
|
2017-12-20 12:33:33 +01:00
|
|
|
coreModule.directive('dashRepeatOption', dashRepeatOptionDirective);
|