From 83d84ee5fd77c854fd6379325327732f09e3de7b Mon Sep 17 00:00:00 2001 From: JakubWalkowiak Date: Sun, 3 Jan 2021 23:30:50 +0100 Subject: [PATCH] added editablity --- .../components/group-edit/group-edit.component.html | 3 ++- .../components/group-edit/group-edit.component.ts | 8 +++++++- src/app/group/services/group.service.ts | 4 ++-- .../subject-edit/subject-edit.component.html | 8 ++++---- .../components/subject-edit/subject-edit.component.ts | 11 ++++++++++- .../subject-list/subject-list.component.html | 1 + .../components/subject-list/subject-list.component.ts | 5 +++++ .../components/subject-main/subject-main.component.ts | 8 +++++++- src/app/subject/interfaces/subject.interface.ts | 1 + src/app/subject/services/subject.service.ts | 8 ++++++-- src/environments/environment.ts | 3 ++- 11 files changed, 47 insertions(+), 13 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 591e0ef..f4d8433 100644 --- a/src/app/group/components/group-edit/group-edit.component.html +++ b/src/app/group/components/group-edit/group-edit.component.html @@ -23,7 +23,8 @@

Users:

+ [adminId]="group.admin.id" + (deleteUser)="onDeleteUser($event)">

Group candidates:

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 fed1cbd..e14e518 100644 --- a/src/app/group/components/group-edit/group-edit.component.ts +++ b/src/app/group/components/group-edit/group-edit.component.ts @@ -37,7 +37,7 @@ export class GroupEditComponent implements OnInit { } onLeaveGroup(): void { - this.groupService.leaveGroup(this.groupId).subscribe(() => { + this.groupService.leaveGroup(this.groupId, localStorage.getItem('userId')).subscribe(() => { this.router.navigateByUrl('/group'); }); } @@ -55,4 +55,10 @@ export class GroupEditComponent implements OnInit { }); } + onDeleteUser(userId: string) { + this.groupService.leaveGroup(this.groupId, userId).subscribe(() => { + this.group$ = this.groupService.getGroup(this.groupId); + }); + } + } diff --git a/src/app/group/services/group.service.ts b/src/app/group/services/group.service.ts index 2dd2d29..a0f9435 100644 --- a/src/app/group/services/group.service.ts +++ b/src/app/group/services/group.service.ts @@ -28,8 +28,8 @@ export class GroupService { return this.http.get(`${environment.host}${environment.apiEndpoints.groups.getCurrentUserGroups}/${localStorage.getItem('userId')}`); } - leaveGroup(groupId: number): Observable { - return this.http.get(`${environment.host}${environment.apiEndpoints.groups.leave}/${groupId}/${localStorage.getItem('userId')}`); + leaveGroup(groupId: number, userId: string): Observable { + return this.http.get(`${environment.host}${environment.apiEndpoints.groups.leave}/${groupId}/${userId}`); } delete(groupId: number): Observable { 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 cb72912..2db178a 100644 --- a/src/app/subject/components/subject-edit/subject-edit.component.html +++ b/src/app/subject/components/subject-edit/subject-edit.component.html @@ -42,7 +42,7 @@
- +
@@ -68,7 +68,7 @@
- +
@@ -82,10 +82,10 @@
- +
- +
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 0995266..5a026ed 100644 --- a/src/app/subject/components/subject-edit/subject-edit.component.ts +++ b/src/app/subject/components/subject-edit/subject-edit.component.ts @@ -1,3 +1,4 @@ +import { GroupService } from './../../../group/services/group.service'; import { Assignment } from './../../interfaces/assignment.interface'; import { Component, OnInit } from '@angular/core'; import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms'; @@ -18,9 +19,11 @@ export class SubjectEditComponent implements OnInit { subjectForm: FormGroup; subjectId: number; groupId: number; + editable: boolean; constructor(private activatedRoute: ActivatedRoute, private subjectService: SubjectService, + private groupService: GroupService, private router: Router) { } ngOnInit(): void { @@ -29,9 +32,13 @@ export class SubjectEditComponent implements OnInit { this.subjectForm = this.createSubjectForm(); this.subjectId = this.activatedRoute.snapshot.params.id; if (this.subjectId) { - this.subjectService.getById(this.subjectId).subscribe((subjectPayload) => { + this.subjectService.getById(this.subjectId, localStorage.getItem('userId')).subscribe((subjectPayload) => { this.subject = subjectPayload; this.updateSubjectForm(this.subject); + this.editable = this.subject.editedBy === localStorage.getItem('userId'); + if (!this.editable) { + this.subjectForm.disable(); + } }); } } @@ -45,6 +52,7 @@ export class SubjectEditComponent implements OnInit { labTeacher: '', mainExam: false, examDate: new Date(), + editedBy: null, tests: [], assignments: [], comments: [] @@ -60,6 +68,7 @@ export class SubjectEditComponent implements OnInit { labTeacher: new FormControl(''), mainExam: new FormControl(false), examDate: new FormControl(this.parseDateTimeToISOFormat(new Date())), + editedBy: new FormControl(null), tests: new FormArray([]), assignments: new FormArray([]), comments: new FormArray([]), 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 1bd4d5b..1111e22 100644 --- a/src/app/subject/components/subject-list/subject-list.component.html +++ b/src/app/subject/components/subject-list/subject-list.component.html @@ -23,6 +23,7 @@
+
diff --git a/src/app/subject/components/subject-list/subject-list.component.ts b/src/app/subject/components/subject-list/subject-list.component.ts index 136787d..d4b078f 100644 --- a/src/app/subject/components/subject-list/subject-list.component.ts +++ b/src/app/subject/components/subject-list/subject-list.component.ts @@ -15,6 +15,7 @@ export class ListComponent implements OnInit { @Output() deleteSubject = new EventEmitter(); @Output() addNewSubject = new EventEmitter(); @Output() editSubject = new EventEmitter(); + @Output() unlockSubject = new EventEmitter(); displayedColumns: string[]; constructor() { } @@ -39,4 +40,8 @@ export class ListComponent implements OnInit { this.editSubject.emit(id); } + onUnlock(id: number): void { + this.unlockSubject.emit(id); + } + } diff --git a/src/app/subject/components/subject-main/subject-main.component.ts b/src/app/subject/components/subject-main/subject-main.component.ts index 931ffe5..46386ff 100644 --- a/src/app/subject/components/subject-main/subject-main.component.ts +++ b/src/app/subject/components/subject-main/subject-main.component.ts @@ -63,7 +63,13 @@ export class SubjectMainComponent implements OnInit { } onEditSubject(id: number): void { - this.router.navigateByUrl(`subject/edit/${id}/${this.groupId}`); + this.router.navigateByUrl(`subject/edit/${id}/${this.userId}`); + } + + onUnlockSubject(id: number): void { + this.subjectService.unlock(id).subscribe(() => { + this.subjects$ = this.subjectService.getListByGroupId(this.groupId); + }); } } diff --git a/src/app/subject/interfaces/subject.interface.ts b/src/app/subject/interfaces/subject.interface.ts index 189adca..dfb34d2 100644 --- a/src/app/subject/interfaces/subject.interface.ts +++ b/src/app/subject/interfaces/subject.interface.ts @@ -10,6 +10,7 @@ export interface Subject { labTeacher: string; mainExam: boolean; examDate: Date; + editedBy?: string; tests: Test[]; assignments: Assignment[]; comments: Comment[]; diff --git a/src/app/subject/services/subject.service.ts b/src/app/subject/services/subject.service.ts index aaee05b..510d1b4 100644 --- a/src/app/subject/services/subject.service.ts +++ b/src/app/subject/services/subject.service.ts @@ -19,8 +19,8 @@ export class SubjectService { return this.http.delete(`${environment.host + environment.apiEndpoints.subjects.delete}/${id}`); } - getById(id: number): Observable { - return this.http.get(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}`); + getById(id: number, userId: string): Observable { + return this.http.get(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}/${userId}`); } getListByGroupId(groupId: number): Observable { @@ -30,4 +30,8 @@ export class SubjectService { update(subject: Subject): Observable { return this.http.put(`${environment.host + environment.apiEndpoints.subjects.update}/${subject.id}`, subject); } + + unlock(id: number): Observable { + return this.http.get(`${environment.host + environment.apiEndpoints.subjects.unlock}/${id}`); + } } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index e071207..35258fb 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -7,7 +7,8 @@ export const environment = { getById: 'api/subjects/get-by-id', delete: 'api/subjects/delete', add: 'api/subjects/add', - update: 'api/subjects/update' + update: 'api/subjects/update', + unlock: 'api/subjects/unlock' }, deleteRequests: { getListByGroupId: 'api/subjectDeleteRequests/list-by-group-id',