<div class="p-1" [ngStyle]="{flex: flexAt(2)}">
<ng-container *ngIf="copyIdx == 0 && volIdx == 0">
<input type="number" class="form-control form-control-sm"
- [required]="true" min="0"
+ [required]="true" [min]="existingVolCount(orgNode)"
[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" min="0"
+ [required]="true" [min]="existingCopyCount(volNode)"
[ngModel]="volNode.children.length"
(ngModelChange)="copyCountChanged(volNode, $event)"/>
</ng-container>
if (diff > 0) {
this.createVols(orgNode, diff);
} else if (diff < 0) {
- this.deleteVols(orgNode, diff);
+ this.deleteVols(orgNode, -diff);
}
}
return vol;
}
+ existingVolCount(orgNode: HoldingsTreeNode): number {
+ return orgNode.children.filter(volNode => !volNode.target.isnew()).length;
+ }
+
+ existingCopyCount(volNode: HoldingsTreeNode): number {
+ return volNode.children.filter(copyNode => !copyNode.target.isnew()).length;
+ }
+
+
+
createStubCopy(vol: IdlObject): IdlObject {
}
copyCountChanged(volNode: HoldingsTreeNode, count: number) {
- console.log('vol set set to ', count);
+ const diff = count - volNode.children.length;
+ if (diff > 0) {
+ this.createCopies(volNode, diff);
+ } else if (diff < 0) {
+ this.deleteCopies(volNode, -diff);
+ }
+ }
+
+ // This only removes copies that were created during the
+ // current editing session and have not yet been saved in the DB.
+ deleteCopies(volNode: HoldingsTreeNode, count: number) {
+ for (let i = 0; i < count; i++) {
+ const copyNode = volNode.children[volNode.children.length - 1];
+ if (copyNode && copyNode.target.isnew()) {
+ volNode.children.pop();
+ } else {
+ break;
+ }
+ }
+ }
+
+ createCopies(volNode: HoldingsTreeNode, count: number) {
+ for (let i = 0; i < count; i++) {
+
+ // Our context assumes copies are fleshed with volumes
+ const vol = volNode.target;
+ const copy = this.createStubCopy(vol);
+ copy.call_number(vol);
+ this.context.findOrCreateCopyNode(copy);
+ }
}
+
createVols(orgNode: HoldingsTreeNode, count: number) {
for (let i = 0; i < count; i++) {
}
}
-
+ // This only removes vols that were created during the
+ // current editing session and have not yet been saved in the DB.
deleteVols(orgNode: HoldingsTreeNode, count: number) {
+ for (let i = 0; i < count; i++) {
+ const volNode = orgNode.children[orgNode.children.length - 1];
+ if (volNode && volNode.target.isnew()) {
+ orgNode.children.pop();
+ } else {
+ break;
+ }
+ }
}
-
// 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;