<span *ngIf="copyIdx == 0">{{orgNode.target.shortname()}}</span>
</div>
<div class="p-1" [ngStyle]="{flex: flexAt(2)}">
- <ng-container *ngIf="copyIdx == 0">
+ <ng-container *ngIf="copyIdx == 0 && volIdx == 0">
<input type="number" class="form-control form-control-sm"
- [required]="true"
+ [required]="true" min="0"
[ngModel]="orgNode.children.length"
(ngModelChange)="volCountChanged(orgNode, $event)"/>
</ng-container>
<div class="p-1" [ngStyle]="{flex: flexAt(7)}">
<ng-container *ngIf="copyIdx == 0">
<input type="number" class="form-control form-control-sm"
- [required]="true"
+ [required]="true" min="0"
[ngModel]="volNode.children.length"
(ngModelChange)="copyCountChanged(volNode, $event)"/>
</ng-container>
Duplicate Barcode</div>
</div>
<div class="p-1" [ngStyle]="{flex: flexAt(9)}">
- <input type="number" class="form-control form-control-sm"
+ <input type="number" min="0" class="form-control form-control-sm"
[ngModel]="copyNode.target.copy_number()"
(ngModelChange)="applyCopyValue(copyNode.target, 'copy_number', $event)"/>
</div>
import {Component, OnInit, AfterViewInit, ViewChild, Input, Renderer2} from '@angular/core';
import {Router, ActivatedRoute, ParamMap} from '@angular/router';
import {tap} from 'rxjs/operators';
-import {IdlObject} from '@eg/core/idl.service';
+import {IdlService, IdlObject} from '@eg/core/idl.service';
import {OrgService} from '@eg/core/org.service';
import {AuthService} from '@eg/core/auth.service';
import {NetService} from '@eg/core/net.service';
autoBarcodeInProgress = false;
useCheckdigit = false;
+ autoId = -1;
+
constructor(
private renderer: Renderer2,
+ private idl: IdlService,
private pcrud: PcrudService,
private net: NetService,
private auth: AuthService,
ngOnInit() {
this.fetchRecordVolLabels()
- .then(_ => this.fetchBibParts());
+ .then(_ => this.fetchBibParts())
+ .then(_ => this.addStubCopies());
// TODO: Filter these to only show org-scoped values
// plus any values otherwise needed for the current
}
volCountChanged(orgNode: HoldingsTreeNode, count: number) {
- console.log('vol set set to ', count);
+ const diff = count - orgNode.children.length;
+ if (diff > 0) {
+ this.createVols(orgNode, diff);
+ } else if (diff < 0) {
+ this.deleteVols(orgNode, diff);
+ }
+ }
+
+ createStubVol(orgId: number): IdlObject {
+ // Volume creation should only be available as an option when
+ // working with a specific call bib record.
+ const recId = +this.context.getRecordIds()[0];
+
+ const vol = this.idl.create('acn');
+ vol.id(this.autoId--);
+ vol.isnew(true);
+ vol.record(recId);
+ vol.label(this.recordVolLabels[0] || '');
+ vol.owning_lib(orgId);
+
+ return vol;
+ }
+
+
+ createStubCopy(vol: IdlObject): IdlObject {
+
+ const copy = this.idl.create('acp');
+ copy.id(this.autoId--);
+ copy.isnew(true);
+ copy.circ_lib(vol.owning_lib());
+ copy.call_number(vol.id());
+ copy.deposit(0);
+ copy.price(0);
+ copy.deposit_amount(0);
+ copy.fine_level(2); // Normal
+ copy.loan_duration(2); // Normal
+ copy.location(1); // Stacks
+ copy.circulate('t');
+ copy.holdable('t');
+ copy.opac_visible('t');
+ copy.ref('f');
+ copy.mint_condition('t');
+
+ // TODO: status / fast-add / defaults?
+
+ return copy;
}
copyCountChanged(volNode: HoldingsTreeNode, count: number) {
console.log('vol set set to ', count);
}
+ createVols(orgNode: HoldingsTreeNode, count: number) {
+ for (let i = 0; i < count; i++) {
+
+ // This will vivify the volNode if needed.
+ const vol = this.createStubVol(orgNode.target.id())
+
+ // Our context assumes copies are fleshed with volumes
+ const copy = this.createStubCopy(vol);
+ copy.call_number(vol);
+ this.context.findOrCreateCopyNode(copy);
+ }
+ }
+
+
+ deleteVols(orgNode: HoldingsTreeNode, count: number) {
+ }
+
+
+ // Empty volumes get a stub copy
+ addStubCopies() {
+
+ // TODO: timing issue -- all vols getting stubs
+ this.context.volNodes().forEach(volNode => {
+ if (volNode.children.length == 0) {
+ const vol = volNode.target;
+ const copy = this.createStubCopy(vol);
+ copy.call_number(vol);
+ this.context.findOrCreateCopyNode(copy);
+ }
+ });
+ }
+
applyVolValue(vol: IdlObject, key: string, value: any) {
if (value === null && (key === 'prefix' || key === 'suffix')) {