]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts
LP1906058: Course-term map interface only allow reasonable mappings
[Evergreen.git] / Open-ILS / src / eg2 / src / app / staff / admin / local / course-reserves / course-page.component.ts
1 import {Component, ViewChild, OnInit} from '@angular/core';
2 import {ActivatedRoute} from '@angular/router';
3 import {PcrudService} from '@eg/core/pcrud.service';
4 import {IdlObject} 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     // Materials Tab
22     @ViewChild('courseMaterialDialog', {static: true})
23         private courseMaterialDialog: CourseAssociateMaterialComponent;
24     @ViewChild('courseUserDialog', {static: true})
25         private courseUserDialog: CourseAssociateUsersComponent;
26
27     // Edit Tab
28     @ViewChild('archiveFailedString', { static: true })
29         archiveFailedString: StringComponent;
30     @ViewChild('archiveSuccessString', { static: true })
31         archiveSuccessString: StringComponent;
32
33     constructor(
34         private course: CourseService,
35         private pcrud: PcrudService,
36         private route: ActivatedRoute,
37         private toast: ToastService
38     ) {
39     }
40
41     ngOnInit() {
42         this.courseId = +this.route.snapshot.paramMap.get('id');
43         this.course.getCourses([this.courseId]).then(course => {
44             this.currentCourse = course[0];
45         });
46     }
47
48     // Edit Tab
49     archiveCourse() {
50         this.course.disassociateMaterials([this.currentCourse]).then(res => {
51             this.currentCourse.is_archived('t');
52             this.pcrud.update(this.currentCourse).subscribe(val => {
53                 console.debug('archived: ' + val);
54                 this.archiveSuccessString.current()
55                     .then(str => this.toast.success(str));
56             }, err => {
57                 this.archiveFailedString.current()
58                     .then(str => this.toast.danger(str));
59             });
60         });
61     }
62
63     // Materials Tab
64
65 }