From 6fcd6bd2d667e4d9df72d820129b53e9c8078312 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Thu, 25 Jun 2020 12:31:10 -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 | 59 +++++++++------------- .../src/app/staff/cat/volcopy/volcopy.component.ts | 2 +- .../src/app/staff/cat/volcopy/volcopy.service.ts | 34 +++++++++++-- 4 files changed, 57 insertions(+), 42 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 8d06132c4e..86e6cf7e9f 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 @@ -246,11 +246,11 @@ - 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 f01c346d29..cca42f75e9 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 @@ -30,8 +30,6 @@ export class VolEditComponent implements OnInit { flexSettings: {[column: number]: number} = { 1: 1, 2: 1, 3: 2, 4: 1, 5: 2, 6: 1, 7: 1, 8: 2, 9: 1, 10: 1}; - bibParts: {[bibId: number]: IdlObject[]} = {}; - batchVolClass: ComboboxEntry; batchVolPrefix: ComboboxEntry; batchVolSuffix: ComboboxEntry; @@ -69,41 +67,10 @@ export class VolEditComponent implements OnInit { this.volcopy.fetchRecordVolLabels(this.context.recordId) .then(labels => this.recordVolLabels = labels) - .then(_ => this.fetchBibParts()) + .then(_ => this.volcopy.fetchBibParts(this.context.getRecordIds())) .then(_ => this.addStubCopies()); } - - fetchBibParts() { - - this.context.orgNodes().forEach(orgNode => { - orgNode.children.forEach(volNode => - this.bibParts[volNode.target.record()] = [] - ); - }); - - if (Object.keys(this.bibParts).length === 0) { return; } - - this.pcrud.search('bmp', - {record: Object.keys(this.bibParts), deleted: 'f'}) - .subscribe( - part => { - if (!this.bibParts[part.record()]) { - this.bibParts[part.record()] = []; - } - this.bibParts[part.record()].push(part); - }, - err => {}, - () => { - Object.keys(this.bibParts).forEach(bibId => { - this.bibParts[bibId] = this.bibParts[bibId] - .sort((p1, p2) => - p1.label_sortkey() < p2.label_sortkey() ? -1 : 1); - }); - } - ); - } - copyStatLabel(copy: IdlObject): string { if (copy) { const statId = copy.status(); @@ -115,7 +82,8 @@ export class VolEditComponent implements OnInit { } recordHasParts(bibId: number): boolean { - return this.bibParts[bibId] && this.bibParts[bibId].length > 0; + return this.volcopy.bibParts[bibId] && + this.volcopy.bibParts[bibId].length > 0; } flexAt(column: number): number { @@ -258,7 +226,26 @@ export class VolEditComponent implements OnInit { } copyPartChanged(copyNode: HoldingsTreeNode, entry: ComboboxEntry) { - // TODO + const copy = copyNode.target; + let part = copyNode.target.parts()[0]; + + if (entry) { + + const newPart = + this.volcopy.bibParts[copy.call_number().record()] + .filter(p => p.id() === entry.id)[0]; + + // Nothing to change? + if (part && part.id() === newPart.id()) { return; } + + copy.parts([newPart]); + copy.ischanged(true); + + } else if (part) { // Part map no longer needed. + + copy.parts([]); + copy.ischanged(true); + } } batchVolApply() { 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 8f156351fd..d4aaf7f501 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 @@ -322,7 +322,7 @@ export class VolCopyComponent implements OnInit { } }); - newVol.copies(copies); + newVol.copies(copies); if (newVol.ischanged() || newVol.isnew() || copies.length > 0) { volumes.push(newVol); diff --git a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts index 31e4661ba8..80f04c4543 100644 --- a/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/cat/volcopy/volcopy.service.ts @@ -31,6 +31,7 @@ export class VolCopyService { defaults: VolCopyDefaults = null; defaultLocation: IdlObject; copyStatuses: {[id: number]: IdlObject} = null; + bibParts: {[bibId: number]: IdlObject[]} = {}; // This will be all 'local' copy locations plus any remote // locations that we are required to interact with. @@ -196,13 +197,12 @@ export class VolCopyService { Promise.resolve(); return promise - .then(_ => - this.serverStore.getItem('cat.copy.templates')) + .then(_ => this.serverStore.getItem('cat.copy.templates')) .then(templates => { this.templates = templates; - this.templateNames = Object.keys(tmpls) + this.templateNames = Object.keys(templates) .sort((n1, n2) => n1 < n2 ? -1 : 1) .map(name => ({id: name, label: name})); @@ -467,5 +467,33 @@ export class VolCopyService { return this.serverStore.setItem( 'eg.cat.volcopy.defaults', this.defaults); } + + fetchBibParts(recordIds: number[]) { + + if (recordIds.length === 0) { return; } + + // Avoid doubling up + if (this.bibParts[recordIds[0]]) { return; } + + this.pcrud.search('bmp', + {record: recordIds, deleted: 'f'}) + .subscribe( + part => { + if (!this.bibParts[part.record()]) { + this.bibParts[part.record()] = []; + } + this.bibParts[part.record()].push(part); + }, + err => {}, + () => { + recordIds.forEach(bibId => { + this.bibParts[bibId] = this.bibParts[bibId] + .sort((p1, p2) => + p1.label_sortkey() < p2.label_sortkey() ? -1 : 1); + }); + } + ); + } + } -- 2.11.0