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