fixed errors

This commit is contained in:
JakubWalkowiak 2021-01-04 23:39:48 +01:00
parent 83d84ee5fd
commit 24be14bef5
6 changed files with 26 additions and 4 deletions

View File

@ -25,7 +25,7 @@ export class GroupEditComponent implements OnInit {
ngOnInit(): void { ngOnInit(): void {
this.currentUserId = localStorage.getItem('userId'); this.currentUserId = localStorage.getItem('userId');
this.groupId = this.activatedRoute.snapshot.params['groupId']; this.groupId = this.activatedRoute.snapshot.params.groupId;
this.group$ = this.groupService.getGroup(this.groupId); this.group$ = this.groupService.getGroup(this.groupId);
this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); this.groupCandidates$ = this.groupCandidateService.getList(this.groupId);
} }

View File

@ -1,3 +1,8 @@
<div class="d-flex justify-content-center">
<div *ngIf="!editable" class="edit-warning">
<p class="text-danger">Subject is edited by another user</p>
</div>
</div>
<div class="subject-form-container d-flex justify-content-center"> <div class="subject-form-container d-flex justify-content-center">
<form [formGroup]="subjectForm" class="subject-form d-flex flex-column mt-5"> <form [formGroup]="subjectForm" class="subject-form d-flex flex-column mt-5">
<mat-form-field> <mat-form-field>
@ -87,5 +92,8 @@
<div class="mt-4"> <div class="mt-4">
<button [disabled]="!editable" (click)="onSubjectSave()" class="btn btn-primary">Save</button> <button [disabled]="!editable" (click)="onSubjectSave()" class="btn btn-primary">Save</button>
</div> </div>
<div class="mt-4">
<button (click)="backToGroup()" class="btn btn-primary">Back to group</button>
</div>
</form> </form>
</div> </div>

View File

@ -2,4 +2,8 @@
.subject-form { .subject-form {
width: 80%; width: 80%;
} }
}
.edit-warning {
width: 80%;
} }

View File

@ -27,7 +27,7 @@ export class SubjectEditComponent implements OnInit {
private router: Router) { } private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
this.groupId = this.activatedRoute.snapshot.params['groupId']; this.groupId = this.activatedRoute.snapshot.params.groupId;
this.subject = this.createEmptySubject(); this.subject = this.createEmptySubject();
this.subjectForm = this.createSubjectForm(); this.subjectForm = this.createSubjectForm();
this.subjectId = this.activatedRoute.snapshot.params.id; this.subjectId = this.activatedRoute.snapshot.params.id;
@ -43,6 +43,16 @@ export class SubjectEditComponent implements OnInit {
} }
} }
backToGroup(): void {
if (this.editable) {
this.subjectService.unlock(this.subjectId).subscribe(() => {
this.router.navigateByUrl('/group/edit/' + this.groupId);
});
} else {
this.router.navigateByUrl('/group/edit/' + this.groupId);
}
}
createEmptySubject(): Subject { createEmptySubject(): Subject {
return { return {
id: null, id: null,

View File

@ -63,7 +63,7 @@ export class SubjectMainComponent implements OnInit {
} }
onEditSubject(id: number): void { onEditSubject(id: number): void {
this.router.navigateByUrl(`subject/edit/${id}/${this.userId}`); this.router.navigateByUrl(`subject/edit/${this.groupId}/${id}`);
} }
onUnlockSubject(id: number): void { onUnlockSubject(id: number): void {

View File

@ -12,7 +12,7 @@ const routes: Routes = [
children: [ children: [
{ path: '', component: SubjectMainComponent }, { path: '', component: SubjectMainComponent },
{ path: 'new-subject/:groupId', component: SubjectEditComponent }, { path: 'new-subject/:groupId', component: SubjectEditComponent },
{ path: 'edit/:id/:groupId', component: SubjectEditComponent } { path: 'edit/:groupId/:id', component: SubjectEditComponent }
] ]
} }
]; ];