From 8e1e2faf6bcf08f9075372d9cc60f7ba92e16478 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 8 Jun 2020 12:23:50 -0400 Subject: [PATCH] LPXXX Angular Volcopy Signed-off-by: Bill Erickson --- .../app/staff/cat/volcopy/vol-edit.component.html | 4 +- .../app/staff/cat/volcopy/vol-edit.component.ts | 57 ++++++++++++++++++++-- .../src/app/staff/cat/volcopy/volcopy.component.ts | 4 +- 3 files changed, 56 insertions(+), 9 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html index a8a74c722b..0360b00601 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.html @@ -118,7 +118,7 @@
@@ -174,7 +174,7 @@
diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts index 29692eb362..46d3dff8de 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/vol-edit.component.ts @@ -145,7 +145,7 @@ export class VolEditComponent implements OnInit { if (diff > 0) { this.createVols(orgNode, diff); } else if (diff < 0) { - this.deleteVols(orgNode, diff); + this.deleteVols(orgNode, -diff); } } @@ -164,6 +164,16 @@ export class VolEditComponent implements OnInit { 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 { @@ -190,9 +200,39 @@ export class VolEditComponent implements OnInit { } 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++) { @@ -206,15 +246,22 @@ export class VolEditComponent implements OnInit { } } - + // 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; diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts index dd9173f86c..a080c3f44a 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.component.ts @@ -102,12 +102,12 @@ export class VolCopyComponent implements OnInit { return this.pcrud.search('acn', {id: ids}) .pipe(tap(vol => this.context.findOrCreateVolNode(vol))) - .pipe(tap(vol => { + .toPromise().then(_ => { 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. -- 2.11.0