From d173567ea47d58733cbc04ae0f5381db7b27e323 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 21 Sep 2020 15:38:26 -0400 Subject: [PATCH 1/1] LP1896512 Angular retrieve record by ID/TCN Ports the retrieve records by ID/TCN to Angular. Note this version of the form confirms a record exists by both ID and TCN before directing the user to the record detail page in the Angular staff catalog. Updates the navigation bars to use the Angular port for each. Signed-off-by: Bill Erickson Signed-off-by: Rogan Hamby Signed-off-by: Galen Charlton --- .../app/staff/cat/bib-by-ident.component.html | 28 +++++ .../app/staff/cat/bib-by-ident.component.ts | 104 ++++++++++++++++++ .../src/eg2/src/app/staff/cat/cat.module.ts | 19 ++++ .../eg2/src/app/staff/cat/routing.module.ts | 4 + .../src/eg2/src/app/staff/nav.component.html | 5 +- .../src/eg2/src/app/staff/routing.module.ts | 2 +- Open-ILS/src/templates/staff/navbar.tt2 | 5 +- 7 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.ts create mode 100644 Open-ILS/src/eg2/src/app/staff/cat/cat.module.ts diff --git a/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.html b/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.html new file mode 100644 index 0000000000..b60e78d611 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.html @@ -0,0 +1,28 @@ + +
+
+
+
+ + Record ID: + Record TCN: + +
+ +
+ +
+
+ +
+
+
+ Record not found: {{identValue}} +
+
+ More than one Bib Record found with TCN: {{identValue}} +
+
+
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.ts new file mode 100644 index 0000000000..458902e284 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.ts @@ -0,0 +1,104 @@ +import {Component, OnInit, ViewChild, Input, AfterViewInit} from '@angular/core'; +import {Router, ActivatedRoute, ParamMap} from '@angular/router'; +import {IdlObject} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {PcrudService} from '@eg/core/pcrud.service'; + +/* Component for retrieving bib records by ID, TCN */ + +@Component({ + templateUrl: 'bib-by-ident.component.html' +}) +export class BibByIdentComponent implements OnInit, AfterViewInit { + + identType: 'id' | 'tcn' = 'id'; + identValue: string; + notFound = false; + multiRecordsFound = false; + + constructor( + private router: Router, + private route: ActivatedRoute, + private net: NetService, + private pcrud: PcrudService + ) {} + + ngOnInit() { + this.route.paramMap.subscribe((params: ParamMap) => { + this.identType = params.get('identType') as 'id' | 'tcn'; + }); + } + + ngAfterViewInit() { + const node = document.getElementById('bib-ident-value'); + setTimeout(() => node.focus()); + } + + search() { + if (!this.identValue) { return; } + + this.notFound = false; + this.multiRecordsFound = false; + + let promise; + if (this.identType === 'id') { + promise = this.getById(); + + } else if (this.identType === 'tcn') { + promise = this.getByTcn(); + } + + promise.then(id => { + if (id === null) { + this.notFound = true; + } else { + this.goToRecord(id); + } + }); + } + + getById(): Promise { + // Confirm the record exists before redirecting. + return this.pcrud.retrieve('bre', this.identValue).toPromise() + .then(rec => rec ? rec.id() : null); + } + + getByTcn(): Promise { + // Start by searching non-deleted records + + return this.net.request( + 'open-ils.search', + 'open-ils.search.biblio.tcn', this.identValue).toPromise() + .then(resp => { + + if (resp.count > 0) { + return Promise.resolve(resp); + } + + // No active records, see if we have any deleted records. + return this.net.request( + 'open-ils.search', + 'open-ils.search.biblio.tcn', this.identValue, true + ).toPromise(); + + }).then(resp => { + + if (resp.count) { + if (resp.count > 1) { + this.multiRecordsFound = true; + return null; + } else { + return resp.ids[0]; + } + } + + return null; + }); + } + + goToRecord(id: number) { + this.router.navigate([`/staff/catalog/record/${id}`]); + } +} + + diff --git a/Open-ILS/src/eg2/src/app/staff/cat/cat.module.ts b/Open-ILS/src/eg2/src/app/staff/cat/cat.module.ts new file mode 100644 index 0000000000..f7e65ef110 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/cat/cat.module.ts @@ -0,0 +1,19 @@ +import {NgModule} from '@angular/core'; +import {StaffCommonModule} from '@eg/staff/common.module'; +import {CatRoutingModule} from './routing.module'; +import {BibByIdentComponent} from './bib-by-ident.component'; + +@NgModule({ + declarations: [ + BibByIdentComponent + ], + imports: [ + StaffCommonModule, + CatRoutingModule + ], + providers: [ + ] +}) + +export class CatModule { +} diff --git a/Open-ILS/src/eg2/src/app/staff/cat/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/cat/routing.module.ts index b3523789d9..67cf5c6fd3 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/routing.module.ts @@ -1,5 +1,6 @@ import {NgModule} from '@angular/core'; import {RouterModule, Routes} from '@angular/router'; +import {BibByIdentComponent} from './bib-by-ident.component'; const routes: Routes = [ { path: 'vandelay', @@ -13,6 +14,9 @@ const routes: Routes = [ path: 'marcbatch', loadChildren: () => import('./marcbatch/marcbatch.module').then(m => m.MarcBatchModule) + }, { + path: 'bib-from/:identType', + component: BibByIdentComponent } ]; 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 7f0eb23812..468365714a 100644 --- a/Open-ILS/src/eg2/src/app/staff/nav.component.html +++ b/Open-ILS/src/eg2/src/app/staff/nav.component.html @@ -181,12 +181,11 @@ Item Buckets - + Retrieve Bib Record by ID - diff --git a/Open-ILS/src/eg2/src/app/staff/routing.module.ts b/Open-ILS/src/eg2/src/app/staff/routing.module.ts index 58c3443b3c..21e7427537 100644 --- a/Open-ILS/src/eg2/src/app/staff/routing.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/routing.module.ts @@ -42,7 +42,7 @@ const routes: Routes = [{ }, { path: 'cat', loadChildren: () => - import('./cat/routing.module').then(m => m.CatRoutingModule) + import('./cat/cat.module').then(m => m.CatModule) }, { path: 'catalog', loadChildren: () => diff --git a/Open-ILS/src/templates/staff/navbar.tt2 b/Open-ILS/src/templates/staff/navbar.tt2 index d8287d87cb..e9c2d647e1 100644 --- a/Open-ILS/src/templates/staff/navbar.tt2 +++ b/Open-ILS/src/templates/staff/navbar.tt2 @@ -287,13 +287,14 @@
  • - + [% l('Retrieve Bib Record by ID') %]
  • - -- 2.43.2