diff options
author | 2020-01-23 17:06:22 +0530 | |
---|---|---|
committer | 2020-01-28 07:29:04 +0000 | |
commit | 91e3434fc7c515416ff2da10d55acf1d2dbcde71 (patch) | |
tree | ac29f6ea8a20d06255c47ebdb8e4e2692621c0ab /portal-FE-common/src/app/shared/plugin | |
parent | 16c3ddbf7f9f644adc23b8f834e6453c5260ada6 (diff) |
Adding new components with portal-FE-common
added layout, admins, functional-menu, portal-admins, plugins components along with helpers class, models, pipes and dependent angular services.
Issue-ID: PORTAL-795
Change-Id: I8e9771fcee5d0e58c4a48711c943761f29ae48b8
Signed-off-by: Sudarshan Kumar <sudarshan.kumar@att.com>
Diffstat (limited to 'portal-FE-common/src/app/shared/plugin')
15 files changed, 937 insertions, 0 deletions
diff --git a/portal-FE-common/src/app/shared/plugin/dynamic-widget/dynamic-widget.module.ts b/portal-FE-common/src/app/shared/plugin/dynamic-widget/dynamic-widget.module.ts new file mode 100644 index 00000000..baab502d --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/dynamic-widget/dynamic-widget.module.ts @@ -0,0 +1,57 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { NgModule } from '@angular/core'; +import { CommonModule } from '@angular/common'; +import { ListWidgetComponent } from './list-widget/list-widget.component'; +import { HttpClientModule } from '@angular/common/http'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; + +@NgModule({ + declarations: [ListWidgetComponent], + imports: [ + CommonModule, + HttpClientModule + ], + exports: [ListWidgetComponent], + providers: [HttpClient], + entryComponents: [ListWidgetComponent] +}) +export class DynamicWidgetModule { + static entry = ListWidgetComponent; +} diff --git a/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.html b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.html new file mode 100644 index 00000000..82f4f35d --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.html @@ -0,0 +1,58 @@ +<!-- + ============LICENSE_START========================================== + ONAP Portal + =================================================================== + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + =================================================================== + + Unless otherwise specified, all software contained herein is licensed + under the Apache License, Version 2.0 (the "License"); + you may not use this software except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Unless otherwise specified, all documentation contained herein is licensed + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + you may not use this documentation except in compliance with the License. + You may obtain a copy of the License at + + https://creativecommons.org/licenses/by/4.0/ + + Unless required by applicable law or agreed to in writing, documentation + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + ============LICENSE_END============================================ + + + --> + +<div id="widget-news" class="widget-news-main"> + <div onap-gridster-item-body class="information-section-gridsterContent"> + <div class="resources"> + <ul *ngIf="newsData && newsData.length!=0"> + <li *ngFor="let item of newsData"><a href="{{item.href}}" target="_blank">{{item.title}}</a></li> + </ul> + <div *ngIf="newsData && newsData.length!=0"> + <div class="activity-error-container" + style="background: rgb(255, 255, 255); overflow: hidden !important; width: 100%;"> + <div class="activity-error-block"> + <i class="icon-information full-linear-icon-information" style="margin-left: 125px; font-size: 90px"></i> + <br> + <div class="activity-error-msg1">There's currently no + news available.</div> + </div> + </div> + </div> + </div> + </div> +</div> diff --git a/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.scss b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.scss new file mode 100644 index 00000000..7a773398 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.scss @@ -0,0 +1,37 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */
\ No newline at end of file diff --git a/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.spec.ts b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.spec.ts new file mode 100644 index 00000000..d7991933 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.spec.ts @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ListWidgetComponent } from './list-widget.component'; + +describe('ListWidgetComponent', () => { + let component: ListWidgetComponent; + let fixture: ComponentFixture<ListWidgetComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ ListWidgetComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(ListWidgetComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.ts b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.ts new file mode 100644 index 00000000..1d28026f --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/dynamic-widget/list-widget/list-widget.component.ts @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { Component, OnInit } from '@angular/core'; +import { HttpClient, HttpHeaders, HttpParams } from '@angular/common/http'; +import { Observable } from 'rxjs'; + +@Component({ + selector: 'app-list-widget', + templateUrl: './list-widget.component.html', + styleUrls: ['./list-widget.component.scss'] +}) +export class ListWidgetComponent implements OnInit { + newsData: any[]; + + constructor(private api: HttpClient) { } + + ngOnInit() { + this.getNewsWidgetCatalog(); + } + + getNewsWidgetCatalog() { + //console.log("getNewsWidgetCatalog called"); + } + +} diff --git a/portal-FE-common/src/app/shared/plugin/plugin-loader/client-plugin-loader.service.ts b/portal-FE-common/src/app/shared/plugin/plugin-loader/client-plugin-loader.service.ts new file mode 100644 index 00000000..2666a523 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin-loader/client-plugin-loader.service.ts @@ -0,0 +1,86 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { Injectable, NgModuleFactory } from '@angular/core'; +import { PluginLoaderService } from './plugin-loader.service'; +import { PLUGIN_EXTERNALS_MAP } from './plugin-externals'; +import { PluginsConfigProvider } from '../plugins-config.provider'; + +const SystemJs = window.System; + +@Injectable({ + providedIn: 'root', +}) +export class ClientPluginLoaderService extends PluginLoaderService { + constructor(private configProvider: PluginsConfigProvider) { + super(); + configProvider.loadConfig() + .toPromise() + .then(config => { + configProvider.config = config; + console.log(config); + }); + } + + provideExternals() { + Object.keys(PLUGIN_EXTERNALS_MAP).forEach(externalKey => + window.define(externalKey, [], () => PLUGIN_EXTERNALS_MAP[externalKey]) + ); + } + + load<T>(pluginName): Promise<NgModuleFactory<T>> { + + const { config } = this.configProvider; + if (!config[pluginName]) { + throw Error(`Can't find appropriate plugin`); + } + + const depsPromises = (config[pluginName].deps || []).map(dep => { + return SystemJs.import(window['base'] + config[dep].path).then(m => { + window['define'](dep, [], () => m.default); + }); + }); + + return Promise.all(depsPromises).then(() => { + + return SystemJs.import(window['base'] + config[pluginName].path).then( + module => module.default.default + ); + }); + } +} diff --git a/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-externals.ts b/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-externals.ts new file mode 100644 index 00000000..3bd5a133 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-externals.ts @@ -0,0 +1,53 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import * as core from '@angular/core'; +import * as common from '@angular/common'; +import * as forms from '@angular/forms'; +import * as router from '@angular/router'; +import * as rxjs from 'rxjs'; +import * as tslib from 'tslib'; + +export const PLUGIN_EXTERNALS_MAP = { + 'ng.core': core, + 'ng.common': common, + 'ng.forms': forms, + 'ng.router': router, + rxjs, + tslib +}; diff --git a/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-loader.service.ts b/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-loader.service.ts new file mode 100644 index 00000000..1d79b65f --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin-loader/plugin-loader.service.ts @@ -0,0 +1,49 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { NgModuleFactory } from '@angular/core'; + +export abstract class PluginLoaderService { + protected constructor() { + this.provideExternals(); + } + + abstract provideExternals(): void; + + abstract load<T>(pluginName): Promise<NgModuleFactory<T>>; +} diff --git a/portal-FE-common/src/app/shared/plugin/plugin.component.html b/portal-FE-common/src/app/shared/plugin/plugin.component.html new file mode 100644 index 00000000..e2aeaf18 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin.component.html @@ -0,0 +1,48 @@ +<!-- + ============LICENSE_START========================================== + ONAP Portal + =================================================================== + Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + =================================================================== + + Unless otherwise specified, all software contained herein is licensed + under the Apache License, Version 2.0 (the "License"); + you may not use this software except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + Unless otherwise specified, all documentation contained herein is licensed + under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + you may not use this documentation except in compliance with the License. + You may obtain a copy of the License at + + https://creativecommons.org/licenses/by/4.0/ + + Unless required by applicable law or agreed to in writing, documentation + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + + ============LICENSE_END============================================ + + + --> + +<p> plugin works</p> +<button (click)="loadPlugin('listWidgetPlugin')">Load News</button> +<div> + <div class="plugins"> + <ng-template #targetRef></ng-template> + </div> +</div> +<!-- +<app-list-widget></app-list-widget> +--> diff --git a/portal-FE-common/src/app/shared/plugin/plugin.component.scss b/portal-FE-common/src/app/shared/plugin/plugin.component.scss new file mode 100644 index 00000000..fa57ecbf --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin.component.scss @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ +
\ No newline at end of file diff --git a/portal-FE-common/src/app/shared/plugin/plugin.component.spec.ts b/portal-FE-common/src/app/shared/plugin/plugin.component.spec.ts new file mode 100644 index 00000000..cc5810c1 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin.component.spec.ts @@ -0,0 +1,63 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { PluginComponent } from './plugin.component'; + +describe('PluginComponent', () => { + let component: PluginComponent; + let fixture: ComponentFixture<PluginComponent>; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ PluginComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(PluginComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/portal-FE-common/src/app/shared/plugin/plugin.component.ts b/portal-FE-common/src/app/shared/plugin/plugin.component.ts new file mode 100644 index 00000000..b64ea7c9 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin.component.ts @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { + Component, + Injector, + OnInit, + ViewChild, + ViewContainerRef +} from '@angular/core'; +import { PluginLoaderService } from './plugin-loader/plugin-loader.service'; + +@Component({ + selector: 'app-plugin', + templateUrl: './plugin.component.html', + styleUrls: ['./plugin.component.scss'] +}) +export class PluginComponent implements OnInit { + @ViewChild('targetRef', { read: ViewContainerRef }) vcRef: ViewContainerRef; + + constructor( + private injector: Injector, + private pluginLoader: PluginLoaderService + ) {} + + ngOnInit() { + //this.loadPlugin('plugin1'); + } + + loadPlugin(pluginName: string) { + this.pluginLoader.load(pluginName).then(moduleFactory => { + const moduleRef = moduleFactory.create(this.injector); + const entryComponent = (moduleFactory.moduleType as any).entry; + const compFactory = moduleRef.componentFactoryResolver.resolveComponentFactory( + entryComponent + ); + this.vcRef.createComponent(compFactory); + }); + } +} diff --git a/portal-FE-common/src/app/shared/plugin/plugin.module.ts b/portal-FE-common/src/app/shared/plugin/plugin.module.ts new file mode 100644 index 00000000..de366627 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugin.module.ts @@ -0,0 +1,89 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { + BrowserModule, + BrowserTransferStateModule, TransferState +} from '@angular/platform-browser'; +import { APP_INITIALIZER, NgModule, APP_BOOTSTRAP_LISTENER } from '@angular/core'; +import { HttpClientModule } from '@angular/common/http'; +import { DynamicWidgetModule } from './dynamic-widget/dynamic-widget.module'; + + + +import { ClientPluginLoaderService } from './plugin-loader/client-plugin-loader.service'; +import { PluginsConfigProvider } from './plugins-config.provider'; +import { TransferStateService } from './transfer-state.service'; +import { PluginLoaderService } from './plugin-loader/plugin-loader.service'; +import { PluginComponent } from './plugin.component'; +import { ListWidgetComponent } from './dynamic-widget/list-widget/list-widget.component'; + +import { config } from 'rxjs'; + +@NgModule({ + declarations: [PluginComponent], + imports: [ + HttpClientModule, + //BrowserModule.withServerTransition({ appId: 'serverApp' }), + BrowserTransferStateModule + ], + providers: [ + { provide: PluginLoaderService, useClass: ClientPluginLoaderService }, + //PluginsConfigProvider, + TransferStateService, + { + provide: APP_BOOTSTRAP_LISTENER, + useFactory: (provider: PluginsConfigProvider) => () => + provider + .loadConfig() + .toPromise() + .then(config => { + provider.config = config; + console.log(config); + } + ), + multi: true, + deps: [PluginsConfigProvider] + } + ], + bootstrap: [PluginComponent], + exports: [PluginComponent] +}) +export class PluginModule { + constructor(transferStateService: TransferStateService) {} +} diff --git a/portal-FE-common/src/app/shared/plugin/plugins-config.provider.ts b/portal-FE-common/src/app/shared/plugin/plugins-config.provider.ts new file mode 100644 index 00000000..8c2a2e7d --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/plugins-config.provider.ts @@ -0,0 +1,75 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { Inject, Injectable, Optional, PLATFORM_ID } from '@angular/core'; +import { HttpClient } from '@angular/common/http'; +import { tap } from 'rxjs/operators'; +import { preserveServerState } from './transfer-state.service'; +import { isPlatformBrowser } from '@angular/common'; + +interface PluginsConfig { + [key: string]: { + name: string; + path: string; + deps: string[]; + }; +} + +@Injectable({ + providedIn: 'root', +}) +export class PluginsConfigProvider { + config: PluginsConfig; + + constructor( + private http: HttpClient, + @Inject(PLATFORM_ID) private platformId: {}, + @Inject('APP_BASE_URL') @Optional() private readonly baseUrl: string + ) { + if (isPlatformBrowser(platformId)) { + this.baseUrl = document.location.origin; + } + } + + @preserveServerState('PLUGIN_CONFIGS') + loadConfig() { + return this.http.get<PluginsConfig>( + `assets/plugins-config.json` + ); + } +} diff --git a/portal-FE-common/src/app/shared/plugin/transfer-state.service.ts b/portal-FE-common/src/app/shared/plugin/transfer-state.service.ts new file mode 100644 index 00000000..e42abcb8 --- /dev/null +++ b/portal-FE-common/src/app/shared/plugin/transfer-state.service.ts @@ -0,0 +1,85 @@ +/*- + * ============LICENSE_START========================================== + * ONAP Portal + * =================================================================== + * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * =================================================================== + * + * Unless otherwise specified, all software contained herein is licensed + * under the Apache License, Version 2.0 (the "License"); + * you may not use this software except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * Unless otherwise specified, all documentation contained herein is licensed + * under the Creative Commons License, Attribution 4.0 Intl. (the "License"); + * you may not use this documentation except in compliance with the License. + * You may obtain a copy of the License at + * + * https://creativecommons.org/licenses/by/4.0/ + * + * Unless required by applicable law or agreed to in writing, documentation + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * ============LICENSE_END============================================ + * + * + */ + +import { Inject, Injectable, PLATFORM_ID } from '@angular/core'; +import { makeStateKey, TransferState } from '@angular/platform-browser'; +import { isPlatformBrowser, isPlatformServer } from '@angular/common'; +import { of } from 'rxjs'; +import { tap } from 'rxjs/operators'; + +let isBrowser: boolean; +let isServer: boolean; +let transferState: TransferState; + +@Injectable({ + providedIn: 'root' +}) +export class TransferStateService { + constructor( + private state: TransferState, + @Inject(PLATFORM_ID) private platformId: any + ) { + transferState = state; + isBrowser = isPlatformBrowser(this.platformId); + isServer = isPlatformServer(this.platformId); + } +} + +export const preserveServerState = ( + keyName: string, + emptyResult: any = null +) => { + const key = makeStateKey(keyName); + return (target: any, propertyKey: string, descriptor: PropertyDescriptor) => { + const method = descriptor.value; + descriptor.value = function() { + if (isBrowser && transferState.hasKey(key)) { + const state = transferState.get(key, emptyResult); + return of(state); + } + + return method.apply(this, arguments).pipe( + tap(res => { + // if (isServer) { + transferState.set(key, res); + // } + }) + ); + }; + }; +}; |