]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts
LP 2061136 follow-up: ng lint --fix
[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     courseIsArchived: String;
21
22     // Materials Tab
23     @ViewChild('courseMaterialDialog', {static: true})
24     private courseMaterialDialog: CourseAssociateMaterialComponent;
25     @ViewChild('courseUserDialog', {static: true})
26     private courseUserDialog: CourseAssociateUsersComponent;
27
28     // Edit Tab
29     @ViewChild('archiveFailedString', { static: true })
30         archiveFailedString: StringComponent;
31     @ViewChild('archiveSuccessString', { static: true })
32         archiveSuccessString: StringComponent;
33     @ViewChild('unarchiveFailedString', { static: true })
34         unarchiveFailedString: StringComponent;
35     @ViewChild('unarchiveSuccessString', { static: true })
36         unarchiveSuccessString: StringComponent;
37
38     constructor(
39         private course: CourseService,
40         private pcrud: PcrudService,
41         private route: ActivatedRoute,
42         private toast: ToastService
43     ) {
44     }
45
46     ngOnInit() {
47         this.courseId = +this.route.snapshot.paramMap.get('id');
48         this.course.getCourses([this.courseId]).then(course => {
49             this.currentCourse = course[0];
50             this.courseIsArchived = course[0].is_archived();
51             console.log(this.courseIsArchived);
52         });
53     }
54
55     // Edit Tab
56     archiveCourse() {
57         this.course.disassociateMaterials([this.currentCourse]).then(res => {
58             this.currentCourse.is_archived('t');
59             this.pcrud.update(this.currentCourse).subscribe(val => {
60                 this.courseIsArchived = 't';
61                 console.debug('archived: ' + val);
62                 this.archiveSuccessString.current()
63                     .then(str => this.toast.success(str));
64             }, (err: unknown) => {
65                 this.archiveFailedString.current()
66                     .then(str => this.toast.danger(str));
67             });
68         });
69     }
70
71     unarchiveCourse() {
72         this.course.disassociateMaterials([this.currentCourse]).then(res => {
73             this.currentCourse.is_archived('f');
74             this.pcrud.update(this.currentCourse).subscribe(val => {
75                 this.courseIsArchived = 'f';
76                 console.debug('archived: ' + val);
77                 this.course.removeNonPublicUsers(this.currentCourse.id());
78                 this.unarchiveSuccessString.current()
79                     .then(str => this.toast.success(str));
80             }, (err: unknown) => {
81                 this.unarchiveFailedString.current()
82                     .then(str => this.toast.danger(str));
83             });
84         });
85     }
86
87     // Materials Tab
88
89 }