From: Kyle Huckins Date: Thu, 5 Dec 2019 17:37:46 +0000 (+0000) Subject: lp1849212 Associate Item from Service X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=fc22c667e9ea8066ac79d9452172a5be72bc1998;p=working%2FEvergreen.git lp1849212 Associate Item from Service - Move bulk of Associate Item funcitonality into Course Service Signed-off-by: Kyle Huckins Changes to be committed: modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts modified: Open-ILS/src/eg2/src/app/staff/share/course.service.ts --- 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 5fcad15b96..a6c1971e6e 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 @@ -88,53 +88,38 @@ export class CourseAssociateMaterialComponent extends DialogComponent { associateItem(barcode, relationship) { if (barcode) { - this.pcrud.search('acp', {barcode: barcode}, - {flesh: 3, flesh_fields: {acp: ['call_number']}}).subscribe(item => { - let material = this.idl.create('acmcm'); - material.item(item.id()); - material.course(this.currentCourse.id()); - if (relationship) material.relationship(relationship); - if (this.isModifyingStatus && this.tempStatus) { - material.original_status(item.status()); - item.status(this.tempStatus); - } - if (this.isModifyingLocation && this.tempLocation) { - material.original_location(item.location()); - item.location(this.tempLocation); - } - if (this.isModifyingCircMod) { - material.original_circ_modifier(item.circ_modifier()); - item.circ_modifier(this.tempCircMod); - if (!this.tempCircMod) item.circ_modifier(null); - } - if (this.isModifyingCallNumber) { - material.original_callnumber(item.call_number()); - } - this.pcrud.create(material).subscribe( - val => { - console.debug('created: ' + val); - let new_cn = item.call_number().label(); - if (this.tempCallNumber) new_cn = this.tempCallNumber; - this.courseSvc.updateItem(item, this.currentCourse.owning_lib(), new_cn, this.isModifyingCallNumber).then(res => { - this.fetchItem(item.id(), relationship); + let args = { + barcode: barcode, + relationship: relationship, + isModifyingCallNumber: this.isModifyingCallNumber, + isModifyingCircMod: this.isModifyingCircMod, + isModifyingLocation: this.isModifyingLocation, + isModifyingStatus: this.isModifyingStatus, + tempCircMod: this.tempCircMod, + tempLocation: this.tempLocation, + tempStatus: this.tempStatus, + currentCourse: this.currentCourse + } + + this.pcrud.search('acp', {barcode: barcode}, { + flesh: 3, flesh_fields: {acp: ['call_number']} + }).subscribe(item => { + let associatedMaterial = this.courseSvc.associateMaterials(item, args); + console.log(associatedMaterial); + associatedMaterial.material.then(res => { + item = associatedMaterial.item; + let new_cn = item.call_number().label(); + if (this.tempCallNumber) new_cn = this.tempCallNumber; + this.courseSvc.updateItem(item, + this.currentCourse.owning_lib(), + new_cn, args.isModifyingCallNumber).then(resp => { + this.fetchItem(item.id(), args.relationship); if (item.circ_lib() != this.currentCourse.owning_lib()) { this.differentLibraryString.current().then(str => this.toast.warning(str)); } else { this.successString.current().then(str => this.toast.success(str)); } }); - - // Cleaning up inputs - this.barcodeInput = ""; - this.relationshipInput = ""; - this.tempStatus = null; - this.tempCircMod = null; - this.tempCallNumber = null; - this.tempLocation = null; - this.isModifyingCallNumber = false; - this.isModifyingCircMod = false; - this.isModifyingLocation = false; - this.isModifyingStatus = false; }, err => { this.failedString.current().then(str => this.toast.danger(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 cca2882396..0856cfd6c1 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 @@ -79,6 +79,39 @@ export class CourseService { }); } + // Creating a new acmcm Entry + associateMaterials(item, args) { + console.log("entering associateMaterials") + let material = this.idl.create('acmcm'); + material.item(item.id()); + material.course(args.currentCourse.id()); + if (args.relationship) material.relationship(args.relationship); + + // Apply temporary fields to the item + if (args.isModifyingStatus && args.tempStatus) { + material.original_status(item.status()); + item.status(args.tempStatus); + } + if (args.isModifyingLocation && args.tempLocation) { + material.original_location(item.location()); + item.location(args.tempLocation); + } + if (args.isModifyingCircMod) { + material.original_circ_modifier(item.circ_modifier()); + item.circ_modifier(args.tempCircMod); + if (!args.tempCircMod) item.circ_modifier(null); + } + if (args.isModifyingCallNumber) { + material.original_callnumber(item.call_number()); + } + let response = { + item: item, + material: this.pcrud.create(material).toPromise() + }; + + return response; + } + disassociateMaterials(courses) { return new Promise((resolve, reject) => { let course_ids = [];