From: Bill Erickson Date: Mon, 13 Jun 2022 19:36:38 +0000 (-0400) Subject: LP1840773 SCKO Angular X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fc276237992ab7a49669956569d13fc03cfe2aca;p=working%2FEvergreen.git LP1840773 SCKO Angular Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/src/eg2/src/app/core/auth.service.ts b/Open-ILS/src/eg2/src/app/core/auth.service.ts index 7a04f5874a..682b730855 100644 --- a/Open-ILS/src/eg2/src/app/core/auth.service.ts +++ b/Open-ILS/src/eg2/src/app/core/auth.service.ts @@ -40,6 +40,9 @@ export enum AuthWsState { @Injectable({providedIn: 'root'}) export class AuthService { + // Override this to store authtokens, etc. in a different location + storePrefix = 'eg.auth'; + private authChannel: any; private activeUser: AuthUser = null; @@ -62,7 +65,7 @@ export class AuthService { // Returns true if we are currently in op-change mode. opChangeIsActive(): boolean { - return Boolean(this.store.getLoginSessionItem('eg.auth.time.oc')); + return Boolean(this.store.getLoginSessionItem(`${this.storePrefix}.time.oc`)); } // - Accessor functions always refer to the active user. @@ -92,8 +95,8 @@ export class AuthService { // Only necessary on new page loads. During op-change, // for example, we already have an activeUser. this.activeUser = new AuthUser( - this.store.getLoginSessionItem('eg.auth.token'), - this.store.getLoginSessionItem('eg.auth.time') + this.store.getLoginSessionItem(`${this.storePrefix}.token`), + this.store.getLoginSessionItem(`${this.storePrefix}.time`) ); } @@ -175,8 +178,8 @@ export class AuthService { handleLoginOk(args: AuthLoginArgs, evt: EgEvent, isOpChange: boolean): Promise { if (isOpChange) { - this.store.setLoginSessionItem('eg.auth.token.oc', this.token()); - this.store.setLoginSessionItem('eg.auth.time.oc', this.authtime()); + this.store.setLoginSessionItem(`${this.storePrefix}.token.oc`, this.token()); + this.store.setLoginSessionItem(`${this.storePrefix}.time.oc`, this.authtime()); } this.activeUser = new AuthUser( @@ -185,8 +188,8 @@ export class AuthService { args.workstation ); - this.store.setLoginSessionItem('eg.auth.token', this.token()); - this.store.setLoginSessionItem('eg.auth.time', this.authtime()); + this.store.setLoginSessionItem(`${this.storePrefix}.token`, this.token()); + this.store.setLoginSessionItem(`${this.storePrefix}.time`, this.authtime()); return Promise.resolve(); } @@ -195,14 +198,14 @@ export class AuthService { if (this.opChangeIsActive()) { this.deleteSession(); this.activeUser = new AuthUser( - this.store.getLoginSessionItem('eg.auth.token.oc'), - this.store.getLoginSessionItem('eg.auth.time.oc'), + this.store.getLoginSessionItem(`${this.storePrefix}.token.oc`), + this.store.getLoginSessionItem(`${this.storePrefix}.time.oc`), this.activeUser.workstation ); - this.store.removeLoginSessionItem('eg.auth.token.oc'); - this.store.removeLoginSessionItem('eg.auth.time.oc'); - this.store.setLoginSessionItem('eg.auth.token', this.token()); - this.store.setLoginSessionItem('eg.auth.time', this.authtime()); + this.store.removeLoginSessionItem(`${this.storePrefix}.token.oc`); + this.store.removeLoginSessionItem(`${this.storePrefix}.time.oc`); + this.store.setLoginSessionItem(`${this.storePrefix}.token`, this.token()); + this.store.setLoginSessionItem(`${this.storePrefix}.time`, this.authtime()); } // Re-fetch the user. return this.testAuthToken(); diff --git a/Open-ILS/src/eg2/src/app/scko/banner.component.html b/Open-ILS/src/eg2/src/app/scko/banner.component.html new file mode 100644 index 0000000000..61e6aa9c16 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/scko/banner.component.html @@ -0,0 +1,98 @@ + +
+
+ +
+
+ +
+ Please log in with your username or library barcode. +
+
+
+
+
+ + + + + + + + +
+
+
+
+
+ +
+
+ +
+ +
+
+

Staff Account Login

+
+
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ +
+
+
Login Failed
+
+
+
+
+
+
diff --git a/Open-ILS/src/eg2/src/app/scko/banner.component.ts b/Open-ILS/src/eg2/src/app/scko/banner.component.ts new file mode 100644 index 0000000000..8bd9a56b8e --- /dev/null +++ b/Open-ILS/src/eg2/src/app/scko/banner.component.ts @@ -0,0 +1,113 @@ +import {Component, OnInit, NgZone, HostListener} from '@angular/core'; +import {Location} from '@angular/common'; +import {Router, ActivatedRoute, NavigationEnd} from '@angular/router'; +import {AuthService, AuthWsState} from '@eg/core/auth.service'; +import {StoreService} from '@eg/core/store.service'; +import {SckoService} from './scko.service'; +import {OrgService} from '@eg/core/org.service'; + +@Component({ + selector: 'eg-scko-banner', + templateUrl: 'banner.component.html' +}) + +export class SckoBannerComponent implements OnInit { + + workstations: any[]; + loginFailed = false; + workstationNotFound = false; + + patronUsername: string; + patronPassword: string; + + staffUsername: string; + staffPassword: string; + staffWorkstation: string; + + constructor( + private route: ActivatedRoute, + private store: StoreService, + private auth: AuthService, + private ngLocation: Location, + private org: OrgService, + public scko: SckoService + ) {} + + ngOnInit() { + + const node = document.getElementById('staff-username'); + + console.log('PFX', this.scko.auth.storePrefix); + console.log(this.scko.auth.token()); + console.log(this.scko.auth.user()); + + // NOTE: Displaying a list of workstations will not work for users + // of Hatch until the extension is updated to support /eg2/*/scko + this.store.getWorkstations() + .then(wsList => { + this.workstations = wsList; + return this.store.getDefaultWorkstation(); + }).then(def => { + this.staffWorkstation = def; + this.applyWorkstation(); + }); + } + + applyWorkstation() { + const wanted = this.route.snapshot.queryParamMap.get('workstation'); + if (!wanted) { return; } // use the default + + const exists = this.workstations.filter(w => w.name === wanted)[0]; + if (exists) { + this.staffWorkstation = wanted; + } else { + console.error(`Unknown workstation requested: ${wanted}`); + } + } + + submitStaffLogin() { + + this.loginFailed = false; + + const args = { + type: 'persistent', + username: this.staffUsername, + password: this.staffPassword, + workstation: this.staffWorkstation + }; + + this.loginFailed = false; + this.workstationNotFound = false; + + this.auth.login(args).then( + ok => { + + if (this.auth.workstationState === AuthWsState.NOT_FOUND_SERVER) { + this.loginFailed = true; + this.workstationNotFound = true; + + } else { + + // Initial login clears cached org unit setting values + // and user/workstation setting values + this.org.clearCachedSettings().then(_ => { + + // Force reload of the app after a successful login. + // This allows the route resolver to re-run with a + // valid auth token and workstation. + window.location.href = + this.ngLocation.prepareExternalUrl('/scko'); + + }); + } + }, + notOk => { + this.loginFailed = true; + } + ); + } + + submitPatronLogin() { + } +} + diff --git a/Open-ILS/src/eg2/src/app/scko/routing.module.ts b/Open-ILS/src/eg2/src/app/scko/routing.module.ts index be056adf54..6d52229ab1 100644 --- a/Open-ILS/src/eg2/src/app/scko/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/scko/routing.module.ts @@ -4,7 +4,12 @@ import {SckoComponent} from './scko.component'; const routes: Routes = [{ path: '', - component: SckoComponent + component: SckoComponent, + /* + children: [{ + + }] + */ }]; @NgModule({ diff --git a/Open-ILS/src/eg2/src/app/scko/scko.component.html b/Open-ILS/src/eg2/src/app/scko/scko.component.html index 33a7795c69..24bf192c56 100644 --- a/Open-ILS/src/eg2/src/app/scko/scko.component.html +++ b/Open-ILS/src/eg2/src/app/scko/scko.component.html @@ -1,34 +1,7 @@ -
-
- -
-
- -
- Please log in with your username or library barcode. -
-
-
-
- - - - - -
-
-
-
-
-
+ -
- - -
+ diff --git a/Open-ILS/src/eg2/src/app/scko/scko.component.ts b/Open-ILS/src/eg2/src/app/scko/scko.component.ts index 2ca8289d6e..e3f90a50bc 100644 --- a/Open-ILS/src/eg2/src/app/scko/scko.component.ts +++ b/Open-ILS/src/eg2/src/app/scko/scko.component.ts @@ -1,24 +1,20 @@ -import {Component, OnInit, NgZone, HostListener} from '@angular/core'; +import {Component, OnInit, ViewEncapsulation} from '@angular/core'; import {Router, ActivatedRoute, NavigationEnd} from '@angular/router'; -import {AuthService, AuthWsState} from '@eg/core/auth.service'; -import {NetService} from '@eg/core/net.service'; -import {IdlObject, IdlService} from '@eg/core/idl.service'; +import {AuthService} from '@eg/core/auth.service'; +import {SckoService} from './scko.service'; @Component({ templateUrl: 'scko.component.html', - styleUrls: ['scko.component.css'] + styleUrls: ['scko.component.css'], + encapsulation: ViewEncapsulation.None }) export class SckoComponent implements OnInit { - // Currently active patron account object. - patron: IdlObject; - constructor( private router: Router, private route: ActivatedRoute, - private net: NetService, - private auth: AuthService, + public scko: SckoService ) {} ngOnInit() { diff --git a/Open-ILS/src/eg2/src/app/scko/scko.module.ts b/Open-ILS/src/eg2/src/app/scko/scko.module.ts index f386f6b8ba..31f202dc30 100644 --- a/Open-ILS/src/eg2/src/app/scko/scko.module.ts +++ b/Open-ILS/src/eg2/src/app/scko/scko.module.ts @@ -6,15 +6,21 @@ import {TitleComponent} from '@eg/share/title/title.component'; import {SckoComponent} from './scko.component'; import {SckoRoutingModule} from './routing.module'; +import {SckoService} from './scko.service'; +import {SckoBannerComponent} from './banner.component'; @NgModule({ declarations: [ SckoComponent, + SckoBannerComponent, ], imports: [ EgCommonModule, CommonWidgetsModule, SckoRoutingModule + ], + providers: [ + SckoService ] }) diff --git a/Open-ILS/src/eg2/src/app/scko/scko.service.ts b/Open-ILS/src/eg2/src/app/scko/scko.service.ts new file mode 100644 index 0000000000..cdfc91df81 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/scko/scko.service.ts @@ -0,0 +1,24 @@ +import {Injectable, EventEmitter} from '@angular/core'; +import {NetService} from '@eg/core/net.service'; +import {AuthService} from '@eg/core/auth.service'; +import {EventService, EgEvent} from '@eg/core/event.service'; +import {IdlService, IdlObject} from '@eg/core/idl.service'; +import {StoreService} from '@eg/core/store.service'; +import {ServerStoreService} from '@eg/core/server-store.service'; + +@Injectable({providedIn: 'root'}) +export class SckoService { + + // Currently active patron account object. + patron: IdlObject; + + constructor( + private net: NetService, + public auth: AuthService + ) { + this.auth.storePrefix = 'eg.scko'; + } +} + + +