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;
+ }
+}