]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts
LP1849212: Angular Course Page improvements, OPAC course search
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / local / course-reserves / course-page.component.ts
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';
19 import {CourseAssociateUsersComponent} from './course-associate-users.component';
20 import {CourseAssociateMaterialComponent} from './course-associate-material.component';
21
22 @Component({
23     selector: 'eg-course-page',
24     templateUrl: './course-page.component.html'
25 })
26
27 export class CoursePageComponent implements OnInit {
28
29     currentCourse: IdlObject;
30     courseId: any;
31
32     @ViewChild('courseMaterialDialog', {static: true})
33         private courseMaterialDialog: CourseAssociateMaterialComponent;
34     @ViewChild('courseUserDialog', {static: true})
35         private courseUserDialog: CourseAssociateUsersComponent;
36     
37     // Edit Tab
38     @ViewChild('archiveFailedString', { static: true })
39         archiveFailedString: StringComponent;
40     @ViewChild('archiveSuccessString', { static: true })
41         archiveSuccessString: StringComponent;
42
43     // Materials Tab
44
45     constructor(
46         private auth: AuthService,
47         private course: CourseService,
48         private event: EventService,
49         private idl: IdlService,
50         private net: NetService,
51         private org: OrgService,
52         private pcrud: PcrudService,
53         private route: ActivatedRoute,
54         private toast: ToastService
55     ) {
56     }
57
58     ngOnInit() {
59         this.courseId = parseInt(this.route.snapshot.paramMap.get('id'));
60         this.course.getCourses([this.courseId]).then(course => {
61             this.currentCourse = course[0];
62         });
63     }
64
65     // Edit Tab
66     archiveCourse() {
67         this.course.disassociateMaterials([this.currentCourse]).then(res => {
68             this.currentCourse.is_archived('t');
69             this.pcrud.update(this.currentCourse).subscribe(val => {
70                 console.debug('archived: ' + val);
71                 this.archiveSuccessString.current()
72                     .then(str => this.toast.success(str));
73             }, err => {
74                 this.archiveFailedString.current()
75                     .then(str => this.toast.danger(str));
76             });
77         });
78     }
79
80     // Materials Tab
81     
82 }