fixed errors
This commit is contained in:
parent
24be14bef5
commit
76cbb96eaf
@ -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>
|
||||
|
@ -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');
|
||||
|
@ -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>
|
||||
|
@ -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,6 +161,10 @@ export class SubjectEditComponent implements OnInit {
|
||||
}
|
||||
|
||||
onSubjectSave(): void {
|
||||
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);
|
||||
@ -169,6 +175,7 @@ export class SubjectEditComponent implements OnInit {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private parseDateTimeToISOFormat(date: Date): string {
|
||||
return new Date(date.getTime() - (date.getTimezoneOffset() * 60000)).toISOString().slice(0, 16);
|
||||
|
@ -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">
|
||||
|
@ -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">
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user