2017-12-20 05:33:33 -06:00
|
|
|
import angular from 'angular';
|
2016-01-24 15:39:25 -06:00
|
|
|
|
2018-08-25 14:22:50 -05:00
|
|
|
const directiveModule = angular.module('grafana.directives');
|
|
|
|
const directiveCache = {};
|
2016-01-24 15:39:25 -06:00
|
|
|
|
|
|
|
/** @ngInject */
|
|
|
|
function panelEditorTab(dynamicDirectiveSrv) {
|
|
|
|
return dynamicDirectiveSrv.create({
|
|
|
|
scope: {
|
2017-12-20 05:33:33 -06:00
|
|
|
ctrl: '=',
|
|
|
|
editorTab: '=',
|
2016-01-24 15:39:25 -06:00
|
|
|
},
|
|
|
|
directive: scope => {
|
2018-08-25 14:22:50 -05:00
|
|
|
const pluginId = scope.ctrl.pluginId;
|
2018-12-07 08:18:43 -06:00
|
|
|
const tabName = scope.editorTab.title
|
|
|
|
.toLowerCase()
|
|
|
|
.replace(' ', '-')
|
|
|
|
.replace('&', '')
|
|
|
|
.replace(' ', '')
|
|
|
|
.replace(' ', '-');
|
2016-01-26 16:28:07 -06:00
|
|
|
|
2018-08-25 14:22:50 -05:00
|
|
|
if (directiveCache[pluginId]) {
|
2018-09-10 12:04:56 -05:00
|
|
|
if (directiveCache[pluginId][tabName]) {
|
|
|
|
return directiveCache[pluginId][tabName];
|
2018-08-25 14:22:50 -05:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
directiveCache[pluginId] = [];
|
|
|
|
}
|
|
|
|
|
2018-09-10 08:42:36 -05:00
|
|
|
const result = {
|
2018-08-25 14:22:50 -05:00
|
|
|
fn: () => scope.editorTab.directiveFn(),
|
2018-09-10 12:04:56 -05:00
|
|
|
name: `panel-editor-tab-${pluginId}${tabName}`,
|
2018-08-25 14:22:50 -05:00
|
|
|
};
|
|
|
|
|
2018-09-10 12:04:56 -05:00
|
|
|
directiveCache[pluginId][tabName] = result;
|
2018-08-25 14:22:50 -05:00
|
|
|
|
|
|
|
return result;
|
2017-12-20 05:33:33 -06:00
|
|
|
},
|
2016-01-24 15:39:25 -06:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2017-12-20 05:33:33 -06:00
|
|
|
directiveModule.directive('panelEditorTab', panelEditorTab);
|