From 9ab93c45157ddfad2148008c3c82e4c9a4d2a182 Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Wed, 10 Feb 2021 17:37:57 -0800 Subject: [PATCH] LP1907974: Updating call numbers in course module reflected in grid 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 Signed-off-by: Michele Morgan --- .../course-associate-material.component.ts | 24 ++++---- .../src/eg2/src/app/staff/share/course.service.ts | 64 ++++++++-------------- 2 files changed, 36 insertions(+), 52 deletions(-) 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 27c8ecf542..99fd469568 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 @@ -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; 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 6c84647c78..6f56fe0477 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 @@ -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(); + } } -- 2.11.0