mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(apps): work on plugin directives loading
This commit is contained in:
@@ -25,5 +25,6 @@ import 'app/core/controllers/all';
|
|||||||
import 'app/core/services/all';
|
import 'app/core/services/all';
|
||||||
import 'app/core/routes/all';
|
import 'app/core/routes/all';
|
||||||
import './filters/filters';
|
import './filters/filters';
|
||||||
|
import coreModule from './core_module';
|
||||||
|
|
||||||
export {arrayJoin};
|
export {arrayJoin, coreModule};
|
||||||
|
|||||||
@@ -9,25 +9,31 @@ class DynamicDirectiveSrv {
|
|||||||
constructor(private $compile, private $parse) {}
|
constructor(private $compile, private $parse) {}
|
||||||
|
|
||||||
addDirective(element, name, scope) {
|
addDirective(element, name, scope) {
|
||||||
|
var child = angular.element(document.createElement(name));
|
||||||
|
this.$compile(child)(scope);
|
||||||
|
|
||||||
element.empty();
|
element.empty();
|
||||||
element.append(angular.element(document.createElement(name)));
|
element.append(child);
|
||||||
this.$compile(element)(scope);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
create(options) {
|
create(options) {
|
||||||
let directiveDef = {
|
let directiveDef = {
|
||||||
restrict: 'E',
|
restrict: 'E',
|
||||||
scope: options.scope,
|
scope: options.scope,
|
||||||
link: function(scope, elem) {
|
link: (scope, elem, attrs) => {
|
||||||
options.directive(scope).then(directiveInfo => {
|
options.directive(scope).then(directiveInfo => {
|
||||||
if (!directiveInfo) {
|
if (!directiveInfo) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (directiveInfo.fn.hasBeenRegistered) {
|
if (!directiveInfo.fn.registered) {
|
||||||
coreModule.directive(directiveInfo.name, directiveInfo.fn);
|
coreModule.directive(attrs.$normalize(directiveInfo.name), directiveInfo.fn);
|
||||||
directiveInfo.fn.hasBeenRegistered = true;
|
directiveInfo.fn.registered = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.addDirective(elem, directiveInfo.name, scope);
|
||||||
|
}).catch(function(err) {
|
||||||
|
console.log('Dynamic directive load error: ', err);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -11,8 +11,8 @@ function appConfigLoader(dynamicDirectiveSrv) {
|
|||||||
directive: scope => {
|
directive: scope => {
|
||||||
return System.import(scope.appModel.module).then(function(appModule) {
|
return System.import(scope.appModel.module).then(function(appModule) {
|
||||||
return {
|
return {
|
||||||
name: 'appConfigLoader' + scope.appModel.appId,
|
name: 'app-config-' + scope.appModel.appId,
|
||||||
fn: scope.appModel.directives.configView,
|
fn: appModule.configView,
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -96,8 +96,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
<nginx-config></nginx-config>
|
|
||||||
|
|
||||||
<div ng-if="ctrl.appModel.appId">
|
<div ng-if="ctrl.appModel.appId">
|
||||||
<app-config-loader app-model="ctrl.appModel"></app-config-loader>
|
<app-config-loader app-model="ctrl.appModel"></app-config-loader>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -8,12 +8,12 @@ import 'angular-sanitize';
|
|||||||
import 'angular-dragdrop';
|
import 'angular-dragdrop';
|
||||||
import 'angular-bindonce';
|
import 'angular-bindonce';
|
||||||
import 'angular-ui';
|
import 'angular-ui';
|
||||||
import 'app/core/core';
|
|
||||||
|
|
||||||
import $ from 'jquery';
|
import $ from 'jquery';
|
||||||
import angular from 'angular';
|
import angular from 'angular';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
import {coreModule} from './core/core';
|
||||||
|
|
||||||
export class GrafanaApp {
|
export class GrafanaApp {
|
||||||
registerFunctions: any;
|
registerFunctions: any;
|
||||||
@@ -67,6 +67,9 @@ export class GrafanaApp {
|
|||||||
this.useModule(angular.module(moduleName, []));
|
this.useModule(angular.module(moduleName, []));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// makes it possible to add dynamic stuff
|
||||||
|
this.useModule(coreModule);
|
||||||
|
|
||||||
var preBootRequires = [System.import('app/features/all')];
|
var preBootRequires = [System.import('app/features/all')];
|
||||||
var pluginModules = config.bootData.pluginModules || [];
|
var pluginModules = config.bootData.pluginModules || [];
|
||||||
|
|
||||||
|
|||||||
@@ -27,15 +27,17 @@ module.exports = function(config, grunt) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (/(\.ts)$/.test(filepath)) {
|
if (/(\.ts)$/.test(filepath)) {
|
||||||
|
newPath = filepath.replace(/^public/, 'public_gen');
|
||||||
|
grunt.log.writeln('Copying to ' + newPath);
|
||||||
|
grunt.file.copy(filepath, newPath);
|
||||||
|
|
||||||
|
// copy ts file also used by source maps
|
||||||
//changes changed file source to that of the changed file
|
//changes changed file source to that of the changed file
|
||||||
var option = 'typescript.build.src';
|
var option = 'typescript.build.src';
|
||||||
var result = filepath;
|
var result = filepath;
|
||||||
grunt.config(option, result);
|
grunt.config(option, result);
|
||||||
grunt.task.run('typescript:build');
|
grunt.task.run('typescript:build');
|
||||||
grunt.task.run('tslint');
|
grunt.task.run('tslint');
|
||||||
// copy ts file also used by source maps
|
|
||||||
newPath = filepath.replace(/^public/, 'public_gen');
|
|
||||||
grunt.file.copy(filepath, newPath);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user