|
@@ -0,0 +1,108 @@
|
|
|
|
|
+import {Component, OnInit} from '@angular/core';
|
|
|
|
|
+import {Student} from "../models/student";
|
|
|
|
|
+import {StudentService} from "../services/student";
|
|
|
|
|
+import {GradeService} from "../services/grade";
|
|
|
|
|
+import {Grade} from "../models/grade";
|
|
|
|
|
+import {ActivatedRoute} from "@angular/router";
|
|
|
|
|
+import {Subject} from "../models/subject";
|
|
|
|
|
+import {SubjectService} from "../services/subject";
|
|
|
|
|
+import {FormsModule} from '@angular/forms';
|
|
|
|
|
+import {NgForOf, NgIf} from '@angular/common';
|
|
|
|
|
+
|
|
|
|
|
+@Component({
|
|
|
|
|
+ selector: 'app-grade-teacher',
|
|
|
|
|
+ templateUrl: './grade-teacher.html',
|
|
|
|
|
+ imports: [
|
|
|
|
|
+ FormsModule,
|
|
|
|
|
+ NgForOf,
|
|
|
|
|
+ NgIf
|
|
|
|
|
+ ],
|
|
|
|
|
+ styleUrls: ['./grade-teacher.css']
|
|
|
|
|
+})
|
|
|
|
|
+
|
|
|
|
|
+export class GradeTeacher implements OnInit {
|
|
|
|
|
+ form: any = {};
|
|
|
|
|
+ studentList?: Student[];
|
|
|
|
|
+ student?: Student;
|
|
|
|
|
+ gradeToAdd?: Grade;
|
|
|
|
|
+ gradeList?: Grade[];
|
|
|
|
|
+ grade?: Grade;
|
|
|
|
|
+ subject?: Subject;
|
|
|
|
|
+ errorMessage = '';
|
|
|
|
|
+ subjectId?: number;
|
|
|
|
|
+ selectedGrade: Grade | null = null;
|
|
|
|
|
+ selectedGradeValue: number | null = null;
|
|
|
|
|
+ gradeOptions = [2, 3, 3.5, 4, 4.5, 5];
|
|
|
|
|
+
|
|
|
|
|
+ constructor(private studentService: StudentService, private gradeService: GradeService, private subjectService: SubjectService, private route: ActivatedRoute) {}
|
|
|
|
|
+
|
|
|
|
|
+ ngOnInit() {
|
|
|
|
|
+ this.getStudents();
|
|
|
|
|
+ this.subjectId = Number(this.route.snapshot.paramMap.get('id'));
|
|
|
|
|
+ this.subjectService.getSubject(this.subjectId).subscribe(subject => this.subject = subject);
|
|
|
|
|
+ this.getGrades();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getStudents(): void {
|
|
|
|
|
+ this.studentService.getStudents()
|
|
|
|
|
+ .subscribe(studentList => this.studentList = studentList);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ getGrades(): void {
|
|
|
|
|
+ if(this.subjectId){
|
|
|
|
|
+ this.gradeService.getGradesFromSubject(this.subjectId)
|
|
|
|
|
+ .subscribe(gradeList => this.gradeList = gradeList);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ addGrade(): void {
|
|
|
|
|
+ this.student = this.studentList?.find(student => student.id === Number(this.form.student));
|
|
|
|
|
+ if (this.subject && this.student) {
|
|
|
|
|
+ this.gradeToAdd = new Grade(this.form.grade, this.subject, this.student);
|
|
|
|
|
+ }
|
|
|
|
|
+ if(this.gradeToAdd) {
|
|
|
|
|
+ this.gradeService.addGrade(this.gradeToAdd).subscribe(
|
|
|
|
|
+ data => {
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ this.reloadPage();
|
|
|
|
|
+ },
|
|
|
|
|
+ error => {
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ this.errorMessage = error.error.message;
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ editGrade(grade: Grade): void {
|
|
|
|
|
+ this.selectedGrade = grade;
|
|
|
|
|
+ this.selectedGradeValue = grade.grade;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ cancelEdit(): void {
|
|
|
|
|
+ this.selectedGrade = null;
|
|
|
|
|
+ this.selectedGradeValue = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ saveGrade(): void {
|
|
|
|
|
+ if (this.selectedGrade && this.selectedGradeValue) {
|
|
|
|
|
+ this.selectedGrade.grade = this.selectedGradeValue;
|
|
|
|
|
+ this.gradeService.editGrade(this.selectedGrade).subscribe(
|
|
|
|
|
+ data => {
|
|
|
|
|
+ console.log(data);
|
|
|
|
|
+ this.reloadPage();
|
|
|
|
|
+ },
|
|
|
|
|
+ error => {
|
|
|
|
|
+ console.log(error);
|
|
|
|
|
+ this.errorMessage = error.error.message;
|
|
|
|
|
+ }
|
|
|
|
|
+ );
|
|
|
|
|
+ }
|
|
|
|
|
+ this.selectedGrade = null;
|
|
|
|
|
+ this.selectedGradeValue = null;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ reloadPage(): void {
|
|
|
|
|
+ window.location.reload();
|
|
|
|
|
+ }
|
|
|
|
|
+}
|