From: Kyle Huckins Date: Sun, 27 Feb 2022 01:33:29 +0000 (+0000) Subject: lp1940105 Archive Course Should Use detach_material X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=5e812fb64f612efd5cecb18a97a4c857dc4da3d7;p=working%2FEvergreen.git lp1940105 Archive Course Should Use detach_material - Replaced resetItemFields with detachMaterials in Course Service - Refactored disassociateMaterials to utilize detach_materials - Refacotred deleteSelectedMaterials to utilize Course Service detachMaterials function Signed-off-by: Kyle Huckins Signed-off-by: Jane Sandberg Signed-off-by: Michele Morgan --- diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts index 99fd469568..8534d21437 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts @@ -204,12 +204,7 @@ export class CourseAssociateMaterialComponent extends DialogComponent implements } deleteSelectedMaterials(items) { - const deleteRequest$ = []; - items.forEach(item => { - deleteRequest$.push(this.net.request( - 'open-ils.courses', 'open-ils.courses.detach_material', - this.auth.token(), item.id())); - }); + let deleteRequest$ = this.course.detachMaterials(items); merge(...deleteRequest$).subscribe( val => { this.materialDeleteSuccessString.current().then(str => this.toast.success(str)); diff --git a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts index cb6e9543bb..53766381d7 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -157,6 +157,8 @@ export class CourseService { } disassociateMaterials(courses) { + const deleteRequest$ = []; + return new Promise((resolve, reject) => { const course_ids = []; const course_library_hash = {}; @@ -164,23 +166,36 @@ export class CourseService { course_ids.push(course.id()); course_library_hash[course.id()] = course.owning_lib(); }); - this.pcrud.search('acmcm', {course: course_ids}).subscribe(material => { - material.isdeleted(true); - this.resetItemFields(material, course_library_hash[material.course()]); - this.pcrud.autoApply(material).subscribe(() => { + + this.pcrud.retrieveAll('acmcm', {course: course_ids}).subscribe(material => { + deleteRequest$.push(this.net.request( + 'open-ils.courses', 'open-ils.courses.detach_material', + this.auth.token(), material.id())); + }, err => { + reject(err); + }, () => { + merge(...deleteRequest$).subscribe(val => { + console.log(val); }, err => { reject(err); }, () => { - resolve(material); + resolve(courses); }); - }, err => { - reject(err); - }, () => { - resolve(courses); }); }); } + detachMaterials(materials) { + const deleteRequest$ = []; + materials.forEach(material => { + deleteRequest$.push(this.net.request( + 'open-ils.courses', 'open-ils.courses.detach_material', + this.auth.token(), material.id())); + }); + + return deleteRequest$; + } + disassociateUsers(user) { return new Promise((resolve, reject) => { const user_ids = []; @@ -206,28 +221,6 @@ export class CourseService { }); } - resetItemFields(material, course_lib) { - this.pcrud.retrieve('acp', material.item(), - {flesh: 3, flesh_fields: {acp: ['call_number']}}).subscribe(copy => { - if (material.original_status()) { - copy.status(material.original_status()); - } - if (copy.circ_modifier() !== material.original_circ_modifier()) { - copy.circ_modifier(material.original_circ_modifier()); - } - if (material.original_location()) { - copy.location(material.original_location()); - } - if (material.original_callnumber()) { - this.pcrud.retrieve('acn', material.original_callnumber()).subscribe(cn => { - this.updateItem(copy, course_lib, cn.label(), true); - }); - } else { - this.updateItem(copy, course_lib, copy.call_number().label(), false); - } - }); - } - updateItem(item: IdlObject, courseLib: IdlObject, callNumber: string, updatingVolume: boolean) { const cn = item.call_number();