grafana/public/app/features/panel/repeat_option.ts
Tobias Skarhed c8498461a5 noImplicitAny: Down approx 200 errors (#18143)
* noImplicitAny playlist approx 200

* Add AngularPanelMenuItem interface

* Roughly 100 noImplicitAny
2019-07-18 08:03:04 +02:00

49 lines
1.4 KiB
TypeScript

import { coreModule } from 'app/core/core';
import { VariableSrv } from 'app/features/templating/variable_srv';
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: VariableSrv) {
return {
restrict: 'E',
template: template,
scope: {
panel: '=',
},
link: (scope: any, element: JQuery) => {
element.css({ display: 'block', width: '100%' });
scope.variables = variableSrv.variables.map((item: any) => {
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);