<ng-container *ngFor="let copyNode of volNode.children; let copyIdx = index">
<div class="row d-flex mt-1">
<div class="p-1" [ngStyle]="{flex: flexAt(1)}">
- <span *ngIf="volIdx == 0">{{orgNode.target.shortname()}}</span>
+ <span *ngIf="copyIdx == 0">{{orgNode.target.shortname()}}</span>
</div>
<div class="p-1" [ngStyle]="{flex: flexAt(2)}">
- <ng-container *ngIf="volIdx == 0">
+ <ng-container *ngIf="copyIdx == 0">
<input type="number" class="form-control form-control-sm"
[required]="true"
[ngModel]="orgNode.children.length"
(ngModelChange)="applyCopyValue(copyNode.target, 'copy_number', $event)"/>
</div>
<div class="p-1" [ngStyle]="{flex: flexAt(10)}">
+ <ng-container *ngIf="!recordHasParts(volNode.target.record())">
+ <label i18n>N/A</label>
+ </ng-container>
+ <ng-container *ngIf="recordHasParts(volNode.target.record())">
<eg-combobox
+ [disabled]="bibParts[volNode.target.record()].length == 0"
[startId]="copyNode.target.parts()[0] ? copyNode.target.parts()[0].id() : null"
[smallFormControl]="true"
(onChange)="copyPartChanged(copyNode, $event)">
[entryId]="part.id()" [entryLabel]="part.label()">
</eg-combobox-entry>
</eg-combobox>
+ </ng-container>
</div>
</div>
</ng-container>
import {Component, OnInit, AfterViewInit, ViewChild, Renderer2} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
+import {tap} from 'rxjs/operators';
import {IdlObject} from '@eg/core/idl.service';
import {OrgService} from '@eg/core/org.service';
import {PcrudService} from '@eg/core/pcrud.service';
import {HoldingsService} from '@eg/staff/share/holdings/holdings.service';
import {VolCopyContext} from './volcopy';
-const copy_FLESH = {
+const COPY_FLESH = {
flesh: 1,
flesh_fields: {
acp: ['call_number', 'location', 'parts']
// Note in multi-record mode this value will be unset.
recordId: number;
- // Load the editor for a specific copy by ID.
+ // Load specific call number by ID.
+ volId: number;
+
+ // Load specific copy by ID.
copyId: number;
session: string;
}
negotiateRoute(params: ParamMap) {
- const copyId = +params.get('copy_id');
- if (copyId) {
- if (copyId !== this.copyId) {
- this.copyId = copyId;
- this.load();
- }
- } else {
- this.copyId = null;
- }
+ this.recordId = +params.get('record_id') || null;
+ this.volId = +params.get('vol_id') || null;
+ this.copyId = +params.get('copy_id') || null;
+ this.session = params.get('session') || null;
+ this.load();
}
load() {
.then(_ => this.holdings.fetchCallNumberPrefixes())
.then(_ => this.holdings.fetchCallNumberSuffixes())
.then(_ => this.context.sortHoldings())
+ .then(_ => this.setRecordId())
.then(_ => this.loading = false);
}
+ setRecordId() {
+ if (!this.recordId) {
+ this.recordId = this.context.getRecordId();
+ }
+ }
+
fetchHoldings(): Promise<any> {
if (this.copyId) {
- return this.fetchCopy();
+ return this.fetchCopies(this.copyId);
+ } else if (this.volId) {
+ return this.fetchVols(this.volId);
+ } else if (this.recordId) {
+ return this.fetchRecords(this.recordId);
}
}
- fetchCopy(): Promise<any> {
- return this.pcrud.retrieve('acp', this.copyId, copy_FLESH)
- .toPromise().then(copy => {
- this.recordId = copy.call_number().record();
- this.context.findOrCreateCopyNode(copy);
- });
+ fetchCopies(copyIds: number | number[]): Promise<any> {
+ const ids = [].concat(copyIds);
+ return this.pcrud.search('acp', {id: ids}, COPY_FLESH)
+ .pipe(tap(copy => this.context.findOrCreateCopyNode(copy)))
+ .toPromise();
+ }
+
+ // Fetch call numbers and copies by call number ids.
+ fetchVols(volIds?: number | number[]): Promise<any> {
+ const ids = [].concat(volIds);
+
+ return this.pcrud.search('acn', {id: ids})
+ .pipe(tap(vol => this.context.findOrCreateVolNode(vol)))
+ .pipe(tap(vol => {
+ return this.pcrud.search('acp',
+ {call_number: ids, deleted: 'f'}, COPY_FLESH
+ ).pipe(tap(copy => this.context.findOrCreateCopyNode(copy))
+ ).toPromise();
+ })).toPromise();
+ }
+
+ // Fetch call numbers and copies by record ids.
+ fetchRecords(recordIds: number | number[]): Promise<any> {
+ const ids = [].concat(recordIds);
+
+ return this.pcrud.search('acn',
+ {record: ids, deleted: 'f'},
+ {}, {idlist: true, atomic: true}
+ ).toPromise().then(volIds =>this.fetchVols(volIds));
}
}
+
+
return this.holdings.root.children;
}
+ // If the holdings in question all link to a single bib
+ // record, return the ID of said record. Otherwise null.
+ getRecordId(): number {
+ let id = null;
+ let nope = false;
+ this.orgNodes().forEach(orgNode => {
+ orgNode.children.forEach(volNode => {
+ if (id === null) {
+ id = volNode.target.record();
+ } else if (id !== volNode.target.record()) {
+ nope = true;
+ }
+ })
+ });
+
+ return nope ? null : id;
+ }
+
// Adds an org unit node; unsorted.
findOrCreateOrgNode(orgId: number): HoldingsTreeNode {
return node;
}
- findOrCreateCallNumNode(vol: IdlObject): HoldingsTreeNode {
+ findOrCreateVolNode(vol: IdlObject): HoldingsTreeNode {
const orgId = vol.owning_lib();
const orgNode = this.findOrCreateOrgNode(orgId);
findOrCreateCopyNode(copy: IdlObject): HoldingsTreeNode {
- const volNode = this.findOrCreateCallNumNode(copy.call_number());
+ const volNode = this.findOrCreateVolNode(copy.call_number());
const existing = volNode.children.filter(
c => c.target.id() === copy.id())[0];