From 0bc506f7c08d5941c30590daa281f02d28014f97 Mon Sep 17 00:00:00 2001 From: Galen Charlton Date: Wed, 1 Sep 2021 16:37:55 -0400 Subject: [PATCH] staff portal: implement clone action Signed-off-by: Galen Charlton --- .../app/staff/admin/local/admin-local.module.ts | 2 + .../clone-portal-entries-dialog.component.html | 50 ++++++++++++++++++++++ .../clone-portal-entries-dialog.component.ts | 34 +++++++++++++++ .../staff-portal-page.component.html | 8 ++++ .../staff-portal-page.component.ts | 49 +++++++++++++++++++++ 5 files changed, 143 insertions(+) create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.html create mode 100644 Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.ts diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local.module.ts index 099b071abe..2fff294dc9 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/admin-local.module.ts @@ -6,6 +6,7 @@ import {AdminCommonModule} from '@eg/staff/admin/common.module'; import {AdminLocalSplashComponent} from './admin-local-splash.component'; import {AddressAlertComponent} from './address-alert.component'; import {AdminCarouselComponent} from './admin-carousel.component'; +import {ClonePortalEntriesDialogComponent} from './staff_portal_page/clone-portal-entries-dialog.component'; import {AdminStaffPortalPageComponent} from './staff_portal_page/staff-portal-page.component'; import {StandingPenaltyComponent} from './standing-penalty.component'; @@ -15,6 +16,7 @@ import {StandingPenaltyComponent} from './standing-penalty.component'; AddressAlertComponent, AdminCarouselComponent, StandingPenaltyComponent, + ClonePortalEntriesDialogComponent, AdminStaffPortalPageComponent ], imports: [ diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.html new file mode 100644 index 0000000000..322c036146 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.html @@ -0,0 +1,50 @@ + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.ts new file mode 100644 index 0000000000..f630e39f44 --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/clone-portal-entries-dialog.component.ts @@ -0,0 +1,34 @@ +import {Component, Input, ViewChild, TemplateRef, OnInit} from '@angular/core'; +import {DialogComponent} from '@eg/share/dialog/dialog.component'; +import {NgForm, NG_VALIDATORS} from '@angular/forms'; +import {NgbModal} from '@ng-bootstrap/ng-bootstrap'; + +@Component({ + selector: 'eg-clone-portal-entries-dialog', + templateUrl: './clone-portal-entries-dialog.component.html' +}) + +export class ClonePortalEntriesDialogComponent + extends DialogComponent implements OnInit { + + result = { }; + + constructor( + private modal: NgbModal + ) { + super(modal); + } + + ngOnInit() { + this.onOpen$.subscribe(() => this._initRecord()); + } + + private _initRecord() { + this.result = { + source_library: null, + target_library: null, + overwrite_target: false + } + } + +} diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.html index ecfd722223..043615b589 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.html @@ -16,6 +16,11 @@ Failed to create new {{idlClassDef.label}} + + + + +
@@ -59,6 +64,9 @@ + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.ts index e312249b27..574f540a87 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/staff_portal_page/staff-portal-page.component.ts @@ -13,6 +13,8 @@ import {NetService} from '@eg/core/net.service'; import {GridCellTextGenerator} from '@eg/share/grid/grid'; import {StringComponent} from '@eg/share/string/string.component'; import {FmRecordEditorComponent} from '@eg/share/fm-editor/fm-editor.component'; +import {ClonePortalEntriesDialogComponent} from './clone-portal-entries-dialog.component'; +import {merge, Observable, empty} from 'rxjs'; @Component({ templateUrl: './staff-portal-page.component.html' @@ -31,6 +33,9 @@ export class AdminStaffPortalPageComponent extends AdminPageComponent implements @ViewChild('refreshString', { static: true }) refreshString: StringComponent; @ViewChild('refreshErrString', { static: true }) refreshErrString: StringComponent; + @ViewChild('cloneSuccessString', { static: true }) cloneSuccessString: StringComponent; + @ViewChild('cloneFailedString', { static: true }) cloneFailedString: StringComponent; + @ViewChild('cloneDialog', { static: true}) cloneDialog: ClonePortalEntriesDialogComponent; constructor( route: ActivatedRoute, @@ -54,4 +59,48 @@ export class AdminStaffPortalPageComponent extends AdminPageComponent implements this.defaultNewRecord.owner(this.auth.user().ws_ou()); } + cloneEntries() { + this.cloneDialog.open().subscribe( + result => { + this._handleClone(result.source_library, result.target_library, result.overwrite_target); + } + ); + } + + _handleClone(src: number, tgt: number, overwrite: Boolean) { + const updates: IdlObject[] = []; + + const delObs = (overwrite) ? + this.pcrud.search('cusppe', { owner: tgt }, {}, {}) : + empty(); + const newObs = this.pcrud.search('cusppe', { owner: src }, {}, {}); + merge(delObs, newObs).subscribe( + entry => { + if (entry.owner() === tgt) { + entry.isdeleted(true); + } else { + entry.owner(tgt); + entry.id(null); + entry.isnew(true); + } + updates.push(entry); + }, + err => {}, + ).add(() => { + this.pcrud.autoApply(updates).subscribe( + val => {}, + err => { + this.cloneFailedString.current() + .then(str => this.toast.danger(str)); + }, + () => { + this.cloneSuccessString.current() + .then(str => this.toast.success(str)); + this.searchOrgs = {primaryOrgId: tgt}; // change the org filter to the + // the one we just cloned into + this.grid.reload(); + } + ); + }); + } } -- 2.11.0