1 import {Component, Input, ViewChild, OnInit, TemplateRef} from '@angular/core';
2 import {Router, ActivatedRoute} from '@angular/router';
3 import {Observable, Observer, of} from 'rxjs';
4 import {DialogComponent} from '@eg/share/dialog/dialog.component';
5 import {AuthService} from '@eg/core/auth.service';
6 import {NetService} from '@eg/core/net.service';
7 import {EventService} from '@eg/core/event.service';
8 import {OrgService} from '@eg/core/org.service';
9 import {PcrudService} from '@eg/core/pcrud.service';
10 import {Pager} from '@eg/share/util/pager';
11 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
12 import {GridDataSource} from '@eg/share/grid/grid';
13 import {GridComponent} from '@eg/share/grid/grid.component';
14 import {IdlObject, IdlService} from '@eg/core/idl.service';
15 import {StringComponent} from '@eg/share/string/string.component';
16 import {StaffBannerComponent} from '@eg/staff/share/staff-banner.component';
17 import {ToastService} from '@eg/share/toast/toast.service';
18 import {CourseService} from '@eg/staff/share/course.service';
21 selector: 'eg-course-page',
22 templateUrl: './course-page.component.html'
25 export class CoursePageComponent implements OnInit {
27 currentCourse: IdlObject;
31 @ViewChild('archiveFailedString', { static: true })
32 archiveFailedString: StringComponent;
33 @ViewChild('archiveSuccessString', { static: true })
34 archiveSuccessString: StringComponent;
37 materials: any[] = [];
38 @ViewChild('materialsGrid', {static: true}) materialsGrid: GridComponent;
39 @ViewChild('materialDeleteFailedString', { static: true })
40 materialDeleteFailedString: StringComponent;
41 @ViewChild('materialDeleteSuccessString', { static: true })
42 materialDeleteSuccessString: StringComponent;
43 @ViewChild('materialAddSuccessString', { static: true })
44 materialAddSuccessString: StringComponent;
45 @ViewChild('materialAddFailedString', { static: true })
46 materialAddFailedString: StringComponent;
47 @ViewChild('materialAddDifferentLibraryString', { static: true })
48 materialAddDifferentLibraryString: StringComponent;
49 materialsDataSource: GridDataSource;
50 @Input() barcodeInput: String;
51 @Input() relationshipInput: String;
52 @Input() tempCallNumber: String;
53 @Input() tempStatus: Number;
54 @Input() tempLocation: Number;
55 @Input() tempCircMod: String;
56 @Input() isModifyingStatus: Boolean;
57 @Input() isModifyingCircMod: Boolean;
58 @Input() isModifyingCallNumber: Boolean;
59 @Input() isModifyingLocation: Boolean;
62 @Input() userBarcode: String;
63 @Input() userRoleInput: String;
65 private auth: AuthService,
66 private course: CourseService,
67 private event: EventService,
68 private idl: IdlService,
69 private org: OrgService,
70 private pcrud: PcrudService,
71 private route: ActivatedRoute,
72 private toast: ToastService
74 this.materialsDataSource = new GridDataSource();
78 this.courseId = parseInt(this.route.snapshot.paramMap.get('id'));
79 this.course.getCourses([this.courseId]).then(course => {
80 this.currentCourse = course[0];
82 this.materialsDataSource.getRows = (pager: Pager, sort: any[]) => {
83 return this.loadMaterialsGrid(pager);
89 this.course.disassociateMaterials([this.currentCourse]).then(res => {
90 this.currentCourse.is_archived('t');
91 this.pcrud.update(this.currentCourse).subscribe(val => {
92 console.debug('archived: ' + val);
93 this.archiveSuccessString.current()
94 .then(str => this.toast.success(str));
96 this.archiveFailedString.current()
97 .then(str => this.toast.danger(str));
103 loadMaterialsGrid(pager: Pager): Observable<any> {
104 return new Observable<any>(observer => {
105 this.course.getMaterials(this.courseId).then(materials => {
106 materials.forEach(material => {
107 this.course.fleshMaterial(material.item(), material.relationship()).then(fleshed_material => {
108 this.materialsDataSource.data.push(fleshed_material);
116 associateItem(barcode, relationship) {
120 relationship: relationship,
121 isModifyingCallNumber: this.isModifyingCallNumber,
122 isModifyingCircMod: this.isModifyingCircMod,
123 isModifyingLocation: this.isModifyingLocation,
124 isModifyingStatus: this.isModifyingStatus,
125 tempCircMod: this.tempCircMod,
126 tempLocation: this.tempLocation,
127 tempStatus: this.tempStatus,
128 currentCourse: this.currentCourse
130 this.barcodeInput = null;
132 this.pcrud.search('acp', {barcode: args.barcode}, {
133 flesh: 3, flesh_fields: {acp: ['call_number']}
134 }).subscribe(item => {
135 let associatedMaterial = this.course.associateMaterials(item, args);
136 associatedMaterial.material.then(res => {
137 item = associatedMaterial.item;
138 let new_cn = item.call_number().label();
139 if (this.tempCallNumber) new_cn = this.tempCallNumber;
140 this.course.updateItem(item, this.currentCourse.owning_lib(),
141 new_cn, args.isModifyingCallNumber
143 this.course.fleshMaterial(item.id(), args.relationship).then(fleshed_material => {
144 this.materialsDataSource.data.push(fleshed_material);
146 if (item.circ_lib() != this.currentCourse.owning_lib()) {
147 this.materialAddDifferentLibraryString.current()
148 .then(str => this.toast.warning(str));
150 this.materialAddSuccessString.current()
151 .then(str => this.toast.success(str));
155 this.materialAddFailedString.current()
156 .then(str => this.toast.danger(str));
162 deleteSelected(items) {
164 items.forEach(item => {
165 this.materialsDataSource.data.splice(this.materialsDataSource.data.indexOf(item, 0), 1);
166 item_ids.push(item.id())
168 this.pcrud.search('acmcm', {course: this.courseId, item: item_ids}).subscribe(material => {
169 material.isdeleted(true);
170 this.pcrud.autoApply(material).subscribe(
172 this.course.resetItemFields(material, this.currentCourse.owning_lib());
173 console.debug('deleted: ' + val);
174 this.materialDeleteSuccessString.current().then(str => this.toast.success(str));
177 this.materialDeleteFailedString.current()
178 .then(str => this.toast.danger(str));