From 76cbb96eafa3d8c5a9c7af9be7502e46cf8dced0 Mon Sep 17 00:00:00 2001 From: JakubWalkowiak Date: Fri, 8 Jan 2021 22:13:47 +0100 Subject: [PATCH] fixed errors --- .../group-edit/group-edit.component.html | 1 + .../group-edit/group-edit.component.ts | 4 ++ .../subject-edit/subject-edit.component.html | 10 ++--- .../subject-edit/subject-edit.component.ts | 43 +++++++++++-------- .../subject-list/subject-list.component.html | 4 +- .../subject-main/subject-main.component.html | 3 +- src/styles.scss | 9 ++++ 7 files changed, 48 insertions(+), 26 deletions(-) diff --git a/src/app/group/components/group-edit/group-edit.component.html b/src/app/group/components/group-edit/group-edit.component.html index f4d8433..652f5c3 100644 --- a/src/app/group/components/group-edit/group-edit.component.html +++ b/src/app/group/components/group-edit/group-edit.component.html @@ -3,6 +3,7 @@
+

Group info:

diff --git a/src/app/group/components/group-edit/group-edit.component.ts b/src/app/group/components/group-edit/group-edit.component.ts index 0692ddf..7e36f31 100644 --- a/src/app/group/components/group-edit/group-edit.component.ts +++ b/src/app/group/components/group-edit/group-edit.component.ts @@ -30,6 +30,10 @@ export class GroupEditComponent implements OnInit { this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); } + onBackToGroupList(): void { + this.router.navigateByUrl('/group'); + } + onDelete(): void { this.groupService.delete(this.groupId).subscribe(() => { this.router.navigateByUrl('/group'); diff --git a/src/app/subject/components/subject-edit/subject-edit.component.html b/src/app/subject/components/subject-edit/subject-edit.component.html index 7203485..3b6e2ae 100644 --- a/src/app/subject/components/subject-edit/subject-edit.component.html +++ b/src/app/subject/components/subject-edit/subject-edit.component.html @@ -53,15 +53,15 @@
Test {{i + 1}}
- + Name - + Deadline - + Description @@ -79,7 +79,7 @@
Test {{i + 1}}
- + Text @@ -90,7 +90,7 @@
- +
diff --git a/src/app/subject/components/subject-edit/subject-edit.component.ts b/src/app/subject/components/subject-edit/subject-edit.component.ts index beeace0..eef0c7a 100644 --- a/src/app/subject/components/subject-edit/subject-edit.component.ts +++ b/src/app/subject/components/subject-edit/subject-edit.component.ts @@ -1,6 +1,6 @@ import { GroupService } from './../../../group/services/group.service'; import { Assignment } from './../../interfaces/assignment.interface'; -import { Component, OnInit } from '@angular/core'; +import { Component, OnInit, ChangeDetectorRef } from '@angular/core'; import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms'; import { SubjectService } from '../../services/subject.service'; import { ActivatedRoute, Router } from '@angular/router'; @@ -18,13 +18,15 @@ export class SubjectEditComponent implements OnInit { subject: Subject; subjectForm: FormGroup; subjectId: number; + submited = false; groupId: number; - editable: boolean; + editable = true; constructor(private activatedRoute: ActivatedRoute, private subjectService: SubjectService, private groupService: GroupService, - private router: Router) { } + private router: Router, + private cd: ChangeDetectorRef) { } ngOnInit(): void { this.groupId = this.activatedRoute.snapshot.params.groupId; @@ -44,7 +46,7 @@ export class SubjectEditComponent implements OnInit { } backToGroup(): void { - if (this.editable) { + if (this.editable && this.subjectId) { this.subjectService.unlock(this.subjectId).subscribe(() => { this.router.navigateByUrl('/group/edit/' + this.groupId); }); @@ -90,7 +92,7 @@ export class SubjectEditComponent implements OnInit { (this.subjectForm.controls.tests as FormArray).push(new FormGroup({ id: new FormControl(null), date: new FormControl(null), - scope: new FormControl(''), + scope: new FormControl('', Validators.required), finalMarkPercent: new FormControl(0), subjectId: new FormControl(null) })); @@ -98,9 +100,9 @@ export class SubjectEditComponent implements OnInit { for (let assignment of this.subject.assignments) { (this.subjectForm.controls.assignments as FormArray).push(new FormGroup({ id: new FormControl(null), - name: new FormControl(''), + name: new FormControl('', Validators.required), deadline: new FormControl(null), - description: new FormControl(''), + description: new FormControl('', Validators.required), finalMarkPercent: new FormControl(0), subjectId: new FormControl(null) })); @@ -108,7 +110,7 @@ export class SubjectEditComponent implements OnInit { for (let comment of this.subject.comments) { (this.subjectForm.controls.comments as FormArray).push(new FormGroup({ id: new FormControl(null), - text: new FormControl(''), + text: new FormControl('', Validators.required), subjectId: new FormControl(null) })); } @@ -140,9 +142,9 @@ export class SubjectEditComponent implements OnInit { }; } (this.subjectForm.controls.assignments as FormArray).push(new FormGroup({ - name: new FormControl(assignment.name), + name: new FormControl(assignment.name, Validators.required), deadline: new FormControl(this.parseDateTimeToISOFormat(assignment.deadline)), - description: new FormControl(assignment.description), + description: new FormControl(assignment.description, Validators.required), finalMarkPercent: new FormControl(assignment.finalMarkPercent) })); } @@ -159,14 +161,19 @@ export class SubjectEditComponent implements OnInit { } onSubjectSave(): void { - if (this.subjectId) { - this.subjectService.update(this.subjectForm.value).subscribe(() => { - this.router.navigateByUrl('/group/edit/' + this.groupId); - }); - } else { - this.subjectService.add(this.subjectForm.value).subscribe(() => { - this.router.navigateByUrl('/group/edit/' + this.groupId); - }); + this.submited = true; + //this.subjectForm.updateValueAndValidity(); + //this.cd.detectChanges(); + if (this.subjectForm.valid) { + if (this.subjectId) { + this.subjectService.update(this.subjectForm.value).subscribe(() => { + this.router.navigateByUrl('/group/edit/' + this.groupId); + }); + } else { + this.subjectService.add(this.subjectForm.value).subscribe(() => { + this.router.navigateByUrl('/group/edit/' + this.groupId); + }); + } } } diff --git a/src/app/subject/components/subject-list/subject-list.component.html b/src/app/subject/components/subject-list/subject-list.component.html index 1111e22..bcee208 100644 --- a/src/app/subject/components/subject-list/subject-list.component.html +++ b/src/app/subject/components/subject-list/subject-list.component.html @@ -17,8 +17,8 @@
Exam: {{ subject.mainExam ? 'Yes' : 'No' }}
-
- Exam date: {{ subject.examDate }} +
+ Exam date: {{ subject.examDate | date:'dd-MM-y, HH:mm' }}
diff --git a/src/app/subject/components/subject-main/subject-main.component.html b/src/app/subject/components/subject-main/subject-main.component.html index 9e49c68..804776b 100644 --- a/src/app/subject/components/subject-main/subject-main.component.html +++ b/src/app/subject/components/subject-main/subject-main.component.html @@ -9,7 +9,8 @@ (addNewSubject)="onAddNewSubject()" (deleteRequest)="onAddDeleteRequest($event)" (deleteSubject)="onDeleteSubject($event)" - (editSubject)="onEditSubject($event)"> + (editSubject)="onEditSubject($event)" + (unlockSubject)="onUnlockSubject($event)">
diff --git a/src/styles.scss b/src/styles.scss index 7e7239a..d88d117 100644 --- a/src/styles.scss +++ b/src/styles.scss @@ -2,3 +2,12 @@ html, body { height: 100%; } body { margin: 0; font-family: Roboto, "Helvetica Neue", sans-serif; } + +.error-field { + .mat-form-field-empty.mat-form-field-label { + color: red; + } + .mat-form-field-underline { + background-color: red; + } +}