From 7392b3e5727490f7c719e32c3857d151ca09cf34 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Sun, 19 Nov 2017 15:19:20 -0500 Subject: [PATCH] LP#626157 Ang2 experiments / service Signed-off-by: Bill Erickson --- Open-ILS/webby-src/src/app/core/eg-net-request.ts | 3 ++- Open-ILS/webby-src/src/app/core/eg-net.service.ts | 25 +++++++++++-------- .../circ/patron/bcsearch/bcsearch.component.html | 5 ++++ .../circ/patron/bcsearch/bcsearch.component.ts | 29 +++++++++++++++++++--- .../staff/circ/patron/bcsearch/bcsearch.module.ts | 10 +++++--- Open-ILS/webby-src/src/index.html | 3 +++ 6 files changed, 56 insertions(+), 19 deletions(-) diff --git a/Open-ILS/webby-src/src/app/core/eg-net-request.ts b/Open-ILS/webby-src/src/app/core/eg-net-request.ts index 428d59a1b1..e2c9179ac2 100644 --- a/Open-ILS/webby-src/src/app/core/eg-net-request.ts +++ b/Open-ILS/webby-src/src/app/core/eg-net-request.ts @@ -1,6 +1,7 @@ import { EgEvent } from './eg-event'; +import { Observer } from 'rxjs/Rx'; -public class EgNetRequest { +export class EgNetRequest { service : String; method : String; params : any[]; diff --git a/Open-ILS/webby-src/src/app/core/eg-net.service.ts b/Open-ILS/webby-src/src/app/core/eg-net.service.ts index c272c673eb..8cc6b17f78 100644 --- a/Open-ILS/webby-src/src/app/core/eg-net.service.ts +++ b/Open-ILS/webby-src/src/app/core/eg-net.service.ts @@ -15,8 +15,8 @@ * Each response is relayed via Observable onNext(). The interface is * the same for streaming and atomic requests. */ -import { Injectable } from '@angular/core'; -import { Observable, Observer, EventEmitter } from 'rxjs/Rx'; +import { Injectable, EventEmitter } from '@angular/core'; +import { Observable, Observer } from 'rxjs/Rx'; import { EgNetRequest } from './eg-net-request'; import { EgEvent } from './eg-event'; @@ -27,12 +27,12 @@ declare var OpenSRF, OSRF_TRANSPORT_TYPE_WS; @Injectable() export class EgNetService { - public permFailed$: EventEmitter; - public authExpired$: EventEmitter; + permFailed$: EventEmitter; + authExpired$: EventEmitter; // If true, permission failures are emitted via permFailed$ // and the active request is marked as superseded. - public permFailedHasHandler: Boolean = false; + permFailedHasHandler: Boolean = false; constructor() { this.permFailed$ = new EventEmitter(); @@ -41,11 +41,13 @@ export class EgNetService { // Variadic params version request(service: String, method: String, ...params: any[]): Observable { - return this.request(service, method, params); + return this.requestWithParamList(service, method, params); } // Array params version - request(service: String, method: String, params: any[]): Observable { + requestWithParamList(service: String, + method: String, params: any[]): Observable { + var request = new EgNetRequest(service, method, params); return Observable.create( @@ -58,6 +60,7 @@ export class EgNetService { private sendRequest(request: EgNetRequest): void { OpenSRF.Session.transport = OSRF_TRANSPORT_TYPE_WS; + var this_ = this; new OpenSRF.ClientSession(request.service).request({ async : true, @@ -70,10 +73,10 @@ export class EgNetService { request.observer.complete(); }, onresponse : function(r) { - this.dispatchResponse(request, r.recv().content()); + this_.dispatchResponse(request, r.recv().content()); }, - onerror : function(msg) { - let msg = `${request.method} failed! See server logs.`; + onerror : function(errmsg) { + let msg = `${request.method} failed! See server logs. ${errmsg}`; console.error(msg); request.observer.error(msg); }, @@ -102,7 +105,7 @@ export class EgNetService { return; case 'PERM_FAILURE': - if (permFailedHasHandler) { + if (this.permFailedHasHandler) { console.debug(`EgNet emitting event: ${request.evt}`); request.superseded = true; this.permFailed$.emit(request); diff --git a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.html b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.html index a4409ebf06..1f55cb1d8b 100644 --- a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.html +++ b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.html @@ -1,3 +1,8 @@

Search for Patron by Barcode

Barcode: + +
+
    +
  • {{str}}
  • +
diff --git a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.ts b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.ts index 6a99ced9a0..958f5228bc 100644 --- a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.ts +++ b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.component.ts @@ -1,14 +1,20 @@ import { Component, OnInit } from '@angular/core'; import { ActivatedRoute } from '@angular/router'; +import { EgNetService } from '@eg/core/eg-net.service'; @Component({ templateUrl: 'bcsearch.component.html' }) export class EgBcSearchComponent implements OnInit { - constructor(private route: ActivatedRoute) {} - barcode: String ''; + barcode: String = ''; + strList: String[] = []; + + constructor( + private route: ActivatedRoute, + private egNet: EgNetService + ) {} ngOnInit() { @@ -19,8 +25,25 @@ export class EgBcSearchComponent implements OnInit { } this.route.data.subscribe((data: { startup : any }) => { - console.debug('EgStaff ngOnInit complete'); + console.debug('EgBcSearch ngOnInit complete'); }); + + this.egNet.request( + 'open-ils.actor', + 'opensrf.system.echo', + 'hello', 'goodbye', 'in the middle' + ).subscribe(res => this.strList.push(res)); + + this.egNet.request( + 'open-ils.actor', + 'opensrf.system.echo', + {textcode : 'NO_SESSION', code: 123, desc: 'test desc'} + ).subscribe( + x => console.log(x), + e => console.log('echo event: ' + e), + () => console.log('done'); + ) + } findUser(): void { diff --git a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.module.ts b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.module.ts index a7c92b5b50..af67ff1da6 100644 --- a/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.module.ts +++ b/Open-ILS/webby-src/src/app/staff/circ/patron/bcsearch/bcsearch.module.ts @@ -1,6 +1,7 @@ -import { CommonModule } from '@angular/common'; -import { NgModule } from '@angular/core'; -import { FormsModule } from '@angular/forms'; +import { CommonModule } from '@angular/common'; +import { NgModule } from '@angular/core'; +import { FormsModule } from '@angular/forms'; +import { EgNetService } from '@eg/core/eg-net.service'; import { EgBcSearchComponent } from './bcsearch.component'; import { EgBcSearchRoutingModule } from './bcsearch-routing.module'; @@ -10,9 +11,10 @@ import { EgBcSearchRoutingModule } from './bcsearch-routing.module'; ], imports: [ EgBcSearchRoutingModule, + CommonModule, FormsModule ], - providers: [] + providers: [EgNetService] }) export class EgBcSearchModule { diff --git a/Open-ILS/webby-src/src/index.html b/Open-ILS/webby-src/src/index.html index fb35cca899..3bb7d5f52e 100644 --- a/Open-ILS/webby-src/src/index.html +++ b/Open-ILS/webby-src/src/index.html @@ -10,5 +10,8 @@ + + + -- 2.11.0