From c9805d85a9bf88a2264282cfa8fe4fc334b5c5ec Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Wed, 25 Apr 2018 16:50:11 -0400 Subject: [PATCH] LP#1626157 op-change, toast; strings cont. Signed-off-by: Bill Erickson --- Open-ILS/src/eg2/src/app/core/auth.service.ts | 41 ++++++++++++---------- .../eg2/src/app/share/string/string.component.ts | 12 ++++--- .../src/eg2/src/app/share/string/string.service.ts | 2 +- Open-ILS/src/eg2/src/app/staff/nav.component.html | 15 +++++--- Open-ILS/src/eg2/src/app/staff/nav.component.ts | 30 +++++----------- .../staff/share/op-change/op-change.component.ts | 34 ++++++++++++++---- 6 files changed, 78 insertions(+), 56 deletions(-) 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 9bd05dcc5a..84de51a8e6 100644 --- a/Open-ILS/src/eg2/src/app/core/auth.service.ts +++ b/Open-ILS/src/eg2/src/app/core/auth.service.ts @@ -42,12 +42,7 @@ export class EgAuthService { private authChannel: any; - private activeUser: EgAuthUser; - - // opChangeUser refers to the user that has been superseded during - // an op-change event. opChangeUser resumes its status as the - // activeUser once the op-change cycle has completed. - private opChangeUser: EgAuthUser = null; + private activeUser: EgAuthUser = null; workstationState: EgAuthWsState = EgAuthWsState.PENDING; @@ -72,7 +67,7 @@ export class EgAuthService { // Returns true if we are currently in op-change mode. opChangeIsActive(): boolean { - return this.opChangeUser !== null; + return Boolean(this.store.getLoginSessionItem('eg.auth.time.oc')); } // - Accessor functions always refer to the active user. @@ -95,12 +90,17 @@ export class EgAuthService { }; // NOTE: EgNetService emits an event if the auth session has expired. + // This only rejects when no authtoken is found. testAuthToken(): Promise { - this.activeUser = new EgAuthUser( - this.store.getLoginSessionItem('eg.auth.token'), - this.store.getLoginSessionItem('eg.auth.time') - ); + if (!this.activeUser) { + // Only necessary on new page loads. During op-change, + // for example, we already have an activeUser. + this.activeUser = new EgAuthUser( + this.store.getLoginSessionItem('eg.auth.token'), + this.store.getLoginSessionItem('eg.auth.time') + ); + } if (!this.token()) return Promise.reject('no authtoken'); @@ -129,8 +129,7 @@ export class EgAuthService { switch (evt.textcode) { case 'SUCCESS': - this.handleLoginOk(args, evt, isOpChange); - return Promise.resolve(); + return this.handleLoginOk(args, evt, isOpChange); case 'WORKSTATION_NOT_FOUND': console.error(`No such workstation "${args.workstation}"`); @@ -145,12 +144,11 @@ export class EgAuthService { } // Stash the login data - handleLoginOk(args: EgAuthLoginArgs, evt: EgEvent, isOpChange: boolean): void { + handleLoginOk(args: EgAuthLoginArgs, 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.opChangeUser = this.activeUser; } this.activeUser = new EgAuthUser( @@ -161,18 +159,24 @@ export class EgAuthService { this.store.setLoginSessionItem('eg.auth.token', this.token()); this.store.setLoginSessionItem('eg.auth.time', this.authtime()); + + return Promise.resolve(); } undoOpChange(): Promise { - if (this.opChangeUser) { + if (this.opChangeIsActive()) { this.deleteSession(); - this.activeUser = this.opChangeUser; - this.opChangeUser = null; + this.activeUser = new EgAuthUser( + this.store.getLoginSessionItem('eg.auth.token.oc'), + this.store.getLoginSessionItem('eg.auth.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()); } + // Re-fetch the user. return this.testAuthToken(); } @@ -281,7 +285,6 @@ export class EgAuthService { // Remove/reset session data cleanup(): void { this.activeUser = null; - this.opChangeUser = null; if (this.pollTimeout) { clearTimeout(this.pollTimeout); this.pollTimeout = null; diff --git a/Open-ILS/src/eg2/src/app/share/string/string.component.ts b/Open-ILS/src/eg2/src/app/share/string/string.component.ts index 13e442c6b8..8c81898b73 100644 --- a/Open-ILS/src/eg2/src/app/share/string/string.component.ts +++ b/Open-ILS/src/eg2/src/app/share/string/string.component.ts @@ -31,10 +31,14 @@ export class EgStringComponent implements OnInit { } ngOnInit() { - this.strings.register({ - key: this.key, - resolver: (ctx:any) => this.current(ctx) - }); + // No key means it's an unregistered (likely static) string + // that does not need interpolation. + if (this.key) { + this.strings.register({ + key: this.key, + resolver: (ctx:any) => this.current(ctx) + }); + } } diff --git a/Open-ILS/src/eg2/src/app/share/string/string.service.ts b/Open-ILS/src/eg2/src/app/share/string/string.service.ts index 0e3e706f6c..1af8083a9f 100644 --- a/Open-ILS/src/eg2/src/app/share/string/string.service.ts +++ b/Open-ILS/src/eg2/src/app/share/string/string.service.ts @@ -16,7 +16,7 @@ export class EgStringService { this.strings[assn.key] = assn; } - interpolate(key: string, ctx: any): Promise { + interpolate(key: string, ctx?: any): Promise { if (!this.strings[key]) return Promise.reject('No Such String'); return this.strings[key].resolver(ctx); diff --git a/Open-ILS/src/eg2/src/app/staff/nav.component.html b/Open-ILS/src/eg2/src/app/staff/nav.component.html index a56fd1668a..c5d5fcbf93 100644 --- a/Open-ILS/src/eg2/src/app/staff/nav.component.html +++ b/Open-ILS/src/eg2/src/app/staff/nav.component.html @@ -186,10 +186,10 @@ -