added editablity
This commit is contained in:
parent
51fded7271
commit
83d84ee5fd
@ -23,7 +23,8 @@
|
|||||||
<h3>Users:</h3>
|
<h3>Users:</h3>
|
||||||
<app-group-users
|
<app-group-users
|
||||||
[groupUsers]="group.users"
|
[groupUsers]="group.users"
|
||||||
[adminId]="group.admin.id"></app-group-users>
|
[adminId]="group.admin.id"
|
||||||
|
(deleteUser)="onDeleteUser($event)"></app-group-users>
|
||||||
</div>
|
</div>
|
||||||
<div *ngIf="group.admin.id === currentUserId && group.groupCandidates" class="mb-5 border p-3">
|
<div *ngIf="group.admin.id === currentUserId && group.groupCandidates" class="mb-5 border p-3">
|
||||||
<h3>Group candidates:</h3>
|
<h3>Group candidates:</h3>
|
||||||
|
@ -37,7 +37,7 @@ export class GroupEditComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onLeaveGroup(): void {
|
onLeaveGroup(): void {
|
||||||
this.groupService.leaveGroup(this.groupId).subscribe(() => {
|
this.groupService.leaveGroup(this.groupId, localStorage.getItem('userId')).subscribe(() => {
|
||||||
this.router.navigateByUrl('/group');
|
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);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -28,8 +28,8 @@ export class GroupService {
|
|||||||
return this.http.get<Group[]>(`${environment.host}${environment.apiEndpoints.groups.getCurrentUserGroups}/${localStorage.getItem('userId')}`);
|
return this.http.get<Group[]>(`${environment.host}${environment.apiEndpoints.groups.getCurrentUserGroups}/${localStorage.getItem('userId')}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
leaveGroup(groupId: number): Observable<void> {
|
leaveGroup(groupId: number, userId: string): Observable<void> {
|
||||||
return this.http.get<void>(`${environment.host}${environment.apiEndpoints.groups.leave}/${groupId}/${localStorage.getItem('userId')}`);
|
return this.http.get<void>(`${environment.host}${environment.apiEndpoints.groups.leave}/${groupId}/${userId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete(groupId: number): Observable<void> {
|
delete(groupId: number): Observable<void> {
|
||||||
|
@ -42,7 +42,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<button (click)="onAddNewTest()" class="btn btn-primary">Add new test</button>
|
<button [disabled]="!editable" (click)="onAddNewTest()" class="btn btn-primary">Add new test</button>
|
||||||
</div>
|
</div>
|
||||||
<div *ngFor="let assignment of subjectForm.get('assignments')['controls']; let i = index" class="list-group list-group-flush">
|
<div *ngFor="let assignment of subjectForm.get('assignments')['controls']; let i = index" class="list-group list-group-flush">
|
||||||
<div class="list-group-item">
|
<div class="list-group-item">
|
||||||
@ -68,7 +68,7 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<button (click)="onAddNewAssignment()" class="btn btn-primary">Add new assignment</button>
|
<button [disabled]="!editable" (click)="onAddNewAssignment()" class="btn btn-primary">Add new assignment</button>
|
||||||
</div>
|
</div>
|
||||||
<div *ngFor="let comment of subjectForm.get('comments')['controls']; let i = index" class="list-group list-group-flush">
|
<div *ngFor="let comment of subjectForm.get('comments')['controls']; let i = index" class="list-group list-group-flush">
|
||||||
<div class="list-group-item">
|
<div class="list-group-item">
|
||||||
@ -82,10 +82,10 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="">
|
<div class="">
|
||||||
<button (click)="onAddNewComment()" class="btn btn-primary">Add new comment</button>
|
<button [disabled]="!editable" (click)="onAddNewComment()" class="btn btn-primary">Add new comment</button>
|
||||||
</div>
|
</div>
|
||||||
<div class="mt-4">
|
<div class="mt-4">
|
||||||
<button (click)="onSubjectSave()" class="btn btn-primary">Save</button>
|
<button [disabled]="!editable" (click)="onSubjectSave()" class="btn btn-primary">Save</button>
|
||||||
</div>
|
</div>
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { GroupService } from './../../../group/services/group.service';
|
||||||
import { Assignment } from './../../interfaces/assignment.interface';
|
import { Assignment } from './../../interfaces/assignment.interface';
|
||||||
import { Component, OnInit } from '@angular/core';
|
import { Component, OnInit } from '@angular/core';
|
||||||
import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms';
|
import { FormGroup, FormControl, Validators, FormArray } from '@angular/forms';
|
||||||
@ -18,9 +19,11 @@ export class SubjectEditComponent implements OnInit {
|
|||||||
subjectForm: FormGroup;
|
subjectForm: FormGroup;
|
||||||
subjectId: number;
|
subjectId: number;
|
||||||
groupId: number;
|
groupId: number;
|
||||||
|
editable: boolean;
|
||||||
|
|
||||||
constructor(private activatedRoute: ActivatedRoute,
|
constructor(private activatedRoute: ActivatedRoute,
|
||||||
private subjectService: SubjectService,
|
private subjectService: SubjectService,
|
||||||
|
private groupService: GroupService,
|
||||||
private router: Router) { }
|
private router: Router) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
@ -29,9 +32,13 @@ export class SubjectEditComponent implements OnInit {
|
|||||||
this.subjectForm = this.createSubjectForm();
|
this.subjectForm = this.createSubjectForm();
|
||||||
this.subjectId = this.activatedRoute.snapshot.params.id;
|
this.subjectId = this.activatedRoute.snapshot.params.id;
|
||||||
if (this.subjectId) {
|
if (this.subjectId) {
|
||||||
this.subjectService.getById(this.subjectId).subscribe((subjectPayload) => {
|
this.subjectService.getById(this.subjectId, localStorage.getItem('userId')).subscribe((subjectPayload) => {
|
||||||
this.subject = subjectPayload;
|
this.subject = subjectPayload;
|
||||||
this.updateSubjectForm(this.subject);
|
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: '',
|
labTeacher: '',
|
||||||
mainExam: false,
|
mainExam: false,
|
||||||
examDate: new Date(),
|
examDate: new Date(),
|
||||||
|
editedBy: null,
|
||||||
tests: [],
|
tests: [],
|
||||||
assignments: [],
|
assignments: [],
|
||||||
comments: []
|
comments: []
|
||||||
@ -60,6 +68,7 @@ export class SubjectEditComponent implements OnInit {
|
|||||||
labTeacher: new FormControl(''),
|
labTeacher: new FormControl(''),
|
||||||
mainExam: new FormControl(false),
|
mainExam: new FormControl(false),
|
||||||
examDate: new FormControl(this.parseDateTimeToISOFormat(new Date())),
|
examDate: new FormControl(this.parseDateTimeToISOFormat(new Date())),
|
||||||
|
editedBy: new FormControl(null),
|
||||||
tests: new FormArray([]),
|
tests: new FormArray([]),
|
||||||
assignments: new FormArray([]),
|
assignments: new FormArray([]),
|
||||||
comments: new FormArray([]),
|
comments: new FormArray([]),
|
||||||
|
@ -23,6 +23,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<div class="subject-buttons d-flex align-items-center">
|
<div class="subject-buttons d-flex align-items-center">
|
||||||
<button (click)="onEdit(subject.id)" class="btn btn-primary">Edit</button>
|
<button (click)="onEdit(subject.id)" class="btn btn-primary">Edit</button>
|
||||||
|
<button *ngIf="adminId === userId && subject.editedBy != null" (click)="onUnlock(subject.id)" class="btn btn-primary ml-2">Unlock</button>
|
||||||
<button *ngIf="adminId === userId" (click)="onDelete(subject.id)" class="btn btn-primary ml-2">Delete</button>
|
<button *ngIf="adminId === userId" (click)="onDelete(subject.id)" class="btn btn-primary ml-2">Delete</button>
|
||||||
<button *ngIf="adminId !== userId" (click)="onDeleteRequest(subject.id)" class="btn btn-primary ml-2">Delete request</button>
|
<button *ngIf="adminId !== userId" (click)="onDeleteRequest(subject.id)" class="btn btn-primary ml-2">Delete request</button>
|
||||||
</div>
|
</div>
|
||||||
|
@ -15,6 +15,7 @@ export class ListComponent implements OnInit {
|
|||||||
@Output() deleteSubject = new EventEmitter<number>();
|
@Output() deleteSubject = new EventEmitter<number>();
|
||||||
@Output() addNewSubject = new EventEmitter<void>();
|
@Output() addNewSubject = new EventEmitter<void>();
|
||||||
@Output() editSubject = new EventEmitter<number>();
|
@Output() editSubject = new EventEmitter<number>();
|
||||||
|
@Output() unlockSubject = new EventEmitter<number>();
|
||||||
displayedColumns: string[];
|
displayedColumns: string[];
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
@ -39,4 +40,8 @@ export class ListComponent implements OnInit {
|
|||||||
this.editSubject.emit(id);
|
this.editSubject.emit(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onUnlock(id: number): void {
|
||||||
|
this.unlockSubject.emit(id);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -63,7 +63,13 @@ export class SubjectMainComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onEditSubject(id: number): void {
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -10,6 +10,7 @@ export interface Subject {
|
|||||||
labTeacher: string;
|
labTeacher: string;
|
||||||
mainExam: boolean;
|
mainExam: boolean;
|
||||||
examDate: Date;
|
examDate: Date;
|
||||||
|
editedBy?: string;
|
||||||
tests: Test[];
|
tests: Test[];
|
||||||
assignments: Assignment[];
|
assignments: Assignment[];
|
||||||
comments: Comment[];
|
comments: Comment[];
|
||||||
|
@ -19,8 +19,8 @@ export class SubjectService {
|
|||||||
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.subjects.delete}/${id}`);
|
return this.http.delete<void>(`${environment.host + environment.apiEndpoints.subjects.delete}/${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getById(id: number): Observable<Subject> {
|
getById(id: number, userId: string): Observable<Subject> {
|
||||||
return this.http.get<Subject>(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}`);
|
return this.http.get<Subject>(`${environment.host + environment.apiEndpoints.subjects.getById}/${id}/${userId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
getListByGroupId(groupId: number): Observable<Subject[]> {
|
getListByGroupId(groupId: number): Observable<Subject[]> {
|
||||||
@ -30,4 +30,8 @@ export class SubjectService {
|
|||||||
update(subject: Subject): Observable<void> {
|
update(subject: Subject): Observable<void> {
|
||||||
return this.http.put<void>(`${environment.host + environment.apiEndpoints.subjects.update}/${subject.id}`, subject);
|
return this.http.put<void>(`${environment.host + environment.apiEndpoints.subjects.update}/${subject.id}`, subject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
unlock(id: number): Observable<void> {
|
||||||
|
return this.http.get<void>(`${environment.host + environment.apiEndpoints.subjects.unlock}/${id}`);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,7 +7,8 @@ export const environment = {
|
|||||||
getById: 'api/subjects/get-by-id',
|
getById: 'api/subjects/get-by-id',
|
||||||
delete: 'api/subjects/delete',
|
delete: 'api/subjects/delete',
|
||||||
add: 'api/subjects/add',
|
add: 'api/subjects/add',
|
||||||
update: 'api/subjects/update'
|
update: 'api/subjects/update',
|
||||||
|
unlock: 'api/subjects/unlock'
|
||||||
},
|
},
|
||||||
deleteRequests: {
|
deleteRequests: {
|
||||||
getListByGroupId: 'api/subjectDeleteRequests/list-by-group-id',
|
getListByGroupId: 'api/subjectDeleteRequests/list-by-group-id',
|
||||||
|
Loading…
Reference in New Issue
Block a user