LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Mon, 20 Nov 2017 22:47:29 +0000 (17:47 -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/base.module.ts
Open-ILS/webby-src/src/app/core/eg-auth.service.ts
Open-ILS/webby-src/src/app/core/eg-event.service.ts [new file with mode: 0644]
Open-ILS/webby-src/src/app/core/eg-event.ts [deleted file]
Open-ILS/webby-src/src/app/core/eg-net.service.ts

index 7358b00..ecb4d28 100644 (file)
@@ -11,9 +11,12 @@ import { NgbModule }     from '@ng-bootstrap/ng-bootstrap';
 import { EgBaseComponent }     from './base.component';
 import { EgBaseRoutingModule } from './base-routing.module';
 import { WelcomeComponent }    from './welcome.component';
-import { EgIdlService }        from '@eg/core/eg-idl.service';
-import { EgNetService }        from '@eg/core/eg-net.service';
-import { EgAuthService }       from '@eg/core/eg-auth.service';
+
+// Import and 'provide' globally required services.
+import { EgEventService } from '@eg/core/eg-event.service';
+import { EgIdlService }   from '@eg/core/eg-idl.service';
+import { EgNetService }   from '@eg/core/eg-net.service';
+import { EgAuthService }  from '@eg/core/eg-auth.service';
 
 @NgModule({
   declarations: [
@@ -26,6 +29,7 @@ import { EgAuthService }       from '@eg/core/eg-auth.service';
     NgbModule.forRoot()
   ],
   providers: [
+    EgEventService,
     EgIdlService,
     EgNetService,
     EgAuthService
@@ -35,7 +39,9 @@ import { EgAuthService }       from '@eg/core/eg-auth.service';
 
 export class EgBaseModule { 
     constructor(router: Router) {
+        /*
         console.debug('Routes: ', 
             JSON.stringify(router.config, undefined, 2));
+        */
     }
 }
index f73720b..920a48c 100644 (file)
@@ -4,7 +4,7 @@
 import { Injectable, EventEmitter } from '@angular/core';
 import { Observable } from 'rxjs/Rx';
 import { EgNetService } from './eg-net.service';
-import { EgEvent } from './eg-event';
+import { EgEventService, EgEvent } from './eg-event.service';
 import { EgIdlService, EgIdlObject } from './eg-idl.service';
 
 class EgAuthUser {
@@ -49,15 +49,17 @@ export class EgAuthService {
         return this.activeUser.authtime 
     };
 
-    constructor(private egNet: EgNetService) { 
-    }
+    constructor(
+        private egEvt: EgEventService,
+        private egNet: EgNetService
+    ) {}
 
     login(args: EgAuthArgs, ops?: Object): Promise<any> {
 
         return new Promise<any>((resolve, reject) => {
             this.egNet.request('open-ils.auth', 'open-ils.auth.login', args)
             .subscribe(res => {
-                let evt = EgEvent.parse(res);
+                let evt = this.egEvt.parse(res);
                 if (evt) {
                     if (evt.textcode == 'SUCCESS') {
                         this.handleLoginOk(args, evt);
diff --git a/Open-ILS/webby-src/src/app/core/eg-event.service.ts b/Open-ILS/webby-src/src/app/core/eg-event.service.ts
new file mode 100644 (file)
index 0000000..3f6afc7
--- /dev/null
@@ -0,0 +1,53 @@
+import { Injectable } from '@angular/core';
+
+export class EgEvent {
+    code        : Number;
+    textcode    : String;
+    payload     : any;
+    desc        : String;
+    debug       : String;
+    note        : String;
+    servertime  : String;
+    ilsperm     : String;
+    ilspermloc  : Number;
+    success     : Boolean = false;
+
+    toString(): String {
+        let s = `Event: ${this.code}:${this.textcode} -> ${this.desc}`;
+        if (this.ilsperm)
+            s += `  ${this.ilsperm}@${this.ilspermloc}`;
+        if (this.note)
+            s += `\n${this.note}`;
+        return s;
+    }
+}
+
+@Injectable()
+export class EgEventService {
+
+    /**
+     * Returns an EgEvent if 'thing' is an event, null otherwise.
+     */
+    parse(thing: any): EgEvent {
+
+        // All events have a textcode
+        if (thing && typeof thing == 'object' && 'textcode' in thing) {
+
+            let evt = new EgEvent();
+
+            ['textcode','payload','desc','note','servertime','ilsperm']
+                .forEach(field => { evt[field] = thing[field]; });
+
+            evt.debug = thing.stacktrace;
+            evt.code = new Number(thing.code);
+            evt.ilspermloc = new Number(thing.ilspermloc);
+            evt.success = thing.textcode == 'SUCCESS';
+
+            return evt;
+        }
+
+        return null;
+    }
+}
+
+
diff --git a/Open-ILS/webby-src/src/app/core/eg-event.ts b/Open-ILS/webby-src/src/app/core/eg-event.ts
deleted file mode 100644 (file)
index 1b5903d..0000000
+++ /dev/null
@@ -1,47 +0,0 @@
-
-export class EgEvent {
-    code        : Number;
-    textcode    : String;
-    payload     : any;
-    desc        : String;
-    debug       : String;
-    note        : String;
-    servertime  : String;
-    ilsperm     : String;
-    ilspermloc  : Number;
-    success     : Boolean = false;
-
-    toString(): String {
-        let s = `Event: ${this.code}:${this.textcode} -> ${this.desc}`;
-        if (this.ilsperm)
-            s += `  ${this.ilsperm}@${this.ilspermloc}`;
-        if (this.note)
-            s += `\n${this.note}`;
-        return s;
-    }
-
-    /**
-     * Returns an EgEvent if 'thing' is an event, null otherwise.
-     */
-    public static parse(thing: any): EgEvent {
-
-        // All events have a textcode
-        if (thing && typeof thing == 'object' && 'textcode' in thing) {
-
-            let evt = new EgEvent();
-
-            ['textcode','payload','desc','note','servertime','ilsperm']
-                .forEach(field => { evt[field] = thing[field]; });
-
-            evt.debug = thing.stacktrace;
-            evt.code = new Number(thing.code);
-            evt.ilspermloc = new Number(thing.ilspermloc);
-            evt.success = thing.textcode == 'SUCCESS';
-
-            return evt;
-        }
-
-        return null;
-    }
-}
-
index c279cca..9232828 100644 (file)
@@ -17,7 +17,7 @@
  */
 import { Injectable, EventEmitter } from '@angular/core';
 import { Observable, Observer } from 'rxjs/Rx';
-import { EgEvent } from './eg-event';
+import { EgEventService, EgEvent } from './eg-event.service';
 
 // Global vars from opensrf.js
 // These are availavble at runtime, but are not exported.
@@ -52,7 +52,9 @@ export class EgNetService {
     // and the active request is marked as superseded.
     permFailedHasHandler: Boolean = false;
 
-    constructor() { 
+    constructor(
+        private egEvt: EgEventService
+    ) { 
         this.permFailed$ = new EventEmitter<EgNetRequest>();
         this.authExpired$ = new EventEmitter<EgNetRequest>();
     }
@@ -111,7 +113,7 @@ export class EgNetService {
     // Relay response object to the caller for typical/successful responses.  
     // Applies special handling to response events that require global attention.
     private dispatchResponse = function(request, response) {
-        request.evt = EgEvent.parse(response);
+        request.evt = this.egEvt.parse(response);
 
         if (request.evt) {
             switch(request.evt.textcode) {