<link field="thesaurus" reltype="might_have" key="code" map="" class="at"/>
</links>
</class>
- <class id="abl" controller="open-ils.cstore" oils_obj:fieldmapper="authority::bib_linking" oils_persist:tablename="authority.bib_linking" reporter:label="Authority-Bibliographic Record Link">
+ <class id="abl" controller="open-ils.cstore open-ils.pcrud" oils_obj:fieldmapper="authority::bib_linking" oils_persist:tablename="authority.bib_linking" reporter:label="Authority-Bibliographic Record Link">
<fields oils_persist:primary="id" oils_persist:sequence="authority.bib_linking_id_seq">
<field name="id" reporter:datatype="id" />
<field name="bib" reporter:datatype="link" />
<link field="bib" reltype="has_a" key="id" map="" class="bre"/>
<link field="authority" reltype="has_a" key="id" map="" class="are"/>
</links>
+ <permacrud xmlns="http://open-ils.org/spec/opensrf/IDL/permacrud/v1">
+ <actions>
+ <retrieve/>
+ </actions>
+ </permacrud>
</class>
<class id="ash" controller="open-ils.cstore" oils_obj:fieldmapper="authority::simple_heading" oils_persist:tablename="authority.simple_heading" reporter:label="Authority Simple Heading">
<fields oils_persist:primary="id" oils_persist:sequence="authority.simple_heading_id_seq">
return {
authority: authMeta.authority,
- link_count: authMeta.linked_bibs.length,
+ link_count: authMeta.linked_bib_count,
heading: authMeta.heading,
thesaurus: authMeta.thesaurus,
thesaurus_code: authMeta.thesaurus_code,
<ngb-tab title="Linked Bibs" i18n-title id="bibs">
<ng-template ngbTabContent>
<div class="mt-3" *ngIf="authMeta">
- <eg-bib-list #bibList [bibIds]="authMeta.linked_bibs"
+ <eg-bib-list #bibList [bibIdSource]="linkedBibIdSource"
gridPersistKey="cat.authority.manage.bibs"></eg-bib-list>
</div>
</ng-template>
authId: number;
authTab = 'bibs';
authMeta: any;
+ linkedBibIdSource: (pager: Pager, sort: any) => Promise<number[]>;
constructor(
private router: Router,
).subscribe(meta => this.authMeta = meta);
}
});
+
+ this.linkedBibIdSource = (pager: Pager, sort: any) => {
+ return this.getLinkedBibIds(pager, sort);
+ };
+ }
+
+ getLinkedBibIds(pager: Pager, sort: any): Promise<number[]> {
+ return this.pcrud.search('abl',
+ {authority: this.authId},
+ {limit: pager.limit, offset: pager.offset},
+ {atomic: true}
+ ).pipe(map(links => links.map(l => l.bib()))
+ ).toPromise();
}
// Changing a tab in the UI means changing the route.
import {Component, Input, OnInit, ViewChild} from '@angular/core';
-import {Observable, empty} from 'rxjs';
-import {map, switchMap} from 'rxjs/operators';
+import {Observable, empty, from} from 'rxjs';
+import {map, tap, switchMap} from 'rxjs/operators';
import {IdlObject} from '@eg/core/idl.service';
import {Pager} from '@eg/share/util/pager';
import {NetService} from '@eg/core/net.service';
})
export class BibListComponent implements OnInit {
- // Display bibs linked to this authority record.
+ // Static source of bib record IDs
@Input() bibIds: number[];
+ // Dynamic source of bib record IDs
+ @Input() bibIdSource: (pager: Pager, sort: any) => Promise<number[]>;
@Input() gridPersistKey: string;
dataSource: GridDataSource;
this.dataSource.getRows = (pager: Pager, sort: any): Observable<any> => {
- if (this.bibIds) {
+ if (this.bibIds || this.bibIdSource) {
return this.loadIds(pager, sort);
}
}
loadIds(pager: Pager, sort: any): Observable<any> {
- if (this.bibIds.length === 0) {
+
+ let promise: Promise<number[]>;
+
+ if (this.bibIdSource) {
+ promise = this.bibIdSource(pager, sort);
+
+ } else if (this.bibIds && this.bibIds.length > 0) {
+ promise = Promise.resolve(
+ this.bibIds.slice(pager.offset, pager.offset + pager.limit));
+
+ } else {
return empty();
}
- const orderBy: any = {rmsr: 'title'};
- if (sort.length) {
- orderBy.rmsr = sort[0].name + ' ' + sort[0].dir;
- }
+ return from(promise).pipe(switchMap(bibIds => {
- return this.pcrud.search('rmsr', {id: this.bibIds}, {
- order_by: orderBy,
- limit: pager.limit,
- offset: pager.offset,
- flesh: 2,
- flesh_fields: {
- rmsr: ['biblio_record'],
- bre: ['creator', 'editor']
- }
- });
+ if (bibIds.length === 0) { return empty(); }
+
+ return this.pcrud.search('rmsr', {id: bibIds}, {
+ order_by: {rmsr: 'id'},
+ flesh: 2,
+ flesh_fields: {
+ rmsr: ['biblio_record'],
+ bre: ['creator', 'editor']
+ }
+ });
+ }));
}
}
thesaurus: short_code,
thesaurus_code: code,
control_set: control_set_object,
- linked_bibs: [id1, id2, ...]
+ linked_bib_count: number
}
/,
type => 'object'
my $rec = $e->retrieve_authority_record_entry([
$auth_id, {
flesh => 1,
- flesh_fields => {are => [qw/control_set bib_links creator/]}
+ flesh_fields => {are => [qw/control_set creator/]}
}
]) or return $e->event;
my $response = {
authority => $rec,
- control_set => $rec->control_set,
- linked_bibs => [ map {$_->bib} @{$rec->bib_links} ]
+ control_set => $rec->control_set
};
+ $response->{linked_bib_count} = $e->json_query({
+ select => {abl => [
+ {column => 'bib', transform => 'count', aggregate => 1}
+ ]},
+ from => 'abl',
+ where => {authority => $auth_id}
+ })->[0]->{bib};
+
# Extract the heading and thesaurus.
# In theory this data has already been extracted in the DB, but
# using authority.simple_heading results in data that varies