From: Bill Erickson Date: Wed, 22 Nov 2017 16:06:46 +0000 (-0500) Subject: LP#626157 Ang2 experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=67244eb4bb39896d894f48bb229ca08546c83fad;p=working%2FEvergreen.git LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/webby-src/src/app/base-resolver.service.ts b/Open-ILS/webby-src/src/app/base-resolver.service.ts deleted file mode 100644 index e1e8b731e4..0000000000 --- a/Open-ILS/webby-src/src/app/base-resolver.service.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { Injectable } from '@angular/core'; -import { Observable } from 'rxjs/Observable'; -import { Router, Resolve, RouterStateSnapshot, - ActivatedRouteSnapshot } from '@angular/router'; - -import { EgIdlService } from '@eg/core/idl.service'; - -@Injectable() -export class EgBaseResolver implements Resolve { - - constructor(private router: Router, private egIdl: EgIdlService) {} - - resolve( - route: ActivatedRouteSnapshot, - state: RouterStateSnapshot): Observable { - - console.debug('EgBaseResolver:resolve()'); - - this.egIdl.parseIdl(); - - return Observable.empty(); // Nothing to report. - } -} diff --git a/Open-ILS/webby-src/src/app/base-routing.module.ts b/Open-ILS/webby-src/src/app/base-routing.module.ts deleted file mode 100644 index 7280e37f9e..0000000000 --- a/Open-ILS/webby-src/src/app/base-routing.module.ts +++ /dev/null @@ -1,27 +0,0 @@ -import { NgModule } from '@angular/core'; -import { RouterModule, Routes } from '@angular/router'; -import { EgBaseResolver } from './base-resolver.service'; -import { WelcomeComponent } from './welcome.component'; - -/** - * Avoid adding bulk to the base module by lazy-loading sub-modules. - * When lazy loading, no module references should be directly imported. - * The refs are encoded in the loadChildren attribute of each route. - */ -const routes: Routes = [ - { path: '', - component: WelcomeComponent - }, { - path: 'staff', - resolve : {startup : EgBaseResolver}, - loadChildren: './staff/staff.module#EgStaffModule' - } -]; - -@NgModule({ - imports: [ RouterModule.forRoot(routes) ], - exports: [ RouterModule ], - providers: [ EgBaseResolver ] -}) - -export class EgBaseRoutingModule {} diff --git a/Open-ILS/webby-src/src/app/base.module.ts b/Open-ILS/webby-src/src/app/base.module.ts index 27dca353a7..553e8aa0cc 100644 --- a/Open-ILS/webby-src/src/app/base.module.ts +++ b/Open-ILS/webby-src/src/app/base.module.ts @@ -10,7 +10,7 @@ import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; import { CookieModule } from 'ngx-cookie'; // import CookieMonster import { EgBaseComponent } from './base.component'; -import { EgBaseRoutingModule } from './base-routing.module'; +import { EgBaseRoutingModule } from './routing.module'; import { WelcomeComponent } from './welcome.component'; // Import and 'provide' globally required services. diff --git a/Open-ILS/webby-src/src/app/resolver.service.ts b/Open-ILS/webby-src/src/app/resolver.service.ts new file mode 100644 index 0000000000..e1e8b731e4 --- /dev/null +++ b/Open-ILS/webby-src/src/app/resolver.service.ts @@ -0,0 +1,23 @@ +import { Injectable } from '@angular/core'; +import { Observable } from 'rxjs/Observable'; +import { Router, Resolve, RouterStateSnapshot, + ActivatedRouteSnapshot } from '@angular/router'; + +import { EgIdlService } from '@eg/core/idl.service'; + +@Injectable() +export class EgBaseResolver implements Resolve { + + constructor(private router: Router, private egIdl: EgIdlService) {} + + resolve( + route: ActivatedRouteSnapshot, + state: RouterStateSnapshot): Observable { + + console.debug('EgBaseResolver:resolve()'); + + this.egIdl.parseIdl(); + + return Observable.empty(); // Nothing to report. + } +} diff --git a/Open-ILS/webby-src/src/app/routing.module.ts b/Open-ILS/webby-src/src/app/routing.module.ts new file mode 100644 index 0000000000..8085267fa9 --- /dev/null +++ b/Open-ILS/webby-src/src/app/routing.module.ts @@ -0,0 +1,27 @@ +import { NgModule } from '@angular/core'; +import { RouterModule, Routes } from '@angular/router'; +import { EgBaseResolver } from './resolver.service'; +import { WelcomeComponent } from './welcome.component'; + +/** + * Avoid requiring all apps to load all JS by lazy-loading sub-modules. + * When lazy loading, no module references should be directly imported. + * The refs are encoded in the loadChildren attribute of each route. + */ +const routes: Routes = [ + { path: '', + component: WelcomeComponent + }, { + path: 'staff', + resolve : {startup : EgBaseResolver}, + loadChildren: './staff/staff.module#EgStaffModule' + } +]; + +@NgModule({ + imports: [ RouterModule.forRoot(routes) ], + exports: [ RouterModule ], + providers: [ EgBaseResolver ] +}) + +export class EgBaseRoutingModule {} diff --git a/Open-ILS/webby-src/src/app/staff/auth-guard.service.ts b/Open-ILS/webby-src/src/app/staff/auth-guard.service.ts index f2c276a2f8..d54ec410bc 100644 --- a/Open-ILS/webby-src/src/app/staff/auth-guard.service.ts +++ b/Open-ILS/webby-src/src/app/staff/auth-guard.service.ts @@ -27,7 +27,7 @@ export class EgStaffAuthGuard implements CanActivate, CanActivateChild { err => { this.egAuth.redirectUrl = state.url; this.router.navigate(['/staff/login']); - resolve(false); + resolve(false); // cannot activate } ); }); diff --git a/Open-ILS/webby-src/src/app/staff/routing.module.ts b/Open-ILS/webby-src/src/app/staff/routing.module.ts index df2d784d51..615c3e3c96 100644 --- a/Open-ILS/webby-src/src/app/staff/routing.module.ts +++ b/Open-ILS/webby-src/src/app/staff/routing.module.ts @@ -18,21 +18,25 @@ const routes: Routes = [{ path: 'logout', component: EgStaffLogoutComponent }, { - // Every path below here requires a valid authtoken. path: '', + // Require a valid authtoken to access child paths canActivate : [EgStaffAuthGuard], + // Load data common to all staff UI's before loading child paths. resolve: {dataResolver: EgStaffDataResolver}, + // EgStaffComponent houses the navbar and the page content shell. component: EgStaffComponent, children: [{ - path: '', - redirectTo: 'splash' - pathMatch: 'full', - }, { - path: 'splash', - component: EgStaffSplashComponent - }, { - path: 'circ', - loadChildren : '@eg/staff/circ/circ.module#EgCircModule' + path: '', + redirectTo: 'splash', // must be to sibling path + pathMatch: 'full', + }, { + path: 'splash', + component: EgStaffSplashComponent + }, { + // Lazy-load collections of sub-modules (circ, cat, etc.) + // with loadChildren + path: 'circ', + loadChildren : '@eg/staff/circ/circ.module#EgCircModule' }] }] }];