forked from thoth-tech/doubtfire-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: migrate the unit-student-enrolment-modal
- Loading branch information
1 parent
f19eabd
commit 0989e03
Showing
6 changed files
with
119 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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' | ||
]) |
31 changes: 31 additions & 0 deletions
31
...app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- eslint-disable prettier/prettier --> | ||
<div class="unit-student-enrolment-modal"> | ||
<div class="modal-header"> | ||
<h3>Enrol Student</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<form class="form-horizontal"> | ||
<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" [(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" [(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" (click)="enrolStudent(studentId, campusId)" class="btn btn-primary" value="Save" /> | ||
</div> | ||
</div> |
64 changes: 64 additions & 0 deletions
64
src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, 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<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.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}`); | ||
}, | ||
}); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.service.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<UnitStudentEnrolmentModalComponent, any>; | ||
dialogRef = this.dialog.open(UnitStudentEnrolmentModalComponent, {position: {top: '2.5%'}}); | ||
dialogRef.updateSize('42.5%', ''); | ||
dialogRef.componentInstance.unit = unit; | ||
} | ||
} |