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));
});
import {NgModule} from '@angular/core';
import {TreeModule} from '@eg/share/tree/tree.module';
+import {StaffCommonModule} from '@eg/staff/common.module';
import {AdminCommonModule} from '@eg/staff/admin/common.module';
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 '@eg/staff/share/course.service';
@NgModule({
declarations: [
CourseAssociateMaterialComponent
],
imports: [
+ StaffCommonModule,
AdminCommonModule,
CourseReservesRoutingModule,
ItemLocationSelectModule,
exports: [
],
providers: [
- CourseService
]
})
<span *ngIf="!context.holdable(copy)" i18n>No</span>
</ng-template>
+<ng-template #courseTemplate let-copy="row">
+ <div *ngFor="let course of copy._courses">{{course.course_number()}}</div>
+</ng-template>
+
<div class='eg-copies w-100 mt-3'>
<eg-grid #copyGrid [dataSource]="gridDataSource"
[disableSelect]="true" [cellTextGenerator]="cellTextGenerator"
<eg-grid-column i18n-label label="Holdable?" name="holdable"
[cellTemplate]="holdableTemplate" [cellContext]="copyContext">
</eg-grid-column>
+ <eg-grid-column i18n-label label="Course" name="course"
+ [cellTemplate]="courseTemplate" *ngIf="usingCourseModule">
+ </eg-grid-column>
<eg-grid-column i18n-label label="Status" path="copy_status">
</eg-grid-column>
<eg-grid-column i18n-label label="Due Date" path="due_date" datatype="timestamp">
import {GridDataSource, GridColumn, GridCellTextGenerator} from '@eg/share/grid/grid';
import {GridComponent} from '@eg/share/grid/grid.component';
import {BroadcastService} from '@eg/share/util/broadcast.service';
+import {CourseService} from '@eg/staff/share/course.service';
@Component({
selector: 'eg-catalog-copies',
recId: number;
initDone = false;
+ usingCourseModule = false;
gridDataSource: GridDataSource;
copyContext: any; // grid context
@ViewChild('copyGrid', { static: true }) copyGrid: GridComponent;
cellTextGenerator: GridCellTextGenerator;
constructor(
+ private course: CourseService,
private net: NetService,
private org: OrgService,
private staffCat: StaffCatalogService,
ngOnInit() {
this.initDone = true;
+ this.course.isOptedIn().then(res => {
+ this.usingCourseModule = res;
+ });
this.gridDataSource.getRows = (pager: Pager, sort: any[]) => {
// sorting not currently supported
pager.offset,
this.staffCat.prefOrg ? this.staffCat.prefOrg.id() : null
).pipe(map(copy => {
+ this.org.settings('circ.course_materials_opt_in').then(res => {
+ if (res['circ.course_materials_opt_in']) {
+ this.course.getCoursesFromMaterial(copy.id).then(courseList => {
+ copy._courses = courseList;
+ });
+ }
+ });
copy.active_date = copy.active_date || copy.create_date;
return copy;
}));
field="issn" joiner=","></eg-bib-display-field>
</div>
</ng-container>
+ <ng-container *ngIf="has_course">
+ <div i18n>Associated Courses:
+ {{courseNames.join(', ')}}</div>
+ </ng-container>
</div>
</div>
</div>
import {CatalogUrlService} from '@eg/share/catalog/catalog-url.service';
import {StaffCatalogService} from '../catalog.service';
import {BasketService} from '@eg/share/catalog/basket.service';
+import {CourseService} from '@eg/staff/share/course.service';
@Component({
selector: 'eg-catalog-result-record',
searchContext: CatalogSearchContext;
isRecordSelected: boolean;
basketSub: Subscription;
+ has_course: boolean;
+ courseNames: any[] = [];
constructor(
private router: Router,
private cat: CatalogService,
private catUrl: CatalogUrlService,
private staffCat: StaffCatalogService,
- private basket: BasketService
+ private basket: BasketService,
+ private course: CourseService
) {}
ngOnInit() {
this.searchContext = this.staffCat.searchContext;
+ this.loadCourseInformation(this.summary.id)
this.isRecordSelected = this.basket.hasRecordId(this.summary.id);
// Watch for basket changes caused by other components
this.basketSub.unsubscribe();
}
+ loadCourseInformation(recordId) {
+ console.log("Entering loadCourseInformation");
+ this.course.isOptedIn().then(res => {
+ if (res) {
+ this.course.fetchCopiesInCourseFromRecord(recordId).then(course_list => {
+ Object.keys(course_list).forEach(key => {
+ this.courseNames.push(course_list[key].name() +
+ "(" + course_list[key].course_number() + ")");
+ });
+ this.has_course = true;
+ });
+ } else {
+ this.has_course = false;
+ }
+ });
+ }
+
orgName(orgId: number): string {
return this.org.get(orgId).shortname();
}
import {NotBeforeMomentValidatorDirective} from '@eg/share/validators/not_before_moment_validator.directive';
import {PatronBarcodeValidatorDirective} from '@eg/share/validators/patron_barcode_validator.directive';
import {BroadcastService} from '@eg/share/util/broadcast.service';
+import {CourseService} from './share/course.service'
/**
* Imports the EG common modules and adds modules common to all staff UI's.
AccessKeyService,
AudioService,
BroadcastService
+ CourseService
]
};
}
<div class="flex-1">{{summary.record.edit_date() | date:'short'}}</div>
</div>
</li>
+ <ng-container *ngIf="expand && has_course">
+ <li class="list-group-item">
+ <div class="d-flex">
+ <div class="flex-1 font-weight-bold" i18n>Associated Courses</div>
+ </div>
+ </li>
+ <li class="list-group-item" *ngFor="let course of courses">
+ <div class="d-flex">
+ <div class="flex-1 font-weight-bold" i18n>Course Name:</div>
+ <div class="flex-3">{{course.name()}}</div>
+ <div class="flex-1 font-weight-bold" i18n>Course Number:</div>
+ <div class="flex-1">{{course.course_number()}}</div>
+ <div class="flex-1 font-weight-bold" i18n>Section Number:</div>
+ <div class="flex-1">{{course.section_number()}}</div>
+ <div class="flex-1 font-weight-bold" i18n>Owning Library:</div>
+ <div class="flex-1">{{this.org.get(course.owning_lib()).shortname()}}</div>
+ </div>
+ </li>
+ </ng-container>
</ul>
</div>
</div><!-- col -->
import {Component, OnInit, Input} from '@angular/core';
import {OrgService} from '@eg/core/org.service';
+import {CourseService} from '@eg/staff/share/course.service';
import {BibRecordService, BibRecordSummary
} from '@eg/share/catalog/bib-record.service';
import {ServerStoreService} from '@eg/core/server-store.service';
export class BibSummaryComponent implements OnInit {
initDone = false;
+ has_course = false;
+ courses: any;
// True / false if the display is vertically expanded
private _exp: boolean;
this.summary = s;
if (this.initDone && this.summary) {
this.summary.getBibCallNumber();
+ this.loadCourseInformation(this.summary.record.id());
}
}
private bib: BibRecordService,
private org: OrgService,
private store: ServerStoreService,
- private cat: CatalogService
+ private cat: CatalogService,
+ private course: CourseService
) {}
ngOnInit() {
if (this.summary) {
this.summary.getBibCallNumber();
+ this.loadCourseInformation(this.summary.record.id());
} else {
if (this.recordId) {
this.loadSummary();
}
loadSummary(): void {
+ this.loadCourseInformation(this.recordId);
this.bib.getBibSummary(this.recordId).toPromise()
.then(summary => {
summary.getBibCallNumber();
});
}
+ loadCourseInformation(record_id) {
+ this.org.settings('circ.course_materials_opt_in').then(setting => {
+ if (setting['circ.course_materials_opt_in']) {
+ this.course.fetchCopiesInCourseFromRecord(record_id).then(course_list => {
+ this.courses = course_list;
+ this.has_course = true;
+ });
+ } else {
+ this.has_course = false;
+ }
+ });
+ }
+
orgName(orgId: number): string {
if (orgId) {
return this.org.get(orgId).shortname();
+import {Injectable} from '@angular/core';
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 {OrgService} from '@eg/core/org.service';
import {PcrudService} from '@eg/core/pcrud.service';
+@Injectable()
export class CourseService {
constructor(
private evt: EventService,
private idl: IdlService,
private net: NetService,
+ private org: OrgService,
private pcrud: PcrudService
) {}
+ isOptedIn(): Promise<any> {
+ return new Promise((resolve, reject) => {
+ this.org.settings('circ.course_materials_opt_in').then(res => {
+ resolve(res['circ.course_materials_opt_in']);
+ });
+ });
+ }
+ getCourses(course_ids?: Number[]): Promise<IdlObject[]> {
+ if (!course_ids) {
+ return this.pcrud.retrieveAll('acmc',
+ {}, {atomic: true}).toPromise();
+ } else {
+ return this.pcrud.search('acmc', {id: course_ids},
+ {}, {atomic: true}).toPromise();
+ }
+ }
+
+ getCoursesFromMaterial(copy_id): Promise<any> {
+ let id_list = [];
+ return new Promise((resolve, reject) => {
+
+ return this.pcrud.search('acmcm', {item: copy_id})
+ .subscribe(materials => {
+ if (materials) {
+ id_list.push(materials.course());
+ }
+ }, err => {
+ console.log(err);
+ reject(err);
+ }, () => {
+ if (id_list.length) {
+ return this.getCourses(id_list).then(courses => {
+ resolve(courses);
+ });
+
+ }
+ });
+ });
+ }
+
+ fetchCopiesInCourseFromRecord(record_id) {
+ let cp_list = [];
+ let course_list = [];
+ return new Promise((resolve, reject) => {
+ this.net.request(
+ 'open-ils.cat',
+ 'open-ils.cat.asset.copy_tree.global.retrieve',
+ this.auth.token(), record_id
+ ).subscribe(copy_tree => {
+ copy_tree.forEach(cn => {
+ cn.copies().forEach(cp => {
+ cp_list.push(cp.id());
+ });
+ });
+ }, err => reject(err),
+ () => {
+ resolve(this.getCoursesFromMaterial(cp_list));
+ });
+ });
+ }
+
+ // 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 = [];