LP#626157 Ang2 experiments
authorBill Erickson <berickxx@gmail.com>
Sat, 9 Dec 2017 20:14:39 +0000 (15: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/share/catalog/catalog.service.ts
Open-ILS/webby-src/src/app/share/catalog/search-context.ts
Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts
Open-ILS/webby-src/src/app/staff/catalog/record/copies.component.ts
Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.html
Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.ts
Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html
Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts
Open-ILS/webby-src/src/app/staff/catalog/record/record.service.ts
Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts
Open-ILS/webby-src/src/app/staff/share/bib-summary.component.ts

index b1311af..a86fbe8 100644 (file)
@@ -69,7 +69,6 @@ export class EgCatalogService {
         if (ctx.isStaff) method += '.staff';
 
         return new Promise((resolve, reject) => {
-
             this.net.request(
                 'open-ils.search', method, {
                     limit : ctx.pager.limit, 
@@ -80,27 +79,30 @@ export class EgCatalogService {
                 ctx.result.records = [];
                 ctx.pager.resultCount = result.count;
                 ctx.searchState = CatalogSearchState.COMPLETE;
-
-                let promises = [];
-                result.ids.forEach((blob, idx) => {
-                    promises.push(
-                        this.getBibSummary(blob[0], 
-                            ctx.searchOrg.id(), 
-                            ctx.global ? 
-                                ctx.org.root().ou_type().depth() :
-                                ctx.searchOrg.ou_type().depth()
-                        ).then(
-                            // idx maintains result sort order
-                            summary => ctx.result.records[idx] = summary
-                        )
-                    );
-                });
-
-                Promise.all(promises).then(ok => resolve());
+                resolve();
             });
         })
     }
 
+    fetchBibSummaries(ctx: CatalogSearchContext): Promise<any> {
+        let promises = [];
+        ctx.result.ids.forEach((blob, idx) => {
+            promises.push(
+                this.getBibSummary(blob[0], 
+                    ctx.searchOrg.id(), 
+                    ctx.global ? 
+                        ctx.org.root().ou_type().depth() :
+                        ctx.searchOrg.ou_type().depth()
+                ).then(
+                    // idx maintains result sort order
+                    summary => ctx.result.records[idx] = summary
+                )
+            );
+        });
+
+        return Promise.all(promises);
+    }
+
     fetchFacets(ctx: CatalogSearchContext): Promise<void> {
 
         if (!ctx.result)
index 0dea627..af22ed1 100644 (file)
@@ -78,6 +78,10 @@ export class CatalogSearchContext {
         this.facetFilters = [];
     }
 
+    isSearchable(): boolean {
+        return this.query.length && this.query[0] != '';
+    }
+
     compileSearch(): string {
         let str: string = '';
 
index 420d271..e1833d0 100644 (file)
@@ -15,7 +15,6 @@ import {ResultPaginationComponent} from './result/pagination.component';
 import {ResultFacetsComponent} from './result/facets.component';
 import {ResultRecordComponent} from './result/record.component';
 import {StaffCatalogService} from './staff-catalog.service';
-import {StaffRecordService} from './record/record.service';
 import {RecordPaginationComponent} from './record/pagination.component';
 
 @NgModule({
@@ -40,8 +39,7 @@ import {RecordPaginationComponent} from './record/pagination.component';
     EgUnapiService,
     EgCatalogService,
     EgCatalogUrlService,
-    StaffCatalogService,
-    StaffRecordService
+    StaffCatalogService
   ]
 })
 
index 4dd4c90..33107ec 100644 (file)
@@ -1,7 +1,6 @@
 import {Component, OnInit, Input} from '@angular/core';
 import {EgNetService} from '@eg/core/net';
 import {StaffCatalogService} from '../staff-catalog.service';
-import {StaffRecordService} from './record.service';
 import {Pager} from '@eg/share/util/pager';
 import {EgOrgService} from '@eg/core/org';
 
@@ -28,7 +27,6 @@ export class CopiesComponent implements OnInit {
         private net: EgNetService,
         private org: EgOrgService,
         private staffCat: StaffCatalogService,
-        private staffRecord: StaffRecordService
     ) {}
 
     ngOnInit() { 
index cc89f43..65c413e 100644 (file)
@@ -1,8 +1,3 @@
-<!-- 
-Using bare BS pagination instead of ng-bootstrap, which seemed 
-unnecessary given we have to track paging externally anyway.
--->
-<span>current index = {{index}}</span>
 <ul class="pagination">
   <li class="page-item">
     <a class="no-href page-link" 
@@ -11,14 +6,16 @@ unnecessary given we have to track paging externally anyway.
       <span i18n>Start</span>
     </a>
   </li>
-  <li class="page-item">
+  <li class="page-item"
+    [ngClass]="{disabled : index == 0}">
     <a class="no-href page-link" 
       i18n-aria-label aria-label="Previous"
       (click)="prevRecord()">
       <span i18n>Previous</span>
     </a>
   </li>
-  <li class="page-item">
+  <li class="page-item"
+    [ngClass]="{disabled : index >= searchContext.result.count - 1}">
     <a class="no-href page-link" 
       i18n-aria-label aria-label="Next"
       (click)="nextRecord()">
@@ -37,7 +34,7 @@ unnecessary given we have to track paging externally anyway.
       i18n-aria-label aria-label="Back to Results"
       (click)="returnToSearch()">
       <span i18n>
-        Back to Results ({{index}} / {{searchContext.result.cout}})
+        Back to Results ({{index + 1}} / {{searchContext.result.count}})
       </span>
     </a>
   </li>
index 45347c4..8803aed 100644 (file)
@@ -4,7 +4,7 @@ import {EgCatalogService} from '@eg/share/catalog/catalog.service';
 import {CatalogSearchContext} from '@eg/share/catalog/search-context';
 import {EgCatalogUrlService} from '@eg/share/catalog/catalog-url.service';
 import {StaffCatalogService} from '../staff-catalog.service';
-import {StaffRecordService} from './record.service';
+import {Pager} from '@eg/share/util/pager';
 
 
 @Component({
@@ -14,10 +14,10 @@ import {StaffRecordService} from './record.service';
 })
 export class RecordPaginationComponent implements OnInit {
 
-    searchContext: CatalogSearchContext;
-    index: number = 0;
     id: number;
+    index: number = 0;
     initDone: boolean = false;
+    searchContext: CatalogSearchContext;
 
     @Input() set recordId(id: number) {
         this.id = id;
@@ -30,7 +30,6 @@ export class RecordPaginationComponent implements OnInit {
         private cat: EgCatalogService,
         private catUrl: EgCatalogUrlService,
         private staffCat: StaffCatalogService,
-        private staffRecord: StaffRecordService
     ) {}
 
     ngOnInit() { 
@@ -53,16 +52,13 @@ export class RecordPaginationComponent implements OnInit {
     }
 
     prevRecord(): void {
-        this.findRecordAtIndex(this.index - 1)
-        .then(id => {
-            // navigate to record
-            // teach record.component to update record w/ route navigation!
+        this.findRecordAtIndex(this.index - 1).then(id => {
+            let params = this.catUrl.toUrlParams(this.searchContext);
+            this.router.navigate(
+                ['/staff/catalog/record/' + id], {queryParams: params});
         });
     }
 
-    returnToSearch(): void {
-    }
-
 
     // Returns the offset of the record within the search results as a whole.
     searchIndex(idx: number): number {
@@ -75,24 +71,33 @@ export class RecordPaginationComponent implements OnInit {
 
         return new Promise((resolve, reject) => {
 
-            // First see if the select record sits in the current page
-            // of search results.  This will be the common case.
-            this.searchContext.result.records.forEach((rec, idx) => {
-                if (rec.id == this.id) {
-                    this.index = this.searchIndex(idx)
-                    resolve();
-                }
-            });
+            this.index = this.findIndexInResults();
+
+            if (this.index !== null) {
+                resolve();
+                return;
+            }
 
-            if (this.index !== null) return;
+            console.debug('Paginator re-searching...');
 
-            // Record not found in current page of search results.
-            // Re-run the search with a broad range to see if we
-            // can track it down.
-            reject('no search index found for record ' + this.id);
+            return this.refreshSearch().then(ok => {
+                this.index = this.findIndexInResults();
+                resolve();
+            });
         });
     }
 
+    findIndexInResults(): number {
+        let index = null;
+        if (this.searchContext.result 
+            && this.searchContext.result.ids) {
+            this.searchContext.result.ids.forEach((recIdBlob, idx) => {
+                if (+recIdBlob[0] == this.id) index = idx;
+            });
+        }
+        return index;
+    }
+
     findRecordAtIndex(index: number): Promise<number> {
 
         // First see if the select record sits in the current page
@@ -100,18 +105,42 @@ export class RecordPaginationComponent implements OnInit {
         return new Promise((resolve, reject) => {
 
             // See if the record is avaialable in the current search page.
-            this.searchContext.result.records.forEach((rec, idx) => {
-                if (this.searchIndex(idx) == index) {
-                    resolve(rec.id);
-                }
-            });
-
-            // Otherwise, expand the search
-            reject('no record found at index ' + index);
+            let found = false;
+            if (this.searchContext.result 
+                && this.searchContext.result.ids) {
+                this.searchContext.result.ids.forEach((recIdBlob, idx) => {
+                    if (this.searchIndex(idx) == index) {
+                        found = true;
+                        resolve(recIdBlob[0]);
+                    }
+                });
+            }
+
+            if (!found) {
+                // TODO: re-run search but only for the next/prev page of results
+                console.debug(
+                    'Record paginator unable to find record at index ' + index);
+                return this.refreshSearch();
+            }
         });
     }
 
-    navigatToRecord(): void {
+    refreshSearch(): Promise<void> {
+
+        if (!this.searchContext.isSearchable())
+            return Promise.resolve();
+
+        let origPager = this.searchContext.pager;
+        let tmpPager = new Pager();
+        tmpPager.limit = 1000;
+
+        this.searchContext.pager = tmpPager;
+
+        return this.cat.search(this.searchContext)
+        .then(
+            ok => { this.searchContext.pager = origPager; console.log(this.searchContext.result); }, 
+            notOk => { this.searchContext.pager = origPager }
+        );
     }
 
 }
index c04998b..127254a 100644 (file)
@@ -1,13 +1,13 @@
 
 <div id="staff-catalog-record-container">
   <div id='staff-catalog-bib-navigation'>
-    <div *ngIf="searchContext.result.records">
+    <div *ngIf="searchContext.isSearchable()">
       <eg-catalog-record-pagination [recordId]="recordId">
       </eg-catalog-record-pagination>
     </div>
   </div>
   <div id='staff-catalog-bib-summary-container' class='mt-1'>
-    <eg-bib-summary [bibSummary]="staffRecord.bibSummary">
+    <eg-bib-summary [bibSummary]="bibSummary">
     </eg-bib-summary>
   </div>
   <div id='staff-catalog-copies-container' class='mt-3'>
index 1c0558c..95d8ecf 100644 (file)
@@ -4,8 +4,8 @@ import {EgPcrudService} from '@eg/core/pcrud';
 import {EgIdlObject} from '@eg/core/idl';
 import {CatalogSearchContext, CatalogSearchState} 
   from '@eg/share/catalog/search-context';
+import {EgCatalogService} from '@eg/share/catalog/catalog.service';
 import {StaffCatalogService} from '../staff-catalog.service';
-import {StaffRecordService} from './record.service';
 import {EgBibSummaryComponent} from '../../share/bib-summary.component';
 
 @Component({
@@ -16,13 +16,14 @@ import {EgBibSummaryComponent} from '../../share/bib-summary.component';
 export class RecordComponent implements OnInit {
 
     recordId: number;
+    bibSummary: any;
     searchContext: CatalogSearchContext;
 
     constructor(
         private route: ActivatedRoute,
         private pcrud: EgPcrudService,
-        private staffCat: StaffCatalogService,
-        private staffRecord: StaffRecordService
+        private cat: EgCatalogService,
+        private staffCat: StaffCatalogService
     ) {}
 
     ngOnInit() { 
@@ -31,9 +32,32 @@ export class RecordComponent implements OnInit {
         // Watch for URL record ID changes
         this.route.paramMap.subscribe((params: ParamMap) => {
             this.recordId = +params.get('id');
-            this.staffRecord.setRecord(this.recordId);
+            console.log('record starting with id ' + this.recordId);
+            this.loadRecord();
         })
     }
+
+    loadRecord(): void { 
+        this.searchContext = this.staffCat.searchContext;
+
+        // If a search is encoded in the URL, be sure we have the
+        // relevant search 
+
+        this.cat.getBibSummary(
+            this.recordId,
+            this.searchContext.searchOrg.id(), 
+            this.searchContext.searchOrg.ou_type().depth()
+        ).then(summary => { 
+            this.bibSummary = summary;
+            this.pcrud.search('au', {id: [summary.creator, summary.editor]})
+            .subscribe(user => {
+                if (user.id() == summary.creator)
+                    summary.creator = user;
+                if (user.id() == summary.editor)
+                    summary.editor = user;
+            })
+        });
+    }
 }
 
 
index fcd80cd..db47c73 100644 (file)
@@ -27,6 +27,9 @@ export class StaffRecordService {
         this.recordId = id;
         this.searchContext = this.staffCat.searchContext;
 
+        // If a search is encoded in the URL, be sure we have the
+        // relevant search 
+
         this.cat.getBibSummary(
             this.recordId,
             this.searchContext.searchOrg.id(), 
index c1b1c25..6313656 100644 (file)
@@ -55,11 +55,13 @@ export class ResultsComponent implements OnInit {
         this.catUrl.applyUrlParams(this.searchContext, params);
 
         // A query string is required at minimum.
-        if (!this.searchContext.query[0]) return;
+        if (!this.searchContext.isSearchable()) return;
 
-        this.cat.search(this.searchContext).then(ok => {
+        this.cat.search(this.searchContext)
+        .then(ok => {
             this.cat.fetchFacets(this.searchContext);
-            this.fleshSearchResults();
+            this.cat.fetchBibSummaries(this.searchContext)
+            .then(ok2 => this.fleshSearchResults());
         });
     }
 
index 1dbeff6..61f438f 100644 (file)
@@ -10,16 +10,16 @@ import {EgCatalogService} from '@eg/share/catalog/catalog.service';
 })
 export class EgBibSummaryComponent implements OnInit {
 
+    initDone: boolean = false;
+
     // If provided, the record will be fetched by the component.
     @Input() recordId: number;
 
     // Otherwise, we'll use the provided bib summary object.
     summary: any;
     @Input() set bibSummary(s: any) {
-        if (s) {
-            this.summary = s;
-            this.fetchBibCallNumber();
-        }
+        this.summary = s;
+        if (this.initDone) this.fetchBibCallNumber();
     }
 
     expandDisplay: boolean = true;
@@ -31,7 +31,12 @@ export class EgBibSummaryComponent implements OnInit {
     ) {}
 
     ngOnInit() { 
-        if (this.recordId) this.loadSummary();
+        this.initDone = true;
+        if (this.summary) {
+            this.fetchBibCallNumber();
+        } else {
+            if (this.recordId) this.loadSummary();
+        }
     }
 
     loadSummary(): void {