diff --git a/pkg/api/dtos/apps.go b/pkg/api/dtos/apps.go index c520b6921a1..88886e40dd9 100644 --- a/pkg/api/dtos/apps.go +++ b/pkg/api/dtos/apps.go @@ -10,6 +10,7 @@ type AppSettings struct { AppId string `json:"appId"` Enabled bool `json:"enabled"` Pinned bool `json:"pinned"` + Module string `json:"module"` Info *plugins.PluginInfo `json:"info"` Pages []*plugins.AppPluginPage `json:"pages"` JsonData map[string]interface{} `json:"jsonData"` @@ -17,10 +18,11 @@ type AppSettings struct { func NewAppSettingsDto(def *plugins.AppPlugin, data *models.AppSettings) *AppSettings { dto := &AppSettings{ - AppId: def.Id, - Name: def.Name, - Info: &def.Info, - Pages: def.Pages, + AppId: def.Id, + Name: def.Name, + Info: &def.Info, + Module: def.Module, + Pages: def.Pages, } if data != nil { diff --git a/public/app/core/services/all.js b/public/app/core/services/all.js index 2d4415a8fa2..96a4ec77737 100644 --- a/public/app/core/services/all.js +++ b/public/app/core/services/all.js @@ -9,5 +9,6 @@ define([ './popover_srv', './segment_srv', './backend_srv', + './dynamic_directive_srv', ], function () {}); diff --git a/public/app/core/services/dynamic_directive_srv.ts b/public/app/core/services/dynamic_directive_srv.ts new file mode 100644 index 00000000000..a38f8e79716 --- /dev/null +++ b/public/app/core/services/dynamic_directive_srv.ts @@ -0,0 +1,37 @@ +/// + +import _ from 'lodash'; +import angular from 'angular'; +import coreModule from '../core_module'; + +class DynamicDirectiveSrv { + + /** @ngInject */ + constructor(private $compile, private $parse, private datasourceSrv) { + } + + addDirective(element, name, scope) { + element.empty(); + element.append(angular.element(document.createElement(name))); + this.$compile(element)(scope); + } + + define(options) { + var editorScope; + options.scope.$watch(options.datasourceProperty, newVal => { + if (editorScope) { + editorScope.$destroy(); + options.parentElem.empty(); + } + + editorScope = options.scope.$new(); + this.datasourceSrv.get(newVal).then(ds => { + this.addDirective(options.parentElem, options.name + '-' + ds.meta.id, editorScope); + }); + }); + } +} + +coreModule.service('dynamicDirectiveSrv', DynamicDirectiveSrv); + + diff --git a/public/app/features/annotations/partials/editor.html b/public/app/features/annotations/partials/editor.html index 875f205c1f9..1fd51774705 100644 --- a/public/app/features/annotations/partials/editor.html +++ b/public/app/features/annotations/partials/editor.html @@ -91,6 +91,9 @@ +
diff --git a/public/app/features/apps/all.ts b/public/app/features/apps/all.ts index fcdd27dff4d..d3163cb71ba 100644 --- a/public/app/features/apps/all.ts +++ b/public/app/features/apps/all.ts @@ -1,2 +1,3 @@ import './edit_ctrl'; import './list_ctrl'; +import './config_loader'; diff --git a/public/app/features/apps/app_srv.ts b/public/app/features/apps/app_srv.ts deleted file mode 100644 index 18c6979b388..00000000000 --- a/public/app/features/apps/app_srv.ts +++ /dev/null @@ -1,43 +0,0 @@ -/// - -import _ from 'lodash'; -import angular from 'angular'; - -export class AppSrv { - apps: any = {}; - - /** @ngInject */ - constructor( - private $rootScope, - private $timeout, - private $q, - private backendSrv) { - } - - get(type) { - return this.getAll().then(() => { - return this.apps[type]; - }); - } - - getAll() { - if (!_.isEmpty(this.apps)) { - return this.$q.when(this.apps); - } - - return this.backendSrv.get('api/org/apps').then(results => { - return results.reduce((prev, current) => { - prev[current.type] = current; - return prev; - }, this.apps); - }); - } - - update(app) { - return this.backendSrv.post('api/org/apps', app).then(resp => { - - }); - } -} - -angular.module('grafana.services').service('appSrv', AppSrv); diff --git a/public/app/features/apps/config_loader.ts b/public/app/features/apps/config_loader.ts new file mode 100644 index 00000000000..d2128778707 --- /dev/null +++ b/public/app/features/apps/config_loader.ts @@ -0,0 +1,36 @@ +/// + +import _ from 'lodash'; +import angular from 'angular'; + +function appConfigLoader($compile, $parse) { + return { + restrict: 'E', + scope: { + appModel: "=" + }, + link: function(scope, elem, attr) { + debugger; + System.import(scope.appModel.module).then(function(appModule) { + var directive = appModule.directives.configView; + if (!directive) { + return; + } + if (!directive.hasBeenRegistered) { + angular.module('grafana.directives').directive('nginxConfig', directive); + directive.hasBeenRegistered = true; + } + + var panelEl = angular.element(document.createElement('nginx-config')); + elem.append(panelEl); + $compile(panelEl)(scope); + }).catch(function(err) { + console.log('Failed to load panel:', err); + scope.appEvent('alert-error', ['App Error', err.toString()]); + }); + } + }; +} + + +angular.module('grafana.directives').directive('appConfigLoader', appConfigLoader); diff --git a/public/app/features/apps/partials/edit.html b/public/app/features/apps/partials/edit.html index ff022299ac2..50ebf9ab5af 100644 --- a/public/app/features/apps/partials/edit.html +++ b/public/app/features/apps/partials/edit.html @@ -97,6 +97,11 @@ - + + +
+ +
+ diff --git a/public/app/features/panel/panel_directive.js b/public/app/features/panel/panel_directive.js index 0c3ab11a9a7..e2228b82ee3 100644 --- a/public/app/features/panel/panel_directive.js +++ b/public/app/features/panel/panel_directive.js @@ -70,31 +70,6 @@ function (angular, $, config) { }; }); - module.service('dynamicDirectiveSrv', function($compile, $parse, datasourceSrv) { - var self = this; - - this.addDirective = function(options, type, editorScope) { - var panelEl = angular.element(document.createElement(options.name + '-' + type)); - options.parentElem.append(panelEl); - $compile(panelEl)(editorScope); - }; - - this.define = function(options) { - var editorScope; - options.scope.$watch(options.datasourceProperty, function(newVal) { - if (editorScope) { - editorScope.$destroy(); - options.parentElem.empty(); - } - - editorScope = options.scope.$new(); - datasourceSrv.get(newVal).then(function(ds) { - self.addDirective(options, ds.meta.id, editorScope); - }); - }); - }; - }); - module.directive('datasourceEditorView', function(dynamicDirectiveSrv) { return { restrict: 'E',