Files
grafana/public/app/features/dashboard/repeat_option/repeat_option.ts

49 lines
1.3 KiB
TypeScript
Raw Normal View History

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