grafana/public/app/features/panel/repeat_option.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

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">
<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>
2016-11-01 07:43:05 -05:00
</div>
`;
/** @ngInject */
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
},
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 => {
return { text: item.name, value: item.name };
2016-11-01 07:43:05 -05:00
});
if (scope.variables.length === 0) {
scope.variables.unshift({
2017-12-20 05:33:33 -06:00
text: 'No template variables found',
value: null,
});
2016-11-01 07:43:05 -05:00
}
2017-12-20 05:33:33 -06:00
scope.variables.unshift({ text: 'Disabled', value: null });
// 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';
}
scope.optionChanged = () => {
if (scope.panel.repeat) {
2017-12-20 05:33:33 -06:00
scope.panel.repeatDirection = 'h';
}
};
2017-12-20 05:33:33 -06:00
},
2016-11-01 07:43:05 -05:00
};
}
2016-11-01 07:43:05 -05:00
2017-12-20 05:33:33 -06:00
coreModule.directive('dashRepeatOption', dashRepeatOptionDirective);