lp1849212 Associate Item from Service
authorKyle Huckins <khuckins@catalyte.io>
Thu, 5 Dec 2019 17:37:46 +0000 (17:37 +0000)
committerJane Sandberg <sandbej@linnbenton.edu>
Wed, 26 Aug 2020 22:53:43 +0000 (15:53 -0700)
- Move bulk of Associate Item funcitonality into Course Service

Signed-off-by: Kyle Huckins <khuckins@catalyte.io>
 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

Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-associate-material.component.ts
Open-ILS/src/eg2/src/app/staff/share/course.service.ts

index 5fcad15..a6c1971 100644 (file)
@@ -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));
                 });
index cca2882..0856cfd 100644 (file)
@@ -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 = [];