From 0989e03fdfde9f2ab5da338f47de34d4f2ed1bd0 Mon Sep 17 00:00:00 2001 From: Minh Tho DUONG Date: Tue, 14 May 2024 16:26:16 +1000 Subject: [PATCH] refactor: migrate the unit-student-enrolment-modal --- src/app/doubtfire-angular.module.ts | 2 + src/app/doubtfire-angularjs.module.ts | 3 +- src/app/units/modals/modals.coffee | 1 - ...nit-student-enrolment-modal.component.html | 31 +++++++++ .../unit-student-enrolment-modal.component.ts | 64 +++++++++++++++++++ .../unit-student-enrolment-modal.service.ts | 20 ++++++ 6 files changed, 119 insertions(+), 2 deletions(-) create mode 100644 src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.html create mode 100644 src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.ts create mode 100644 src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service.ts diff --git a/src/app/doubtfire-angular.module.ts b/src/app/doubtfire-angular.module.ts index 5f250b661..23e7f8d25 100644 --- a/src/app/doubtfire-angular.module.ts +++ b/src/app/doubtfire-angular.module.ts @@ -95,6 +95,7 @@ import {ExtensionCommentComponent} from './tasks/task-comments-viewer/extension- import {CampusListComponent} from './admin/institution-settings/campuses/campus-list/campus-list.component'; import {ExtensionModalComponent} from './common/modals/extension-modal/extension-modal.component'; import {CalendarModalComponent} from './common/modals/calendar-modal/calendar-modal.component'; +import {UnitStudentEnrolmentModalComponent} from './units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component'; import {MatRadioModule} from '@angular/material/radio'; import {MatButtonToggleModule} from '@angular/material/button-toggle'; import {MAT_DATE_LOCALE, MatOptionModule} from '@angular/material/core'; @@ -251,6 +252,7 @@ import {TasksViewerComponent} from './units/states/tasks/tasks-viewer/tasks-view OverseerImageListComponent, ExtensionModalComponent, CalendarModalComponent, + UnitStudentEnrolmentModalComponent, InstitutionSettingsComponent, HomeComponent, CommentBubbleActionComponent, diff --git a/src/app/doubtfire-angularjs.module.ts b/src/app/doubtfire-angularjs.module.ts index c102584ea..a791b82e1 100644 --- a/src/app/doubtfire-angularjs.module.ts +++ b/src/app/doubtfire-angularjs.module.ts @@ -92,7 +92,6 @@ import 'build/src/app/groups/groups.js'; import 'build/src/app/groups/group-member-contribution-assigner/group-member-contribution-assigner.js'; import 'build/src/app/groups/group-member-list/group-member-list.js'; import 'build/src/app/groups/group-set-selector/group-set-selector.js'; -import 'build/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.js'; import 'build/src/app/units/modals/unit-ilo-edit-modal/unit-ilo-edit-modal.js'; import 'build/src/app/units/modals/modals.js'; import 'build/src/app/units/units.js'; @@ -157,6 +156,7 @@ import {ExtensionCommentComponent} from './tasks/task-comments-viewer/extension- import {TaskAssessmentCommentComponent} from './tasks/task-comments-viewer/task-assessment-comment/task-assessment-comment.component'; import {ExtensionModalService} from './common/modals/extension-modal/extension-modal.service'; import {CalendarModalService} from './common/modals/calendar-modal/calendar-modal.service'; +import {UnitStudentEnrolmentModalService} from './units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service'; import {CampusListComponent} from './admin/institution-settings/campuses/campus-list/campus-list.component'; import {ActivityTypeListComponent} from './admin/institution-settings/activity-type-list/activity-type-list.component'; import {InstitutionSettingsComponent} from './admin/institution-settings/institution-settings.component'; @@ -250,6 +250,7 @@ DoubtfireAngularJSModule.factory('DoubtfireConstants', downgradeInjectable(Doubt DoubtfireAngularJSModule.factory('ExtensionModal', downgradeInjectable(ExtensionModalService)); DoubtfireAngularJSModule.factory('Marked', downgradeInjectable(MarkedPipe)); DoubtfireAngularJSModule.factory('CalendarModal', downgradeInjectable(CalendarModalService)); +DoubtfireAngularJSModule.factory('UnitStudentEnrolmentModal', downgradeInjectable(UnitStudentEnrolmentModalService)); DoubtfireAngularJSModule.factory('TaskCommentService', downgradeInjectable(TaskCommentService)); DoubtfireAngularJSModule.factory('alertService', downgradeInjectable(AlertService)); DoubtfireAngularJSModule.factory('tutorialService', downgradeInjectable(TutorialService)); diff --git a/src/app/units/modals/modals.coffee b/src/app/units/modals/modals.coffee index fb091e725..9b2b2c391 100644 --- a/src/app/units/modals/modals.coffee +++ b/src/app/units/modals/modals.coffee @@ -1,4 +1,3 @@ angular.module('doubtfire.units.modals', [ 'doubtfire.units.modals.unit-ilo-edit-modal' - 'doubtfire.units.modals.unit-student-enrolment-modal' ]) diff --git a/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.html b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.html new file mode 100644 index 000000000..e00d34297 --- /dev/null +++ b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.html @@ -0,0 +1,31 @@ + +
+ + + +
diff --git a/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.ts b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.ts new file mode 100644 index 000000000..1c8ec1521 --- /dev/null +++ b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.ts @@ -0,0 +1,64 @@ +/* eslint-disable @typescript-eslint/no-unused-vars */ +/* eslint-disable @angular-eslint/use-lifecycle-interface */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable @angular-eslint/component-selector */ +/* eslint-disable prettier/prettier */ +import { Component, OnInit, Input, Inject} from '@angular/core'; +import { AlertService } from 'src/app/common/services/alert.service'; +import { MatDialogRef } from '@angular/material/dialog'; +import { User } from 'src/app/api/models/user/user'; +import { Unit } from 'src/app/api/models/unit'; +import { Campus, CampusService } from 'src/app/api/models/doubtfire-model'; +import { ProjectService } from 'src/app/api/services/project.service'; + +@Component({ + selector: 'unit-student-enrolment-modal', + templateUrl: 'unit-student-enrolment-modal.component.html', +}) +export class UnitStudentEnrolmentModalComponent { + constructor( + @Inject(AlertService) private alertService: any, + public dialogRef: MatDialogRef, + private campusService: CampusService, + private newProjectService: ProjectService, + ) {} + + @Input() unit: Unit; + public studentId: User; + campuses: Campus[]; + campusId: number = 1; + + ngOnInit(): void { + this.campusService.query().subscribe((campuses) => { + this.campuses = campuses; + this.campusId = campuses[0].id; + }); + } + + public enrolStudent(studentId: any, campusId: any): void { + if (!campusId) { + this.alertService.error('Campus missing. Please indicate student campus'); + return + } + + this.newProjectService.create( + {}, + { cache: this.unit.studentCache, + body: { + unit_id: this.unit.id, + student_num: studentId, + campus_id: campusId + }, + constructorParams: this.unit + } + ).subscribe({ + next: (project) => { + this.alertService.success('Student enrolled'); + this.dialogRef.close(); + }, + error: (message) => { + this.alertService.error(`Error enrolling student: ${message}`); + }, + }); + } +} diff --git a/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service.ts b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service.ts new file mode 100644 index 000000000..035f13ceb --- /dev/null +++ b/src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service.ts @@ -0,0 +1,20 @@ +/* eslint-disable prefer-const */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable prettier/prettier */ +import { Injectable } from '@angular/core'; +import { MatDialogRef, MatDialog } from '@angular/material/dialog'; +import { UnitStudentEnrolmentModalComponent } from './unit-student-enrolment-modal.component'; + +@Injectable({ + providedIn: 'root', +}) +export class UnitStudentEnrolmentModalService { + constructor(public dialog: MatDialog) {} + + public show(unit: any) { + let dialogRef: MatDialogRef; + dialogRef = this.dialog.open(UnitStudentEnrolmentModalComponent, {position: {top: '2.5%'}}); + dialogRef.updateSize('42.5%', ''); + dialogRef.componentInstance.unit = unit; + } +}