From bc4e3682e9cdd7b7fea358b0cb18805079002e7c Mon Sep 17 00:00:00 2001 From: Kyle Huckins Date: Tue, 10 Dec 2019 19:03:17 +0000 Subject: [PATCH] Angular Course Page Associate Users Tab - Apply Course Users functionality to Angular Course Page Admin UI. Signed-off-by: Kyle Huckins Changes to be committed: modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.html modified: Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts modified: Open-ILS/src/eg2/src/app/staff/share/course.service.ts --- .../course-reserves/course-page.component.html | 57 +++++++++++---- .../local/course-reserves/course-page.component.ts | 85 +++++++++++++++++++++- .../src/eg2/src/app/staff/share/course.service.ts | 37 ++++++++++ 3 files changed, 165 insertions(+), 14 deletions(-) diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.html b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.html index 0361526439..1b0f6345b3 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.html +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.html @@ -174,11 +174,11 @@
- + - + @@ -219,20 +219,18 @@
-
+
Patron Barcode
- + [disabled]="currentCourse && currentCourse.is_archived() == 't'" + (keyup.enter)="associateUser(userBarcode)" />
-
-
-
+
Role @@ -245,18 +243,47 @@
-
- +
+
+
+
+ Is Public Role? +
+
+
+
+ +
+
+
+
+
- + + + + + + + + + + + + + + +
@@ -269,4 +296,8 @@ - \ No newline at end of file + + + + + diff --git a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts index 37654963e7..0d25c22ce3 100644 --- a/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts +++ b/Open-ILS/src/eg2/src/app/staff/admin/local/course-reserves/course-page.component.ts @@ -59,19 +59,33 @@ export class CoursePageComponent implements OnInit { @Input() isModifyingLocation: Boolean; // Users Tab + users: any[] = []; + @ViewChild('usersGrid', {static: true}) usersGrid: GridComponent; + @ViewChild('userDeleteFailedString', { static: true }) + userDeleteFailedString: StringComponent; + @ViewChild('userDeleteSuccessString', { static: true }) + userDeleteSuccessString: StringComponent; + @ViewChild('userAddSuccessString', { static: true }) + userAddSuccessString: StringComponent; + @ViewChild('userAddFailedString', { static: true }) + userAddFailedString: StringComponent; + usersDataSource: GridDataSource; @Input() userBarcode: String; @Input() userRoleInput: String; + @Input() isPublicRole: Boolean; constructor( private auth: AuthService, private course: CourseService, private event: EventService, private idl: IdlService, + private net: NetService, private org: OrgService, private pcrud: PcrudService, private route: ActivatedRoute, private toast: ToastService ) { this.materialsDataSource = new GridDataSource(); + this.usersDataSource = new GridDataSource(); } ngOnInit() { @@ -79,6 +93,9 @@ export class CoursePageComponent implements OnInit { this.course.getCourses([this.courseId]).then(course => { this.currentCourse = course[0]; }); + this.usersDataSource.getRows = (pager: Pager, sort: any[]) => { + return this.loadUsersGrid(pager); + } this.materialsDataSource.getRows = (pager: Pager, sort: any[]) => { return this.loadMaterialsGrid(pager); } @@ -159,7 +176,7 @@ export class CoursePageComponent implements OnInit { } } - deleteSelected(items) { + deleteSelectedMaterials(items) { let item_ids = []; items.forEach(item => { this.materialsDataSource.data.splice(this.materialsDataSource.data.indexOf(item, 0), 1); @@ -180,4 +197,70 @@ export class CoursePageComponent implements OnInit { ); }); } + + // Users Tab + loadUsersGrid(pager: Pager): Observable { + return new Observable(observer => { + this.course.getUsers(this.courseId).then(users => { + users.forEach(user => { + console.log(user); + this.course.fleshUser(user.usr(), user.usr_role(), user.is_public()).then(fleshed_user => { + this.usersDataSource.data.push(fleshed_user); + }); + }); + }); + observer.complete(); + }); + } + + associateUser(barcode) { + if (barcode) { + let args = { + currentCourse: this.currentCourse, + barcode: barcode, + role: this.userRoleInput, + is_public: this.isPublicRole + } + + this.userBarcode = null; + + this.net.request( + 'open-ils.actor', + 'open-ils.actor.user.retrieve_id_by_barcode_or_username', + this.auth.token(), barcode + ).subscribe(patron => { + let associatedUser = this.course.associateUsers(patron, args).then(res => { + this.course.fleshUser( + patron, args.role, args.is_public + ).then(fleshed_user => { + this.usersDataSource.data.push(fleshed_user); + this.userAddSuccessString.current().then(str => this.toast.success(str)); + }); + }, err => { + this.userAddFailedString.current().then(str => this.toast.danger(str)); + }); + }); + } + } + + deleteSelectedUsers(users) { + let user_ids = []; + users.forEach(user => { + this.usersDataSource.data.splice(this.usersDataSource.data.indexOf(user, 0), 1); + user_ids.push(user.id()) + }); + this.pcrud.search('acmcu', {course: this.courseId, usr: user_ids}).subscribe(user => { + user.isdeleted(true); + this.pcrud.autoApply(user).subscribe( + val => { + console.debug('deleted: ' + val); + this.userDeleteSuccessString.current().then(str => this.toast.success(str)); + }, + err => { + this.userDeleteFailedString.current() + .then(str => this.toast.danger(str)); + } + ); + }); + } } \ No newline at end of file diff --git a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts index de946c42d9..798ea9bf20 100644 --- a/Open-ILS/src/eg2/src/app/staff/share/course.service.ts +++ b/Open-ILS/src/eg2/src/app/staff/share/course.service.ts @@ -45,6 +45,16 @@ export class CourseService { } } + getUsers(course_ids?: Number[]): Promise { + if (!course_ids) { + return this.pcrud.retrieveAll('acmcu', + {}, {atomic: true}).toPromise(); + } else { + return this.pcrud.search('acmcu', {course: course_ids}, + {}, {atomic: true}).toPromise(); + } + } + fleshMaterial(itemId, relationship?): Promise { return new Promise((resolve, reject) => { let item = this.idl.create('acp'); @@ -66,6 +76,23 @@ export class CourseService { }); } + fleshUser(patron_id, role?, is_public?): Promise { + return new Promise((resolve, reject) => { + let user = this.idl.create('au'); + this.net.request( + 'open-ils.actor', + 'open-ils.actor.user.fleshed.retrieve', + this.auth.token(), patron_id + ).subscribe(patron => { + user = patron; + if (role) user._role = role + if (is_public) user._is_public = is_public + }, err => { + reject(err); + }, () => resolve(user)); + }); + } + getCoursesFromMaterial(copy_id): Promise { let id_list = []; return new Promise((resolve, reject) => { @@ -145,6 +172,16 @@ export class CourseService { return response; } + associateUsers(patron_id, args) { + console.log(args); + let new_user = this.idl.create('acmcu'); + if (args.is_public) new_user.is_public(args.is_public); + if (args.role) new_user.usr_role(args.role); + new_user.course(args.currentCourse.id()); + new_user.usr(patron_id); + return this.pcrud.create(new_user).toPromise() + } + disassociateMaterials(courses) { return new Promise((resolve, reject) => { let course_ids = []; -- 2.11.0