From 0702ecdde4883b057ccfe2ea266450758f4ab155 Mon Sep 17 00:00:00 2001 From: Jamil Omar Date: Thu, 27 Feb 2020 14:56:07 -0500 Subject: [PATCH] fix: shell-ui template --- templates/ui-package/README.md | 2 +- templates/ui-package/config/default.js | 2 ++ templates/ui-package/package.json | 4 ++-- templates/ui-package/src/app/app.component.ts | 6 +---- templates/ui-package/src/app/app.module.ts | 23 +++++++++++++------ .../ui-package/src/app/auth/auth.component.ts | 4 ++++ .../src/app/forms/forms.component.spec.ts | 9 +++++++- .../app/shell/version/version.component.ts | 2 +- templates/ui-package/src/index.d.ts | 6 ++--- templates/ui-package/src/main.ts | 2 +- 10 files changed, 39 insertions(+), 21 deletions(-) diff --git a/templates/ui-package/README.md b/templates/ui-package/README.md index 55cdd9c..3bc4868 100644 --- a/templates/ui-package/README.md +++ b/templates/ui-package/README.md @@ -54,7 +54,7 @@ Run `ng e2e` to execute the end-to-end tests via [Protractor](http://www.protrac ## Env Vars For adding env vars , you can use the .env file. For more information check -[Shell CLI README](https://github.com/angular/shell-ui/blob/master/README.md). +[Shell CLI README](https://github.com/angular/shell-ui/blob/master/README.md).. ## Further help diff --git a/templates/ui-package/config/default.js b/templates/ui-package/config/default.js index 24171ef..8a01d7b 100644 --- a/templates/ui-package/config/default.js +++ b/templates/ui-package/config/default.js @@ -1,7 +1,9 @@ module.exports = { test: process.env.TEST_VAL, + production: false, services: { auth: { + authFlowType: 'code', url: process.env.SERVICES_AUTH_URL, clientId: process.env.SERVICES_AUTH_CLIENT_ID, tenant: process.env.SERVICES_AUTH_TENANT diff --git a/templates/ui-package/package.json b/templates/ui-package/package.json index 2dc39e7..36b0e4c 100644 --- a/templates/ui-package/package.json +++ b/templates/ui-package/package.json @@ -29,8 +29,8 @@ "@angular/router": "~8.2.11", "@labshare/ls-font": "^1.0.0", "@labshare/ngx-core-components": "^1.0.7", - "@labshare/ngx-core-services": "^1.11.0", - "@labshare/shell-ui": "file:../../../LabShare/shell-ui/labshare-shell-ui-1.12.1.tgz", + "@labshare/ngx-core-services": "^2.0.0", + "@labshare/shell-ui": "^2.0.0", "@ng-bootstrap/ng-bootstrap": "^5.2.2", "@ngx-formly/bootstrap": "^5.5.11", "@ngx-formly/core": "^5.5.11", diff --git a/templates/ui-package/src/app/app.component.ts b/templates/ui-package/src/app/app.component.ts index 25b8d90..2c39eb6 100644 --- a/templates/ui-package/src/app/app.component.ts +++ b/templates/ui-package/src/app/app.component.ts @@ -9,11 +9,7 @@ import {filter} from 'rxjs/operators'; styleUrls: ['./app.component.scss'] }) export class AppComponent implements OnInit { - constructor(private authService: AuthService, private router: Router, private eventService: EventService) { - this.authService.configure().subscribe(done => { - this.authService.onAuthCallback(); - }); - } + constructor(private router: Router, private eventService: EventService) {} title = '<%= appNameSlug %>'; ngOnInit(): void { this.eventService diff --git a/templates/ui-package/src/app/app.module.ts b/templates/ui-package/src/app/app.module.ts index a4c95bc..611ebf4 100644 --- a/templates/ui-package/src/app/app.module.ts +++ b/templates/ui-package/src/app/app.module.ts @@ -1,6 +1,6 @@ import {BrowserModule} from '@angular/platform-browser'; import {NgModule, APP_INITIALIZER} from '@angular/core'; -import {HttpClientModule, HttpClient, HTTP_INTERCEPTORS} from '@angular/common/http'; +import {HttpClient} from '@angular/common/http'; import {UsersRouting} from './app-routing.module'; import {NgxCoreComponentsModule} from '@labshare/ngx-core-components'; import {CenterHeaderComponent} from './center-header/center-header.component'; @@ -18,21 +18,26 @@ import { NgxCoreServicesModule, AuthService, ConfigService, - initializerFromUrl, - AuthInterceptor + initializeFromAppConf, + AppType, + EventService } from '@labshare/ngx-core-services'; // this editor should be removed for a real project import {LoggingComponent} from './logging/logging.component'; import {AuthComponent} from './auth/auth.component'; +import {Router} from '@angular/router'; const customThemes = [labshare]; - // Export Angular 8 feature module // app initializer for Auth // app initializer function initialize(http: HttpClient, config: ConfigService, auth: AuthService): () => Promise { return async () => { - return initializerFromUrl(http, config, auth); + if (APP_TYPE === AppType.Site) { + return initializeFromAppConf(http, config, auth); + } else { + return auth.configure().toPromise(); + } }; } @NgModule({ @@ -46,7 +51,7 @@ function initialize(http: HttpClient, config: ConfigService, auth: AuthService): ], imports: [ BrowserModule, - NgxCoreServicesModule.forRoot(APP_CONF), + NgxCoreServicesModule.forRoot({appConf: APP_CONF, appType: APP_TYPE, appBuildVersion: APP_BUILD_VERSION}), NgxCoreComponentsModule.forRoot(customThemes), CommonModule, UsersRouting, @@ -66,4 +71,8 @@ function initialize(http: HttpClient, config: ConfigService, auth: AuthService): ], bootstrap: [AppComponent] }) -export class AppModule {} +export class AppModule { + constructor(private authService: AuthService, private router: Router, private eventService: EventService) { + this.authService.onAuthCallback(); + } +} diff --git a/templates/ui-package/src/app/auth/auth.component.ts b/templates/ui-package/src/app/auth/auth.component.ts index b0bdb67..7634ec4 100644 --- a/templates/ui-package/src/app/auth/auth.component.ts +++ b/templates/ui-package/src/app/auth/auth.component.ts @@ -12,6 +12,10 @@ export class AuthComponent implements OnInit { module.exports = { services: { logging: { + // for apps with no signup page you need to enable + silentRenew :true, + // for changing auth flows - implicit is the default one + authFlowType : 'code', url: process.env.SERVICES_LOG_URL, application: process.env.SERVICES_LOG_APP, environment: process.env.SERVICES_LOG_ENV, diff --git a/templates/ui-package/src/app/forms/forms.component.spec.ts b/templates/ui-package/src/app/forms/forms.component.spec.ts index b964c31..8305817 100644 --- a/templates/ui-package/src/app/forms/forms.component.spec.ts +++ b/templates/ui-package/src/app/forms/forms.component.spec.ts @@ -5,6 +5,7 @@ import {ReactiveFormsModule} from '@angular/forms'; import {FormlyModule} from '@ngx-formly/core'; import {NgxJsonViewerModule} from 'ngx-json-viewer'; import {HttpClientTestingModule} from '@angular/common/http/testing'; +import {FormlyBootstrapModule} from '@ngx-formly/bootstrap'; describe('FormsComponent', () => { let component: FormsComponent; @@ -13,7 +14,13 @@ describe('FormsComponent', () => { beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [FormsComponent], - imports: [HttpClientTestingModule, ReactiveFormsModule, FormlyModule.forRoot(), NgxJsonViewerModule] + imports: [ + HttpClientTestingModule, + ReactiveFormsModule, + FormlyModule.forRoot(), + NgxJsonViewerModule, + FormlyBootstrapModule + ] }).compileComponents(); })); diff --git a/templates/ui-package/src/app/shell/version/version.component.ts b/templates/ui-package/src/app/shell/version/version.component.ts index 47976cf..52cfdbc 100644 --- a/templates/ui-package/src/app/shell/version/version.component.ts +++ b/templates/ui-package/src/app/shell/version/version.component.ts @@ -6,7 +6,7 @@ import {Component, OnInit} from '@angular/core'; styleUrls: ['./version.component.scss'] }) export class VersionComponent implements OnInit { - message = PROJECT_BUILD_VERSION; + message = APP_BUILD_VERSION; constructor() {} ngOnInit() {} diff --git a/templates/ui-package/src/index.d.ts b/templates/ui-package/src/index.d.ts index 22346a9..54faae6 100644 --- a/templates/ui-package/src/index.d.ts +++ b/templates/ui-package/src/index.d.ts @@ -2,6 +2,6 @@ // app configuration injected from shell-ui declare var APP_CONF: any; // project build version injected from shell-ui -declare var PROJECT_BUILD_VERSION: any; -// env var to indicate if the project is built with prod mod -declare var ENABLE_PROD_MODE: true; +declare var APP_BUILD_VERSION: string; +// project app type injected from shell-ui +declare var APP_TYPE: any; diff --git a/templates/ui-package/src/main.ts b/templates/ui-package/src/main.ts index 1e65d2b..b324ed1 100644 --- a/templates/ui-package/src/main.ts +++ b/templates/ui-package/src/main.ts @@ -6,7 +6,7 @@ import {environment} from './environments/environment'; // remove this for real apps import 'prismjs'; -if (environment.production) { +if (APP_CONF.production) { enableProdMode(); }