]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts
LP1849212: Improvements to course materials admin UI
[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 {ActivatedRoute} from '@angular/router';
3 import {PcrudService} from '@eg/core/pcrud.service';
4 import {IdlObject, IdlService} from '@eg/core/idl.service';
5 import {StringComponent} from '@eg/share/string/string.component';
6 import {ToastService} from '@eg/share/toast/toast.service';
7 import {CourseService} from '@eg/staff/share/course.service';
8 import {CourseAssociateUsersComponent} from './course-associate-users.component';
9 import {CourseAssociateMaterialComponent} from './course-associate-material.component';
10
11 @Component({
12     selector: 'eg-course-page',
13     templateUrl: './course-page.component.html'
14 })
15
16 export class CoursePageComponent implements OnInit {
17
18     currentCourse: IdlObject;
19     courseId: any;
20
21     @ViewChild('courseMaterialDialog', {static: true})
22         private courseMaterialDialog: CourseAssociateMaterialComponent;
23     @ViewChild('courseUserDialog', {static: true})
24         private courseUserDialog: CourseAssociateUsersComponent;
25
26     // Edit Tab
27     @ViewChild('archiveFailedString', { static: true })
28         archiveFailedString: StringComponent;
29     @ViewChild('archiveSuccessString', { static: true })
30         archiveSuccessString: StringComponent;
31
32     // Materials Tab
33
34     constructor(
35         private course: CourseService,
36         private pcrud: PcrudService,
37         private route: ActivatedRoute,
38         private toast: ToastService
39     ) {
40     }
41
42     ngOnInit() {
43         this.courseId = +this.route.snapshot.paramMap.get('id');
44         this.course.getCourses([this.courseId]).then(course => {
45             this.currentCourse = course[0];
46         });
47     }
48
49     // Edit Tab
50     archiveCourse() {
51         this.course.disassociateMaterials([this.currentCourse]).then(res => {
52             this.currentCourse.is_archived('t');
53             this.pcrud.update(this.currentCourse).subscribe(val => {
54                 console.debug('archived: ' + val);
55                 this.archiveSuccessString.current()
56                     .then(str => this.toast.success(str));
57             }, err => {
58                 this.archiveFailedString.current()
59                     .then(str => this.toast.danger(str));
60             });
61         });
62     }
63
64     // Materials Tab
65
66 }