Skip to content

Commit

Permalink
refactor: migrate the unit-student-enrolment-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
s223749059 committed May 14, 2024
1 parent 5e81bc1 commit a878953
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 56 deletions.
2 changes: 2 additions & 0 deletions src/app/doubtfire-angular.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -251,6 +252,7 @@ import {TasksViewerComponent} from './units/states/tasks/tasks-viewer/tasks-view
OverseerImageListComponent,
ExtensionModalComponent,
CalendarModalComponent,
UnitStudentEnrolmentModalComponent,
InstitutionSettingsComponent,
HomeComponent,
CommentBubbleActionComponent,
Expand Down
3 changes: 2 additions & 1 deletion src/app/doubtfire-angularjs.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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));
Expand Down
1 change: 0 additions & 1 deletion src/app/units/modals/modals.coffee
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
angular.module('doubtfire.units.modals', [
'doubtfire.units.modals.unit-ilo-edit-modal'
'doubtfire.units.modals.unit-student-enrolment-modal'
])

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<!-- eslint-disable prettier/prettier -->
<div class="unit-student-enrolment-modal">
<div class="modal-header">
<h3>Enrol Student</h3>
Expand All @@ -7,20 +8,24 @@ <h3>Enrol Student</h3>
<div class="form-group" required>
<label class="col-sm-3 control-label">Student</label>
<div class="col-sm-7">
<input type="input" class="form-control" placeholder="Student ID" ng-model="studentId">
<input type="input" class="form-control" placeholder="Student ID" [(ngModel)]="studentId" name="studentId">
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label" for="teachingperiod">Campus</label>
<div class="col-sm-7">
<select class="form-control" ng-model="data.campusId">
<option ng-value="campus.id" ng-repeat="campus in campuses" value="{{campus.id}}">{{campus.name}}</option>
<select class="form-control" [(ngModel)]="campusId" name="campusId">
@for (campus of campuses; track campus) {
<option value="{{campus.id}}">
{{ campus.name }}
<option>
}
</select>
</div>
</div>
</form>
</div>
<div class="modal-footer text-right">
<input type="button" ng-click="enrolStudent(studentId, data.campusId)" class="btn btn-primary" value="Save" />
<input type="button" (click)="enrolStudent(studentId, campusId)" class="btn btn-primary" value="Save" />
</div>
</div>
Original file line number Diff line number Diff line change
@@ -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, 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<UnitStudentEnrolmentModalComponent>,
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.success('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}`);
},
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
/* eslint-disable prefer-const */
/* 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<UnitStudentEnrolmentModalComponent, any>;
dialogRef = this.dialog.open(UnitStudentEnrolmentModalComponent, {position: {top: '2.5%'}});
dialogRef.updateSize('42.5%', '');
dialogRef.componentInstance.unit = unit;
}
}

0 comments on commit a878953

Please sign in to comment.