From: Kyle Huckins Date: Mon, 25 Nov 2019 20:46:53 +0000 (+0000) Subject: lp1849212 - Move Course Service to staff/share directory X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2428a57f3bccd436fce59a023778d6309ea4ee5b;p=Evergreen.git lp1849212 - Move Course Service to staff/share directory 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/admin/local/course-reserves/course-list.component.ts modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts renamed: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course.service.ts -> Open-ILS/src/eg2/src/app/staff/share/course.service.ts Signed-off-by: Michele Morgan Signed-off-by: Galen Charlton --- 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 cb8eeeb317..5fcad15b96 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 @@ -13,7 +13,7 @@ import {GridComponent} from '@eg/share/grid/grid.component'; import {IdlObject, IdlService} from '@eg/core/idl.service'; import {StringComponent} from '@eg/share/string/string.component'; import {ToastService} from '@eg/share/toast/toast.service'; -import {CourseService} from './course.service'; +import {CourseService} from '@eg/staff/share/course.service'; @Component({ selector: 'eg-course-associate-material-dialog', diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.ts index ab9cd3b36e..53875f39b0 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-list.component.ts @@ -2,7 +2,7 @@ import {Component, Input, ViewChild, OnInit} from '@angular/core'; import {IdlObject} from '@eg/core/idl.service'; import {PcrudService} from '@eg/core/pcrud.service'; import {AuthService} from '@eg/core/auth.service'; -import {CourseService} from './course.service'; +import {CourseService} from '@eg/staff/share/course.service'; import {NetService} from '@eg/core/net.service'; import {OrgService} from '@eg/core/org.service'; import {GridComponent} from '@eg/share/grid/grid.component'; diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts index 6f6eed594a..64bd5dc183 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-reserves.module.ts @@ -5,7 +5,8 @@ import {CourseListComponent} from './course-list.component'; import {CourseAssociateMaterialComponent} from './course-associate-material.component'; import {CourseReservesRoutingModule} from './routing.module'; import {ItemLocationSelectModule} from '@eg/share/item-location-select/item-location-select.module'; -import {CourseService} from './course.service' +import {CourseService} from '@eg/staff/share/course.service'; + @NgModule({ declarations: [ CourseListComponent, diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course.service.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course.service.ts deleted file mode 100644 index c8b60cc15d..0000000000 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course.service.ts +++ /dev/null @@ -1,100 +0,0 @@ -import {AuthService} from '@eg/core/auth.service'; -import {EventService} from '@eg/core/event.service'; -import {IdlObject, IdlService} from '@eg/core/idl.service'; -import {NetService} from '@eg/core/net.service'; -import {PcrudService} from '@eg/core/pcrud.service'; - -export class CourseService { - - constructor( - private auth: AuthService, - private evt: EventService, - private idl: IdlService, - private net: NetService, - private pcrud: PcrudService - ) {} - - disassociateMaterials(courses) { - return new Promise((resolve, reject) => { - let course_ids = []; - let course_library_hash = {}; - courses.forEach(course => { - 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(res => { - console.log(res); - }, err => { - reject(err); - }, () => { - resolve(material); - }); - }, err => { - reject(err) - }, () => { - resolve(courses); - }); - }); - } - - 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, course_lib, call_number, updatingVolume) { - return new Promise((resolve, reject) => { - this.pcrud.update(item).subscribe(item_id => { - if (updatingVolume) { - let cn = item.call_number(); - return this.net.request( - 'open-ils.cat', 'open-ils.cat.call_number.find_or_create', - this.auth.token(), call_number, cn.record(), - course_lib, cn.prefix(), cn.suffix(), - cn.label_class() - ).subscribe(res => { - let 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 { - return this.pcrud.update(item); - } - }); - }); - } - -} \ No newline at end of file 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 new file mode 100644 index 0000000000..c8b60cc15d --- /dev/null +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -0,0 +1,100 @@ +import {AuthService} from '@eg/core/auth.service'; +import {EventService} from '@eg/core/event.service'; +import {IdlObject, IdlService} from '@eg/core/idl.service'; +import {NetService} from '@eg/core/net.service'; +import {PcrudService} from '@eg/core/pcrud.service'; + +export class CourseService { + + constructor( + private auth: AuthService, + private evt: EventService, + private idl: IdlService, + private net: NetService, + private pcrud: PcrudService + ) {} + + disassociateMaterials(courses) { + return new Promise((resolve, reject) => { + let course_ids = []; + let course_library_hash = {}; + courses.forEach(course => { + 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(res => { + console.log(res); + }, err => { + reject(err); + }, () => { + resolve(material); + }); + }, err => { + reject(err) + }, () => { + resolve(courses); + }); + }); + } + + 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, course_lib, call_number, updatingVolume) { + return new Promise((resolve, reject) => { + this.pcrud.update(item).subscribe(item_id => { + if (updatingVolume) { + let cn = item.call_number(); + return this.net.request( + 'open-ils.cat', 'open-ils.cat.call_number.find_or_create', + this.auth.token(), call_number, cn.record(), + course_lib, cn.prefix(), cn.suffix(), + cn.label_class() + ).subscribe(res => { + let 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 { + return this.pcrud.update(item); + } + }); + }); + } + +} \ No newline at end of file