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
5e81bc1
commit a878953
Showing
7 changed files
with
97 additions
and
56 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' | ||
]) |
50 changes: 0 additions & 50 deletions
50
src/app/units/modals/unit-student-enrolment-modal/unit-student-enrolment-modal.coffee
This file was deleted.
Oops, something went wrong.
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
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, 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}`); | ||
}, | ||
}); | ||
} | ||
} |
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 @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; | ||
} | ||
} |