1 import {Component, Input, ViewChild, OnInit, TemplateRef} from '@angular/core';
\r
2 import {Observable, Observer, of} from 'rxjs';
\r
3 import {DialogComponent} from '@eg/share/dialog/dialog.component';
\r
4 import {AuthService} from '@eg/core/auth.service';
\r
5 import {NetService} from '@eg/core/net.service';
\r
6 import {EventService} from '@eg/core/event.service';
\r
7 import {OrgService} from '@eg/core/org.service';
\r
8 import {PcrudService} from '@eg/core/pcrud.service';
\r
9 import {Pager} from '@eg/share/util/pager';
\r
10 import {NgbModal, NgbModalOptions} from '@ng-bootstrap/ng-bootstrap';
\r
11 import {GridDataSource} from '@eg/share/grid/grid';
\r
12 import {GridComponent} from '@eg/share/grid/grid.component';
\r
13 import {IdlObject, IdlService} from '@eg/core/idl.service';
\r
14 import {StringComponent} from '@eg/share/string/string.component';
\r
15 import {ToastService} from '@eg/share/toast/toast.service';
\r
16 import {CourseService} from '@eg/staff/share/course.service';
\r
19 selector: 'eg-course-associate-users-dialog',
\r
20 templateUrl: './course-associate-users.component.html'
\r
23 export class CourseAssociateUsersComponent extends DialogComponent {
\r
25 @ViewChild('usersGrid', {static: true}) usersGrid: GridComponent;
\r
26 @ViewChild('deleteFailedString', { static: true }) deleteFailedString: StringComponent;
\r
27 @ViewChild('deleteSuccessString', { static: true }) deleteSuccessString: StringComponent;
\r
28 @ViewChild('successString', { static: true }) successString: StringComponent;
\r
29 @ViewChild('failedString', { static: true }) failedString: StringComponent;
\r
30 @ViewChild('differentLibraryString', { static: true }) differentLibraryString: StringComponent;
\r
31 @Input() table_name = "Course Users";
\r
32 @Input() userRoleInput: String;
\r
34 idl_class = "acmcu";
\r
36 currentCourse: IdlObject;
\r
38 gridDataSource: GridDataSource;
\r
41 private auth: AuthService,
\r
42 private idl: IdlService,
\r
43 private net: NetService,
\r
44 private pcrud: PcrudService,
\r
45 private org: OrgService,
\r
46 private evt: EventService,
\r
47 private modal: NgbModal,
\r
48 private toast: ToastService,
\r
49 private courseSvc: CourseService
\r
52 this.gridDataSource = new GridDataSource();
\r
59 * Takes the user id and creates a course user based around it.
\r
60 * @param user_input The inputted user Id.
\r
62 associateUsers(user_input) {
\r
64 let user = this.idl.create('acmcu');
\r
65 user.course(this.currentCourse.id());
\r
66 user.usr(this.new_usr);
\r
67 user.usr_role(user_input);
\r
68 this.pcrud.create(user).subscribe(
\r
70 console.debug('created: ' + val);
\r
71 this.successString.current().then(str => this.toast.success(str));
\r
73 this.failedString.current().then(str => this.toast.danger(str));
\r
79 * Delete a user based on the id selected from the grid.
\r
82 deleteSelected(users) {
\r
84 users.forEach(user => {
\r
85 this.gridDataSource.data.splice(this.gridDataSource.data.indexOf(user, 0), 1);
\r
86 user_ids.push(user.id())
\r
88 this.pcrud.remove(users).subscribe(user => {
\r
89 this.pcrud.autoApply(user).subscribe(
\r
91 console.debug('deleted: ' + val);
\r
92 this.deleteSuccessString.current().then(str => this.toast.success(str));
\r
95 this.deleteFailedString.current()
\r
96 .then(str => this.toast.danger(str));
\r