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

43 lines
1.0 KiB
TypeScript
Raw Normal View History

2017-12-20 05:33:33 -06:00
import angular from 'angular';
const directiveModule = angular.module('grafana.directives');
const directiveCache = {};
/** @ngInject */
function panelEditorTab(dynamicDirectiveSrv) {
return dynamicDirectiveSrv.create({
scope: {
2017-12-20 05:33:33 -06:00
ctrl: '=',
editorTab: '=',
},
directive: scope => {
const pluginId = scope.ctrl.pluginId;
const tabName = scope.editorTab.title
.toLowerCase()
.replace(' ', '-')
.replace('&', '')
.replace(' ', '')
.replace(' ', '-');
if (directiveCache[pluginId]) {
2018-09-10 12:04:56 -05:00
if (directiveCache[pluginId][tabName]) {
return directiveCache[pluginId][tabName];
}
} else {
directiveCache[pluginId] = [];
}
const result = {
fn: () => scope.editorTab.directiveFn(),
2018-09-10 12:04:56 -05:00
name: `panel-editor-tab-${pluginId}${tabName}`,
};
2018-09-10 12:04:56 -05:00
directiveCache[pluginId][tabName] = result;
return result;
2017-12-20 05:33:33 -06:00
},
});
}
2017-12-20 05:33:33 -06:00
directiveModule.directive('panelEditorTab', panelEditorTab);