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, IdlService} from '@eg/core/idl.service';
5 import {GridDataSource} from '@eg/share/grid/grid';
6 import {StringComponent} from '@eg/share/string/string.component';
7 import {ToastService} from '@eg/share/toast/toast.service';
8 import {CourseService} from '@eg/staff/share/course.service';
9 import {CourseAssociateUsersComponent} from './course-associate-users.component';
10 import {CourseAssociateMaterialComponent} from './course-associate-material.component';
11 import {Pager} from '@eg/share/util/pager';
14 selector: 'eg-course-page',
15 templateUrl: './course-page.component.html'
18 export class CoursePageComponent implements OnInit {
20 currentCourse: IdlObject;
24 @ViewChild('courseMaterialDialog', {static: true})
25 private courseMaterialDialog: CourseAssociateMaterialComponent;
26 @ViewChild('courseUserDialog', {static: true})
27 private courseUserDialog: CourseAssociateUsersComponent;
30 @ViewChild('archiveFailedString', { static: true })
31 archiveFailedString: StringComponent;
32 @ViewChild('archiveSuccessString', { static: true })
33 archiveSuccessString: StringComponent;
36 termsDataSource: GridDataSource = new GridDataSource();
37 defaultNewAcmtcm: IdlObject;
40 private course: CourseService,
41 private idl: IdlService,
42 private pcrud: PcrudService,
43 private route: ActivatedRoute,
44 private toast: ToastService
49 this.courseId = +this.route.snapshot.paramMap.get('id');
50 this.course.getCourses([this.courseId]).then(course => {
51 this.currentCourse = course[0];
54 this.defaultNewAcmtcm = this.idl.create('acmtcm');
55 this.defaultNewAcmtcm.course(this.courseId);
57 this.termsDataSource.getRows = (pager: Pager, sort: any[]) => {
58 const orderBy: any = {};
60 orderBy.acmtcm = sort[0].name + ' ' + sort[0].dir;
68 return this.pcrud.search('acmtcm', {course: this.courseId},
69 searchOps, {fleshSelectors: true});
75 this.course.disassociateMaterials([this.currentCourse]).then(res => {
76 this.currentCourse.is_archived('t');
77 this.pcrud.update(this.currentCourse).subscribe(val => {
78 console.debug('archived: ' + val);
79 this.archiveSuccessString.current()
80 .then(str => this.toast.success(str));
82 this.archiveFailedString.current()
83 .then(str => this.toast.danger(str));