if (ctx.isStaff) method += '.staff';
return new Promise((resolve, reject) => {
-
this.net.request(
'open-ils.search', method, {
limit : ctx.pager.limit,
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)
this.facetFilters = [];
}
+ isSearchable(): boolean {
+ return this.query.length && this.query[0] != '';
+ }
+
compileSearch(): string {
let str: string = '';
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({
EgUnapiService,
EgCatalogService,
EgCatalogUrlService,
- StaffCatalogService,
- StaffRecordService
+ StaffCatalogService
]
})
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';
private net: EgNetService,
private org: EgOrgService,
private staffCat: StaffCatalogService,
- private staffRecord: StaffRecordService
) {}
ngOnInit() {
-<!--
-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"
<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()">
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>
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({
})
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;
private cat: EgCatalogService,
private catUrl: EgCatalogUrlService,
private staffCat: StaffCatalogService,
- private staffRecord: StaffRecordService
) {}
ngOnInit() {
}
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 {
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
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 }
+ );
}
}
<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'>
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({
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() {
// 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;
+ })
+ });
+ }
}
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(),
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());
});
}
})
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;
) {}
ngOnInit() {
- if (this.recordId) this.loadSummary();
+ this.initDone = true;
+ if (this.summary) {
+ this.fetchBibCallNumber();
+ } else {
+ if (this.recordId) this.loadSummary();
+ }
}
loadSummary(): void {