LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Thu, 30 Nov 2017 22:14:27 +0000 (17:14 -0500)
committerBill Erickson <berickxx@gmail.com>
Mon, 11 Dec 2017 17:39:51 +0000 (12:39 -0500)
Signed-off-by: Bill Erickson <berickxx@gmail.com>
Open-ILS/webby-src/src/app/core/auth.ts
Open-ILS/webby-src/src/app/core/net.service.ts
Open-ILS/webby-src/src/app/core/org.ts
Open-ILS/webby-src/src/app/core/pcrud.ts
Open-ILS/webby-src/src/app/resolver.service.ts
Open-ILS/webby-src/src/app/staff/admin/workstation/workstations.component.ts
Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.ts
Open-ILS/webby-src/src/app/staff/login.component.ts
Open-ILS/webby-src/src/app/staff/resolver.service.ts
Open-ILS/webby-src/src/app/staff/share/org-select.component.ts
Open-ILS/webby-src/src/app/staff/staff.component.ts

index 6d94d80..07668fa 100644 (file)
@@ -54,8 +54,8 @@ export class EgAuthService {
 
     constructor(
         private egEvt: EgEventService,
-        private egNet: EgNetService,
-        private egStore: EgStoreService
+        private net: EgNetService,
+        private store: EgStoreService
     ) {}
 
     // - Accessor functions alway refer to the active user.
@@ -81,14 +81,14 @@ export class EgAuthService {
     testAuthToken(): Promise<any> {
 
         this.activeUser = new EgAuthUser(
-            this.egStore.getLoginSessionItem('eg.auth.token'),
-            this.egStore.getLoginSessionItem('eg.auth.time')
+            this.store.getLoginSessionItem('eg.auth.token'),
+            this.store.getLoginSessionItem('eg.auth.time')
         );
 
         if (!this.token()) return Promise.reject('no authtoken');
 
         return new Promise<any>( (resolve, reject) => {
-            this.egNet.request(
+            this.net.request(
                 'open-ils.auth',
                 'open-ils.auth.session.retrieve', this.token()
             ).subscribe(
@@ -112,7 +112,7 @@ export class EgAuthService {
     login(args: EgAuthLoginArgs, isOpChange?: boolean): Promise<void> {
 
         return new Promise<void>((resolve, reject) => {
-            this.egNet.request('open-ils.auth', 'open-ils.auth.login', args)
+            this.net.request('open-ils.auth', 'open-ils.auth.login', args)
             .subscribe(res => {
                 this.handleLoginResponse(args, this.egEvt.parse(res), isOpChange)
                 .then(
@@ -147,8 +147,8 @@ export class EgAuthService {
     handleLoginOk(args: EgAuthLoginArgs, evt: EgEvent, isOpChange: boolean): void {
 
         if (isOpChange) {
-            this.egStore.setLoginSessionItem('eg.auth.token.oc', this.token());
-            this.egStore.setLoginSessionItem('eg.auth.time.oc', this.authtime());
+            this.store.setLoginSessionItem('eg.auth.token.oc', this.token());
+            this.store.setLoginSessionItem('eg.auth.time.oc', this.authtime());
             this.opChangeUser = this.activeUser;
         }
 
@@ -158,8 +158,8 @@ export class EgAuthService {
             args.workstation
         );
 
-        this.egStore.setLoginSessionItem('eg.auth.token', this.token());
-        this.egStore.setLoginSessionItem('eg.auth.time', this.authtime());
+        this.store.setLoginSessionItem('eg.auth.token', this.token());
+        this.store.setLoginSessionItem('eg.auth.time', this.authtime());
     }
 
     undoOpChange(): Promise<any> {
@@ -167,10 +167,10 @@ export class EgAuthService {
             this.deleteSession();
             this.activeUser = this.opChangeUser;
             this.opChangeUser = null;
-            this.egStore.removeLoginSessionItem('eg.auth.token.oc');                
-            this.egStore.removeLoginSessionItem('eg.auth.time.oc');                 
-            this.egStore.setLoginSessionItem('eg.auth.token', this.token());
-            this.egStore.setLoginSessionItem('eg.auth.time', this.authtime());
+            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());
         }
         return this.testAuthToken();
     }
@@ -196,7 +196,7 @@ export class EgAuthService {
                 return;
             }
 
-            this.egStore.getItem('eg.workstation.all')
+            this.store.getItem('eg.workstation.all')
             .then(workstations => {
                 if (!workstations) workstations = [];
 
@@ -217,7 +217,7 @@ export class EgAuthService {
 
     deleteSession(): void {
         if (this.token()) {
-            this.egNet.request(
+            this.net.request(
                 'open-ils.auth',
                 'open-ils.auth.session.delete', this.token())
             .subscribe(x => console.log('logged out'))
@@ -232,7 +232,7 @@ export class EgAuthService {
         }
 
         this.deleteSession();
-        this.egStore.clearLoginSessionItems();                                  
+        this.store.clearLoginSessionItems();                                  
         this.activeUser = null;
         this.opChangeUser = null;
     }
index 0d98d17..b037de1 100644 (file)
@@ -1,6 +1,6 @@
 /**
  * 
- * constructor(private egNet : EgNetService) {
+ * constructor(private net : EgNetService) {
  *   ...
  *   egNet.request(service, method, param1 [, param2, ...])
  *     .subscribe(
index 460b1e3..cad7930 100644 (file)
@@ -13,7 +13,7 @@ export class EgOrgService {
     private orgTree: EgIdlObject; // root node + children
 
     constructor(
-        private egPcrud: EgPcrudService
+        private pcrud: EgPcrudService
     ) {}
 
     get(nodeOrId: EgOrgNodeOrId): EgIdlObject {
@@ -116,7 +116,7 @@ export class EgOrgService {
     fetchOrgs(): Promise<void> {
         
         console.log('fetching..');
-        return this.egPcrud.search('aou', {parent_ou : null},
+        return this.pcrud.search('aou', {parent_ou : null},
             {flesh : -1, flesh_fields : {aou : ['children', 'ou_type']}},
             {anonymous : true}
         ).toPromise().then(tree => {
index 42a93ef..b6185cb 100644 (file)
@@ -32,9 +32,9 @@ export class EgPcrudContext {
     private cudLast: EgPcrudResponse;
     private cudList: EgIdlObject[];
 
-    private egIdl: EgIdlService;
-    private egNet: EgNetService;
-    private egAuth: EgAuthService;
+    private idl: EgIdlService;
+    private net: EgNetService;
+    private auth: EgAuthService;
 
     // Tracks nested CUD actions 
     cudObserver: Observer<EgPcrudResponse>;
@@ -46,9 +46,9 @@ export class EgPcrudContext {
         egNet: EgNetService,
         egAuth: EgAuthService
     ) {
-        this.egIdl = egIdl;
-        this.egNet = egNet;
-        this.egAuth = egAuth;
+        this.idl = egIdl;
+        this.net = egNet;
+        this.auth = egAuth;
         this.xactCloseMode = 'rollback';
         this.ident = EgPcrudContext.identGenerator++;
         this.session = new OpenSRF.ClientSession('open-ils.pcrud');
@@ -69,7 +69,7 @@ export class EgPcrudContext {
 
     token(reqOps?: EgPcrudReqOps): string {
         return (reqOps && reqOps.anonymous) ?
-            'ANONYMOUS' : this.egAuth.token();
+            'ANONYMOUS' : this.auth.token();
     }
 
     connect(): Promise<EgPcrudContext> {
@@ -98,7 +98,7 @@ export class EgPcrudContext {
     retrieveAll(fmClass: string, pcrudOps?: any, 
             reqOps?: EgPcrudReqOps): Observable<EgPcrudResponse> {
         let search = {};
-        search[this.egIdl.classes[fmClass].pkey] = {'!=' : null};
+        search[this.idl.classes[fmClass].pkey] = {'!=' : null};
         return this.search(fmClass, search, pcrudOps, reqOps);
     }
 
@@ -192,7 +192,7 @@ export class EgPcrudContext {
 
         this.log(`sendRequest(${method})`);
 
-        return this.egNet.requestCompiled(
+        return this.net.requestCompiled(
             new EgNetRequest(
                 'open-ils.pcrud', method, params, this.session)
         );
@@ -261,9 +261,9 @@ export class EgPcrudContext {
 export class EgPcrudService {
 
     constructor(
-        private egIdl: EgIdlService,
-        private egNet: EgNetService,
-        private egAuth: EgAuthService
+        private idl: EgIdlService,
+        private net: EgNetService,
+        private auth: EgAuthService
     ) {}
 
     // Pass-thru functions for one-off PCRUD calls
@@ -273,7 +273,7 @@ export class EgPcrudService {
     }
 
     newContext(): EgPcrudContext {
-        return new EgPcrudContext(this.egIdl, this.egNet, this.egAuth);
+        return new EgPcrudContext(this.idl, this.net, this.auth);
     }
 
     retrieve(fmClass: string, pkey: Number | string, 
index c63b2d5..b699fce 100644 (file)
@@ -9,8 +9,8 @@ export class EgBaseResolver implements Resolve<Promise<void>> {
 
     constructor(
         private router: Router, 
-        private egIdl: EgIdlService,
-        private egOrg: EgOrgService,
+        private idl: EgIdlService,
+        private org: EgOrgService,
     ) {}
 
     resolve(
@@ -20,9 +20,9 @@ export class EgBaseResolver implements Resolve<Promise<void>> {
         console.debug('EgBaseResolver:resolve()');
 
         // Safe to assume some data is needed by all applications.
-        this.egIdl.parseIdl();
+        this.idl.parseIdl();
 
-        return this.egOrg.fetchOrgs();
+        return this.org.fetchOrgs();
         // load other common stuff...
     }
 }
index 456e2c2..8508e2b 100644 (file)
@@ -27,7 +27,7 @@ export class EgWorkstationsComponent implements OnInit {
     // Org selector callbacks
     shouldDisableOrg = (org: EgIdlObject): boolean => {
         // TODO: check register perms too
-        return !this.egOrg.canHaveUsers(org);
+        return !this.org.canHaveUsers(org);
     }
 
     shouldHideOrg = (org: EgIdlObject): boolean => {
@@ -36,22 +36,20 @@ export class EgWorkstationsComponent implements OnInit {
 
     orgOnChange = (org: EgIdlObject): void => {
         console.log('org changed to ' + org.shortname());
+        this.newOwner = org;
     }
 
-
     constructor(
         private route: ActivatedRoute,
-        private egNet: EgNetService,
-        private egAuth: EgAuthService,
-        private egStore: EgStoreService,
-        private egOrg: EgOrgService
+        private net: EgNetService,
+        private store: EgStoreService,
+        private auth: EgAuthService,
+        private org: EgOrgService
     ) {}
 
     ngOnInit() {
-        this.egStore.getItem('eg.workstation.all')
+        this.store.getItem('eg.workstation.all')
         .then(res => this.workstations = res);
-
-        this.newOwner = this.egOrg.root();
     }
 
     selected(): Workstation {
index 3b2cfe1..3cc225e 100644 (file)
@@ -14,8 +14,8 @@ export class EgBcSearchComponent implements OnInit {
 
     constructor(
         private route: ActivatedRoute,
-        private egNet: EgNetService,
-        private egAuth: EgAuthService
+        private net: EgNetService,
+        private auth: EgAuthService
     ) {}
 
     ngOnInit() {
@@ -30,7 +30,7 @@ export class EgBcSearchComponent implements OnInit {
             console.debug('EgBcSearch ngOnInit complete');
         });
 
-        this.egNet.request(
+        this.net.request(
             'open-ils.actor',
             'opensrf.system.echo',
             'hello', 'goodbye', 'in the middle'
index 3dd9494..7ec4623 100644 (file)
@@ -24,14 +24,14 @@ export class EgStaffLoginComponent implements OnInit {
       private router: Router,
       private ngLocation: Location,
       private renderer: Renderer,
-      private egAuth: EgAuthService,
-      private egStore: EgStoreService 
+      private auth: EgAuthService,
+      private store: EgStoreService 
     ) {}
     
     ngOnInit() {
 
         // clear out any stale auth data
-        this.egAuth.logout();
+        this.auth.logout();
 
         // Focus username
         this.renderer.selectRootElement('#username').focus();
@@ -39,7 +39,7 @@ export class EgStaffLoginComponent implements OnInit {
         // load browser-local workstation data
 
         // TODO: insert for testing.
-        this.egStore.setItem(
+        this.store.setItem(
           'eg.workstation.all', 
           [{name:'BR1-skiddoo',id:1,owning_lib:4}]
         ); 
@@ -48,13 +48,13 @@ export class EgStaffLoginComponent implements OnInit {
     handleSubmit() {
 
         // post-login URL
-        let url: string = this.egAuth.redirectUrl || '/staff/splash';
+        let url: string = this.auth.redirectUrl || '/staff/splash';
 
-        this.egAuth.login(this.args).then(
+        this.auth.login(this.args).then(
             ok => {
-                this.egAuth.redirectUrl = null;
+                this.auth.redirectUrl = null;
 
-                if (this.egAuth.workstationState == EgAuthWsState.NOT_FOUND_SERVER) {
+                if (this.auth.workstationState == EgAuthWsState.NOT_FOUND_SERVER) {
                     // User is logged in without a workstation.
                     // Redirect them to the WS admin page.
                     this.router.navigate(
index 21eddec..4c7fdf5 100644 (file)
@@ -21,9 +21,9 @@ export class EgStaffResolver implements Resolve<Observable<any>> {
     constructor(
         private router: Router, 
         private ngLocation: Location,
-        private egStore: EgStoreService,
-        private egNet: EgNetService,
-        private egAuth: EgAuthService
+        private store: EgStoreService,
+        private net: EgNetService,
+        private auth: EgAuthService
     ) {}
 
     resolve(
@@ -33,16 +33,16 @@ export class EgStaffResolver implements Resolve<Observable<any>> {
         console.debug('EgStaffResolver:resolve()');
 
         // Staff cookies stay in /$base/staff/
-        this.egStore.loginSessionBasePath = 
+        this.store.loginSessionBasePath = 
             this.ngLocation.prepareExternalUrl('/staff');
 
         // Login resets everything.  No need to load data.
         if (state.url == '/staff/login') return Observable.of(true);
 
         return Observable.create(observer => {
-            this.egAuth.testAuthToken().then(
+            this.auth.testAuthToken().then(
                 tokenOk => {
-                    this.egAuth.verifyWorkstation().then(
+                    this.auth.verifyWorkstation().then(
                         wsOk => {
                             this.loadStartupData(observer).then(
                                 ok => observer.complete()
@@ -58,7 +58,7 @@ export class EgStaffResolver implements Resolve<Observable<any>> {
                 }, 
                 tokenNotOk => {
                     // Authtoken is not OK.
-                    this.egAuth.redirectUrl = state.url;
+                    this.auth.redirectUrl = state.url;
                     this.router.navigate([this.loginPath]);
                     observer.complete();
                 }
index ee1fa5f..d5a361a 100644 (file)
@@ -39,9 +39,9 @@ export class EgOrgSelectComponent implements OnInit {
     @Input() shouldHide: (org:EgIdlObject) => boolean;
 
     constructor(
-      private egAuth: EgAuthService,
-      private egStore: EgStoreService,
-      private egOrg: EgOrgService 
+      private auth: EgAuthService,
+      private store: EgStoreService,
+      private org: EgOrgService 
     ) {}
     
     ngOnInit() {
@@ -49,7 +49,7 @@ export class EgOrgSelectComponent implements OnInit {
 
     orgChanged(selEvent: NgbTypeaheadSelectItemEvent) {
         if (this.onChange) {
-            this.onChange(this.egOrg.get(selEvent.item.id));
+            this.onChange(this.org.get(selEvent.item.id));
         }
     }
 
@@ -63,7 +63,7 @@ export class EgOrgSelectComponent implements OnInit {
             .map(term => {
 
                 // TODO: displayField / shortname
-                return this.egOrg.list().filter(org => {
+                return this.org.list().filter(org => {
 
                     // Find orgs matching the search term
                     return org.shortname()
index 836a92b..572e44e 100644 (file)
@@ -15,8 +15,8 @@ export class EgStaffComponent implements OnInit {
     constructor(
         private router: Router,
         private route: ActivatedRoute,
-        private egNet: EgNetService,
-        private egAuth: EgAuthService
+        private net: EgNetService,
+        private auth: EgAuthService
     ) {}
 
     ngOnInit() {
@@ -30,9 +30,9 @@ export class EgStaffComponent implements OnInit {
         });
 
         // Redirect to the login page on any auth timeout events.
-        this.egNet.authExpired$.subscribe(uhOh => {
+        this.net.authExpired$.subscribe(uhOh => {
             console.log('Auth session has expired.  Send to login');
-            this.egAuth.redirectUrl = this.router.url;
+            this.auth.redirectUrl = this.router.url;
             this.router.navigate(['/staff/login']);
         });
 
@@ -55,14 +55,14 @@ export class EgStaffComponent implements OnInit {
         // Access to login page is always granted
         if (routeEvent.url == this.loginPath) return;
 
-        if (!this.egAuth.token()) 
+        if (!this.auth.token()) 
             this.router.navigate([this.loginPath]);
 
         // Access to workstation admin page is granted regardless
         // of workstation validity.
         if (routeEvent.url == this.wsAdminPath) return;
 
-        if (this.egAuth.workstationState != EgAuthWsState.VALID)
+        if (this.auth.workstationState != EgAuthWsState.VALID)
             this.router.navigate([this.wsAdminPath]);
     }
 }