fixed errors

This commit is contained in:
JakubWalkowiak 2021-01-08 22:13:47 +01:00
parent 24be14bef5
commit 76cbb96eaf
7 changed files with 48 additions and 26 deletions

View File

@ -3,6 +3,7 @@
<div class="d-flex justify-content-end">
<button *ngIf="group.admin.id === currentUserId" (click)="onDelete()" class="btn btn-primary">Delete group</button>
<button *ngIf="group.admin.id !== currentUserId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button>
<button (click)="onBackToGroupList()" class="btn btn-primary ml-2">Back to group list</button>
</div>
<div class="group-main-data mb-5">
<h3>Group info:</h3>

View File

@ -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');

View File

@ -53,15 +53,15 @@
<div class="list-group-item">
<h5 class="card-title">Test {{i + 1}}</h5>
<div [formGroup]="assignment" class="d-flex flex-column">
<mat-form-field>
<mat-form-field [ngClass]="{'error-field': submited && assignment.controls.name.value == ''}">
<mat-label>Name</mat-label>
<input matInput formControlName="name" />
<input matInput formControlName="name"/>
</mat-form-field>
<mat-form-field>
<mat-label>Deadline</mat-label>
<input matInput type="datetime-local" formControlName="deadline" />
</mat-form-field>
<mat-form-field>
<mat-form-field [ngClass]="{'error-field': submited && assignment.controls.description.value == ''}">
<mat-label>Description</mat-label>
<textarea matInput type="text" formControlName="description"></textarea>
</mat-form-field>
@ -79,7 +79,7 @@
<div class="list-group-item">
<h5 class="card-title">Test {{i + 1}}</h5>
<div [formGroup]="comment">
<mat-form-field>
<mat-form-field [ngClass]="{'error-field': submited && comment.controls.text.value == ''}">
<mat-label>Text</mat-label>
<textarea matInput type="text" formControlName="text"></textarea>
</mat-form-field>
@ -90,7 +90,7 @@
<button [disabled]="!editable" (click)="onAddNewComment()" class="btn btn-primary">Add new comment</button>
</div>
<div class="mt-4">
<button [disabled]="!editable" (click)="onSubjectSave()" class="btn btn-primary">Save</button>
<button [disabled]="!editable" (click)="onSubjectSave()" type="submit" class="btn btn-primary">Save</button>
</div>
<div class="mt-4">
<button (click)="backToGroup()" class="btn btn-primary">Back to group</button>

View File

@ -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);
});
}
}
}

View File

@ -17,8 +17,8 @@
<div>
Exam: {{ subject.mainExam ? 'Yes' : 'No' }}
</div>
<div>
Exam date: {{ subject.examDate }}
<div *ngIf="subject.mainExam">
Exam date: {{ subject.examDate | date:'dd-MM-y, HH:mm' }}
</div>
</div>
<div class="subject-buttons d-flex align-items-center">

View File

@ -9,7 +9,8 @@
(addNewSubject)="onAddNewSubject()"
(deleteRequest)="onAddDeleteRequest($event)"
(deleteSubject)="onDeleteSubject($event)"
(editSubject)="onEditSubject($event)">
(editSubject)="onEditSubject($event)"
(unlockSubject)="onUnlockSubject($event)">
</app-subject-list>
</div>
<div *ngIf="userId === adminId">

View File

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