LP1907974: Updating call numbers in course module reflected in grid
authorJane Sandberg <sandbej@linnbenton.edu>
Thu, 11 Feb 2021 01:37:57 +0000 (17:37 -0800)
committerMichele Morgan <mmorgan@noblenet.org>
Tue, 27 Sep 2022 17:52:17 +0000 (13:52 -0400)
Also:
  * refactors the updateItem method for more idiomatic RxJS usage (e.g.
    no nested subscribes)
  * corrects some Boolean, String, and Number types to boolean, string,
    and number (to use the primitive types instead of objects, as
    recommended by the Typescript handbook:
    https://www.typescriptlang.org/docs/handbook/basic-types.html#about-number-string-boolean-symbol-and-object)

To test:

1) Go to Local Admin > Course List
2) Double click on a course
3) Go to the materials tab
4) Add an item by barcode, making sure to supply a temporary call
   number, and that the call number checkbox is checked.
5) Note that the grid on the right display's the item's old call number,
   not its new one.
6) Apply this patch.
7) Repeat step 4.  Note that the temporary call number is reflected in
   the grid now.

Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Signed-off-by: Michele Morgan <mmorgan@noblenet.org>

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 27c8ecf..99fd469 100644 (file)
@@ -25,8 +25,8 @@ import {CourseService} from '@eg/staff/share/course.service';
 export class CourseAssociateMaterialComponent extends DialogComponent implements OnInit {
     @Input() currentCourse: IdlObject;
     @Input() courseId: any;
-    @Input() courseIsArchived: String;
-    @Input() displayMode: String;
+    @Input() courseIsArchived: string;
+    @Input() displayMode: string;
     materials: any[] = [];
     @ViewChild('editDialog', { static: true }) editDialog: FmRecordEditorComponent;
     @ViewChild('materialsGrid', {static: false}) materialsGrid: GridComponent;
@@ -45,16 +45,16 @@ export class CourseAssociateMaterialComponent extends DialogComponent implements
     @ViewChild('materialAddDifferentLibraryString', { static: true })
         materialAddDifferentLibraryString: StringComponent;
     materialsDataSource: GridDataSource;
-    @Input() barcodeInput: String;
-    @Input() relationshipInput: String;
-    @Input() tempCallNumber: String;
-    @Input() tempStatus: Number;
-    @Input() tempLocation: Number;
-    @Input() tempCircMod: String;
-    @Input() isModifyingStatus: Boolean;
-    @Input() isModifyingCircMod: Boolean;
-    @Input() isModifyingCallNumber: Boolean;
-    @Input() isModifyingLocation: Boolean;
+    @Input() barcodeInput: string;
+    @Input() relationshipInput: string;
+    @Input() tempCallNumber: string;
+    @Input() tempStatus: number;
+    @Input() tempLocation: number;
+    @Input() tempCircMod: string;
+    @Input() isModifyingStatus: boolean;
+    @Input() isModifyingCircMod: boolean;
+    @Input() isModifyingCallNumber: boolean;
+    @Input() isModifyingLocation: boolean;
     bibId: number;
 
     associateBriefRecord: (newRecord: string) => void;
index 6c84647..6f56fe0 100644 (file)
@@ -1,5 +1,5 @@
-import {Observable} from 'rxjs';
-import {tap} from 'rxjs/operators';
+import {Observable, throwError} from 'rxjs';
+import {switchMap, tap} from 'rxjs/operators';
 import {Injectable} from '@angular/core';
 import {AuthService} from '@eg/core/auth.service';
 import {EventService} from '@eg/core/event.service';
@@ -229,44 +229,28 @@ export class CourseService {
     }
 
 
-    updateItem(item: IdlObject, courseLib, callNumber, updatingVolume) {
-        return new Promise((resolve, reject) => {
-            this.pcrud.update(item).subscribe(() => {
-                if (updatingVolume) {
-                    const cn = item.call_number();
-                    const callNumberLibrary = this.org.canHaveVolumes(courseLib) ? courseLib.id() : cn.owning_lib();
-                    return this.net.request(
-                        'open-ils.cat', 'open-ils.cat.call_number.find_or_create',
-                        this.auth.token(), callNumber, cn.record(),
-                        callNumberLibrary, cn.prefix(), cn.suffix(),
-                        cn.label_class()
-                    ).subscribe(res => {
-                        const event = this.evt.parse(res);
-                        if (event) { return; }
-                        return this.net.request(
-                            'open-ils.cat', 'open-ils.cat.transfer_copies_to_volume',
-                            this.auth.token(), res.acn_id, [item.id()]
-                        ).subscribe(transfered_res => {
-                            console.debug('Copy transferred to volume with code ' + transfered_res);
-                        }, err => {
-                            reject(err);
-                        }, () => {
-                            resolve(item);
-                        });
-                    }, err => {
-                        reject(err);
-                    }, () => {
-                        resolve(item);
-                    });
-                } else {
-                    this.pcrud.update(item).subscribe(() => {
-                        resolve(item);
-                    }, () => {
-                        reject(item);
-                    });
-                }
-            });
-        });
+    updateItem(item: IdlObject, courseLib: IdlObject, callNumber: string, updatingVolume: boolean) {
+        const cn = item.call_number();
+        const callNumberLibrary = this.org.canHaveVolumes(courseLib) ? courseLib.id() : cn.owning_lib();
+
+        const itemObservable = this.pcrud.update(item);
+        const callNumberObservable = this.net.request(
+            'open-ils.cat', 'open-ils.cat.call_number.find_or_create',
+            this.auth.token(), callNumber, cn.record(),
+            callNumberLibrary, cn.prefix(), cn.suffix(),
+            cn.label_class()
+        ).pipe(switchMap(res => {
+            const event = this.evt.parse(res);
+            if (event) { return throwError; }
+            return this.net.request(
+                'open-ils.cat', 'open-ils.cat.transfer_copies_to_volume',
+                this.auth.token(), res.acn_id, [item.id()]
+            );
+        }));
+
+        return updatingVolume ? itemObservable.pipe(switchMap(() => callNumberObservable)).toPromise() :
+            itemObservable.toPromise();
+
     }
 
 }