From: Bill Erickson Date: Sat, 9 Dec 2017 20:14:39 +0000 (-0500) Subject: LP#626157 Ang2 experiments X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=e161670eeee33cf223cd994866e238da606557f7;p=working%2FEvergreen.git LP#626157 Ang2 experiments Signed-off-by: Bill Erickson --- diff --git a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts index b1311af868..a86fbe839a 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/catalog.service.ts @@ -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 { + 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 { if (!ctx.result) diff --git a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts index 0dea6274da..af22ed1a8b 100644 --- a/Open-ILS/webby-src/src/app/share/catalog/search-context.ts +++ b/Open-ILS/webby-src/src/app/share/catalog/search-context.ts @@ -78,6 +78,10 @@ export class CatalogSearchContext { this.facetFilters = []; } + isSearchable(): boolean { + return this.query.length && this.query[0] != ''; + } + compileSearch(): string { let str: string = ''; diff --git a/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts b/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts index 420d27140f..e1833d051d 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/catalog.module.ts @@ -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 ] }) diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/copies.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/record/copies.component.ts index 4dd4c907f3..33107eccf7 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/copies.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/copies.component.ts @@ -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() { diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.html b/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.html index cc89f43f26..65c413ea66 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.html @@ -1,8 +1,3 @@ - -current index = {{index}}
  • Start
  • -
  • +
  • Previous
  • -
  • +
  • @@ -37,7 +34,7 @@ unnecessary given we have to track paging externally anyway. i18n-aria-label aria-label="Back to Results" (click)="returnToSearch()"> - Back to Results ({{index}} / {{searchContext.result.cout}}) + Back to Results ({{index + 1}} / {{searchContext.result.count}})
  • diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.ts index 45347c4dd8..8803aed3b3 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/pagination.component.ts @@ -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 { // 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 { + + 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 } + ); } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html index c04998bf43..127254aa5d 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.html @@ -1,13 +1,13 @@
    -
    +
    - +
    diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts index 1c0558ccb3..95d8ecf167 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/record.component.ts @@ -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; + }) + }); + } } diff --git a/Open-ILS/webby-src/src/app/staff/catalog/record/record.service.ts b/Open-ILS/webby-src/src/app/staff/catalog/record/record.service.ts index fcd80cddbc..db47c73ed3 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/record/record.service.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/record/record.service.ts @@ -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(), diff --git a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts index c1b1c25b0c..63136564aa 100644 --- a/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts +++ b/Open-ILS/webby-src/src/app/staff/catalog/result/results.component.ts @@ -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()); }); } diff --git a/Open-ILS/webby-src/src/app/staff/share/bib-summary.component.ts b/Open-ILS/webby-src/src/app/staff/share/bib-summary.component.ts index 1dbeff64aa..61f438f892 100644 --- a/Open-ILS/webby-src/src/app/staff/share/bib-summary.component.ts +++ b/Open-ILS/webby-src/src/app/staff/share/bib-summary.component.ts @@ -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 {