LP1896512 Angular retrieve record by ID/TCN
authorBill Erickson <berickxx@gmail.com>
Mon, 21 Sep 2020 19:38:26 +0000 (15:38 -0400)
committerGalen Charlton <gmc@equinoxinitiative.org>
Tue, 22 Sep 2020 13:46:08 +0000 (09:46 -0400)
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 <berickxx@gmail.com>
Signed-off-by: Rogan Hamby <rogan.hamby@gmail.com>
Signed-off-by: Galen Charlton <gmc@equinoxinitiative.org>

Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.html [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/bib-by-ident.component.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/cat.module.ts [new file with mode: 0644]
Open-ILS/src/eg2/src/app/staff/cat/routing.module.ts
Open-ILS/src/eg2/src/app/staff/nav.component.html
Open-ILS/src/eg2/src/app/staff/routing.module.ts
Open-ILS/src/templates/staff/navbar.tt2

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 (file)
index 0000000..b60e78d
--- /dev/null
@@ -0,0 +1,28 @@
+
+<div class="row form-validated mt-5">
+  <div class="col-lg-6 form-inline">
+    <div class="input-group">
+      <div class="input-group-prepend">
+        <span class="input-group-text" id="bib-ident-label">
+          <ng-container *ngIf="identType === 'id'" i18n>Record ID:</ng-container>
+          <ng-container *ngIf="identType === 'tcn'" i18n>Record TCN:</ng-container>
+        </span>
+      </div>
+      <input id="bib-ident-value" type="text" required 
+        (keyup.enter)="search()" [(ngModel)]="identValue"
+        class="form-control" aria-describedby="bib-ident-label"/>
+    </div>
+    <button class="btn btn-outline-dark" (click)="search()" i18n>Submit</button>
+  </div>
+</div>
+
+<div class="row mt-3">
+  <div class="col-lg-6">
+    <div class="alert alert-warning" *ngIf="notFound && !multiRecordsFound" i18n>
+      Record not found: {{identValue}}
+    </div>
+    <div class="alert alert-warning" *ngIf="multiRecordsFound" i18n>
+      More than one Bib Record found with TCN: {{identValue}}
+    </div>
+  </div>
+</div>
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 (file)
index 0000000..458902e
--- /dev/null
@@ -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<number> {
+        // Confirm the record exists before redirecting.
+        return this.pcrud.retrieve('bre', this.identValue).toPromise()
+        .then(rec => rec ? rec.id() : null);
+    }
+
+    getByTcn(): Promise<number> {
+        // 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 (file)
index 0000000..f7e65ef
--- /dev/null
@@ -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 {
+}
index b352378..67cf5c6 100644 (file)
@@ -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
   }
 ];
 
index 7f0eb23..4683657 100644 (file)
             <span i18n>Item Buckets</span>
           </a>
           <div class="dropdown-divider"></div>
-          <a href="/eg/staff/cat/catalog/retrieve_by_id" class="dropdown-item">
+          <a routerLink="/staff/cat/bib-from/id" class="dropdown-item">
             <span class="material-icons" aria-hidden="true">collections</span>
             <span i18n>Retrieve Bib Record by ID</span>
           </a>
-          <a href="/eg/staff/cat/catalog/retrieve_by_tcn"
-            class="dropdown-item"
+          <a routerLink="/staff/cat/bib-from/tcn" class="dropdown-item"
             egAccessKey keyCtx="navbar" i18n-keySpec i18n-keyDesc
             keySpec="shift+f3" keyDesc="Retrieve Bib Record by TCN">
             <span class="material-icons" aria-hidden="true">collections_bookmark</span>
index 58c3443..21e7427 100644 (file)
@@ -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: () =>
index d8287d8..e9c2d64 100644 (file)
           </li>
           <li class="divider"></li>
           <li>
-            <a href="./cat/catalog/retrieve_by_id" target="_self">
+            <a href="/eg2/staff/cat/bib-from/id">
               <span class="glyphicon glyphicon-file" aria-hidden="true"></span>
               [% l('Retrieve Bib Record by ID') %]
             </a>
           </li>
           <li>
-            <a href="./cat/catalog/retrieve_by_tcn" target="_self"
+
+            <a href="/eg2/staff/cat/bib-from/tcn"
               eg-accesskey="[% l('shift+f3') %]" 
               eg-accesskey-desc="[% l('Retrieve Last Bib Record') %]">
               <span class="glyphicon glyphicon-tag" aria-hidden="true"></span>