From d420cb38d150bfeb977d4be18451146f9d846ebc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Thu, 14 Jan 2016 11:21:56 +0100 Subject: [PATCH] feat(plugins): work on plugin directives loading --- .../core/services/dynamic_directive_srv.ts | 2 +- .../apps/{config_loader.ts => config_view.ts} | 4 +-- public/app/features/apps/partials/edit.html | 6 ++--- public/app/features/datasources/all.js | 1 + .../app/features/datasources/config_view.ts | 25 +++++++++++++++++ .../features/datasources/partials/edit.html | 2 +- public/app/features/panel/panel_directive.js | 27 ------------------- .../datasource/elasticsearch/module.js | 1 + 8 files changed, 34 insertions(+), 34 deletions(-) rename public/app/features/apps/{config_loader.ts => config_view.ts} (76%) create mode 100644 public/app/features/datasources/config_view.ts diff --git a/public/app/core/services/dynamic_directive_srv.ts b/public/app/core/services/dynamic_directive_srv.ts index 51c97290914..49de763cd44 100644 --- a/public/app/core/services/dynamic_directive_srv.ts +++ b/public/app/core/services/dynamic_directive_srv.ts @@ -22,7 +22,7 @@ class DynamicDirectiveSrv { scope: options.scope, link: (scope, elem, attrs) => { options.directive(scope).then(directiveInfo => { - if (!directiveInfo) { + if (!directiveInfo || !directiveInfo.fn) { return; } diff --git a/public/app/features/apps/config_loader.ts b/public/app/features/apps/config_view.ts similarity index 76% rename from public/app/features/apps/config_loader.ts rename to public/app/features/apps/config_view.ts index 5e571987d25..31e85967cb2 100644 --- a/public/app/features/apps/config_loader.ts +++ b/public/app/features/apps/config_view.ts @@ -3,7 +3,7 @@ import angular from 'angular'; /** @ngInject */ -function appConfigLoader(dynamicDirectiveSrv) { +function appConfigView(dynamicDirectiveSrv) { return dynamicDirectiveSrv.create({ scope: { appModel: "=" @@ -20,4 +20,4 @@ function appConfigLoader(dynamicDirectiveSrv) { } -angular.module('grafana.directives').directive('appConfigLoader', appConfigLoader); +angular.module('grafana.directives').directive('appConfigView', appConfigView); diff --git a/public/app/features/apps/partials/edit.html b/public/app/features/apps/partials/edit.html index e1a26bbd5aa..91b174cb6a3 100644 --- a/public/app/features/apps/partials/edit.html +++ b/public/app/features/apps/partials/edit.html @@ -93,12 +93,12 @@

Configuration:

+
+ +
-
- -
diff --git a/public/app/features/datasources/all.js b/public/app/features/datasources/all.js index b181fd475c2..8a57bbc5b8a 100644 --- a/public/app/features/datasources/all.js +++ b/public/app/features/datasources/all.js @@ -1,4 +1,5 @@ define([ './list_ctrl', './edit_ctrl', + './config_view', ], function () {}); diff --git a/public/app/features/datasources/config_view.ts b/public/app/features/datasources/config_view.ts new file mode 100644 index 00000000000..8be06bbcdfd --- /dev/null +++ b/public/app/features/datasources/config_view.ts @@ -0,0 +1,25 @@ +/// + +import angular from 'angular'; + +/** @ngInject */ +function dsConfigView(dynamicDirectiveSrv) { + return dynamicDirectiveSrv.create({ + scope: { + dsMeta: "=", + current: "=" + }, + watch: "dsMeta.module", + directive: scope => { + return System.import(scope.dsMeta.module).then(function(dsModule) { + return { + name: 'ds-config-' + scope.dsMeta.id, + fn: dsModule.configView, + }; + }); + }, + }); +} + + +angular.module('grafana.directives').directive('dsConfigView', dsConfigView); diff --git a/public/app/features/datasources/partials/edit.html b/public/app/features/datasources/partials/edit.html index fda9acde58a..24375506b85 100644 --- a/public/app/features/datasources/partials/edit.html +++ b/public/app/features/datasources/partials/edit.html @@ -42,7 +42,7 @@
- +
Testing....
diff --git a/public/app/features/panel/panel_directive.js b/public/app/features/panel/panel_directive.js index e2228b82ee3..40f6c96e736 100644 --- a/public/app/features/panel/panel_directive.js +++ b/public/app/features/panel/panel_directive.js @@ -43,33 +43,6 @@ function (angular, $, config) { }; }); - module.directive('datasourceCustomSettingsView', function($compile) { - return { - restrict: 'E', - scope: { - dsMeta: "=", - current: "=", - }, - link: function(scope, elem) { - scope.$watch("dsMeta.module", function() { - if (!scope.dsMeta) { - return; - } - - System.import(scope.dsMeta.module).then(function() { - elem.empty(); - var panelEl = angular.element(document.createElement('datasource-custom-settings-view-' + scope.dsMeta.id)); - elem.append(panelEl); - $compile(panelEl)(scope); - }).catch(function(err) { - console.log('Failed to load plugin:', err); - scope.appEvent('alert-error', ['Plugin Load Error', 'Failed to load plugin ' + scope.dsMeta.id + ', ' + err]); - }); - }); - } - }; - }); - module.directive('datasourceEditorView', function(dynamicDirectiveSrv) { return { restrict: 'E', diff --git a/public/app/plugins/datasource/elasticsearch/module.js b/public/app/plugins/datasource/elasticsearch/module.js index 958eb3eb8e7..3e8d3c8e481 100644 --- a/public/app/plugins/datasource/elasticsearch/module.js +++ b/public/app/plugins/datasource/elasticsearch/module.js @@ -55,6 +55,7 @@ function (angular, ElasticDatasource, editView) { return { Datasource: ElasticDatasource, + configView: editView.default, }; });