UNPKG

4.14 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3var core_1 = require("@angular/core");
4var authentication_module_config_1 = require("../../dumb-components/authentication-module-config");
5var app_config_1 = require("../../dumb-components/app-config");
6var user_module_config_1 = require("../../dumb-components/user-module-config");
7var dumb_components_1 = require("../../dumb-components");
8var DynamicConfigComponentSelectorComponent = /** @class */ (function () {
9 function DynamicConfigComponentSelectorComponent(resolver) {
10 this.resolver = resolver;
11 this.typeMapToDiagram = {
12 authentication_module_config: authentication_module_config_1.AuthenticationModuleConfigComponent,
13 app_config: app_config_1.ConfigAppConfigComponent,
14 user_module_config: user_module_config_1.UserModuleConfigComponent,
15 layout_config: dumb_components_1.LayoutModuleConfigComponent
16 };
17 this.configChanged = new core_1.EventEmitter();
18 this.currentComponent = null;
19 }
20 Object.defineProperty(DynamicConfigComponentSelectorComponent.prototype, "data", {
21 set: function (data) {
22 var _this = this;
23 if (!data || Object.keys(data).length == 0)
24 return;
25 if (!(data.type in this.typeMapToDiagram)) {
26 if (this.currentComponent)
27 this.currentComponent.destroy();
28 return;
29 }
30 var _component = this.typeMapToDiagram[data.type];
31 var inputProviders = Object.keys(data.inputs).map(function (inputName) {
32 return { provide: inputName, useValue: data.inputs[inputName] };
33 });
34 var resolvedInputs = core_1.ReflectiveInjector.resolve(inputProviders);
35 var injector = core_1.ReflectiveInjector.fromResolvedProviders(resolvedInputs, this.dynamicComponentContainer.parentInjector);
36 var factory = this.resolver.resolveComponentFactory(_component);
37 var component = factory.create(injector);
38 component.instance.configChanged.subscribe(function (data) {
39 _this.configChanged.emit(data);
40 });
41 this.dynamicComponentContainer.insert(component.hostView);
42 if (this.currentComponent) {
43 this.currentComponent.destroy();
44 }
45 this.currentComponent = component;
46 },
47 enumerable: true,
48 configurable: true
49 });
50 DynamicConfigComponentSelectorComponent.prototype.ngAfterViewInit = function () { };
51 DynamicConfigComponentSelectorComponent.decorators = [
52 { type: core_1.Component, args: [{
53 selector: "dynamic-config-component-selector",
54 template: "<div #dynamicComponentContainer></div>",
55 styles: [":host{ width: 100%; } .diagram-box{ margin : 15px; } .diagram-box .c3 { direction: ltr; }"],
56 entryComponents: [
57 authentication_module_config_1.AuthenticationModuleConfigComponent,
58 app_config_1.ConfigAppConfigComponent,
59 user_module_config_1.UserModuleConfigComponent,
60 dumb_components_1.LayoutModuleConfigComponent
61 ]
62 },] },
63 ];
64 /** @nocollapse */
65 DynamicConfigComponentSelectorComponent.ctorParameters = function () { return [
66 { type: core_1.ComponentFactoryResolver, },
67 ]; };
68 DynamicConfigComponentSelectorComponent.propDecorators = {
69 "dynamicComponentContainer": [{ type: core_1.ViewChild, args: ["dynamicComponentContainer", { read: core_1.ViewContainerRef },] },],
70 "configChanged": [{ type: core_1.Output },],
71 "data": [{ type: core_1.Input },],
72 };
73 return DynamicConfigComponentSelectorComponent;
74}());
75exports.DynamicConfigComponentSelectorComponent = DynamicConfigComponentSelectorComponent;
76//# sourceMappingURL=dynamic-config-component-selector.component.js.map
\No newline at end of file