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';
12 selector: 'eg-course-page',
13 templateUrl: './course-page.component.html'
16 export class CoursePageComponent implements OnInit {
18 currentCourse: IdlObject;
20 courseIsArchived: String;
23 @ViewChild('courseMaterialDialog', {static: true})
24 private courseMaterialDialog: CourseAssociateMaterialComponent;
25 @ViewChild('courseUserDialog', {static: true})
26 private courseUserDialog: CourseAssociateUsersComponent;
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;
39 private course: CourseService,
40 private pcrud: PcrudService,
41 private route: ActivatedRoute,
42 private toast: ToastService
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);
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));
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));