From 0b671ab7d7e4d42a478530d19815bb370291ff83 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 26 Mar 2019 13:30:54 -0400 Subject: [PATCH] LP1821382 Link as conjoined items menu action Signed-off-by: Bill Erickson Signed-off-by: Dan Wells --- .../catalog/record/holdings.component.html | 6 + .../catalog/record/holdings.component.ts | 17 ++- .../conjoined-items-dialog.component.html | 42 ++++++ .../conjoined-items-dialog.component.ts | 120 ++++++++++++++++++ .../staff/share/holdings/holdings.module.ts | 7 +- 5 files changed, 189 insertions(+), 3 deletions(-) create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html index dddba6ede2..895734512f 100644 --- a/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html +++ b/Open-ILS/src/eg2/src/app/staff/catalog/record/holdings.component.html @@ -50,6 +50,7 @@ +
@@ -85,6 +86,11 @@ i18n-label label="Request Items" (onClick)="requestItems($event)"> + + + {}, + ok => {}, + dismissed => {} + ); + } + } + + openConjoinedDialog(rows: HoldingsEntry[]) { + const copyIds = this.selectedCopyIds(rows); + if (copyIds.length > 0) { + this.conjoinedDialog.copyIds = copyIds; + this.conjoinedDialog.open({size: 'sm'}).then( + ok => {}, // No grid reload required dismissed => {} ); } diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.html new file mode 100644 index 0000000000..906ce24765 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.html @@ -0,0 +1,42 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.ts new file mode 100644 index 0000000000..51000a77cd --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/conjoined-items-dialog.component.ts @@ -0,0 +1,120 @@ +import {Component, OnInit, OnDestroy, Input, ViewChild, Renderer2} from '@angular/core'; +import {Subscription} from 'rxjs'; +import {IdlService} from '@eg/core/idl.service'; +import {PcrudService} from '@eg/core/pcrud.service'; +import {ToastService} from '@eg/share/toast/toast.service'; +import {StoreService} from '@eg/core/store.service'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {StringComponent} from '@eg/share/string/string.component'; +import {ComboboxEntry} from '@eg/share/combobox/combobox.component'; + + +/** + * Dialog for linking conjoined items. + */ + +@Component({ + selector: 'eg-conjoined-items-dialog', + templateUrl: 'conjoined-items-dialog.component.html' +}) + +export class ConjoinedItemsDialogComponent + extends DialogComponent implements OnInit, OnDestroy { + + @Input() copyIds: number[]; + ids: number[]; // copy of list so we can pop() + + peerType: number; + numSucceeded: number; + numFailed: number; + peerTypes: ComboboxEntry[]; + peerRecord: number; + + onOpenSub: Subscription; + + @ViewChild('successMsg') + private successMsg: StringComponent; + + @ViewChild('errorMsg') + private errorMsg: StringComponent; + + constructor( + private modal: NgbModal, // required for passing to parent + private toast: ToastService, + private idl: IdlService, + private pcrud: PcrudService, + private localStore: StoreService) { + super(modal); // required for subclassing + this.peerTypes = []; + } + + ngOnInit() { + this.onOpenSub = this.onOpen$.subscribe(() => { + this.ids = [].concat(this.copyIds); + this.numSucceeded = 0; + this.numFailed = 0; + this.peerRecord = + this.localStore.getLocalItem('eg.cat.marked_conjoined_record'); + + if (!this.peerRecord) { + this.close(false); + } + + if (this.peerTypes.length === 0) { + this.getPeerTypes(); + } + }); + } + + ngOnDestroy() { + this.onOpenSub.unsubscribe(); + } + + getPeerTypes(): Promise { + return this.pcrud.retrieveAll('bpt', {}, {atomic: true}).toPromise() + .then(types => + // Map types to ComboboxEntry's + this.peerTypes = types.map(t => ({id: t.id(), label: t.name()})) + ); + } + + peerTypeChanged(entry: ComboboxEntry) { + if (entry) { + this.peerType = entry.id; + } else { + this.peerType = null; + } + } + + linkCopies(): Promise { + + if (this.ids.length === 0) { + this.close(this.numSucceeded > 0); + return Promise.resolve(); + } + + const id = this.ids.pop(); + const map = this.idl.create('bpbcm'); + map.peer_record(this.peerRecord); + map.target_copy(id); + map.peer_type(this.peerType); + + return this.pcrud.create(map).toPromise().then( + ok => { + this.successMsg.current().then(msg => this.toast.success(msg)); + this.numSucceeded++; + return this.linkCopies(); + }, + err => { + this.numFailed++; + console.error(err); + this.errorMsg.current().then(msg => this.toast.warning(msg)); + return this.linkCopies(); + } + ); + } +} + + + diff --git a/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts b/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts index 97a65ce0e2..d9ae4fb7e3 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/holdings/holdings.module.ts @@ -6,6 +6,7 @@ import {MarkMissingDialogComponent} from './mark-missing-dialog.component'; import {CopyAlertsDialogComponent} from './copy-alerts-dialog.component'; import {ReplaceBarcodeDialogComponent} from './replace-barcode-dialog.component'; import {DeleteVolcopyDialogComponent} from './delete-volcopy-dialog.component'; +import {ConjoinedItemsDialogComponent} from './conjoined-items-dialog.component'; @NgModule({ declarations: [ @@ -13,7 +14,8 @@ import {DeleteVolcopyDialogComponent} from './delete-volcopy-dialog.component'; MarkMissingDialogComponent, CopyAlertsDialogComponent, ReplaceBarcodeDialogComponent, - DeleteVolcopyDialogComponent + DeleteVolcopyDialogComponent, + ConjoinedItemsDialogComponent ], imports: [ StaffCommonModule @@ -23,7 +25,8 @@ import {DeleteVolcopyDialogComponent} from './delete-volcopy-dialog.component'; MarkMissingDialogComponent, CopyAlertsDialogComponent, ReplaceBarcodeDialogComponent, - DeleteVolcopyDialogComponent + DeleteVolcopyDialogComponent, + ConjoinedItemsDialogComponent ], providers: [ HoldingsService -- 2.43.2