fixed problems with groups

This commit is contained in:
JakubWalkowiak 2020-12-29 22:56:35 +01:00
parent 1c47280a68
commit 0c2f63c57a
15 changed files with 87 additions and 50 deletions

View File

@ -1,4 +1,4 @@
<div class="list-container mt-5"> <div class="list-container">
<div> <div>
<div *ngFor="let candidate of candidates" class="group-list-item d-flex justify-content-between mb-2 p-3"> <div *ngFor="let candidate of candidates" class="group-list-item d-flex justify-content-between mb-2 p-3">
<div class="subject-data"> <div class="subject-data">

View File

@ -1,9 +1,11 @@
<div *ngIf="group$ | async as group"> <div *ngIf="group$ | async as group" class="mt-5 d-flex justify-content-center">
<div> <div class="edit-group-wrapper">
<div class="d-flex justify-content-end">
<button *ngIf="group.admin.id === userId" (click)="onDelete()" class="btn btn-primary">Delete group</button> <button *ngIf="group.admin.id === userId" (click)="onDelete()" class="btn btn-primary">Delete group</button>
<button *ngIf="group.admin.id !== userId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button> <button *ngIf="group.admin.id !== userId" (click)="onLeaveGroup()" class="btn btn-primary">Leave group</button>
</div> </div>
<div class="group-main-data"> <div class="group-main-data mb-5">
<h3>Group info:</h3>
<div> <div>
Name: {{ group.name }} Name: {{ group.name }}
</div> </div>
@ -14,7 +16,16 @@
Admin: {{ group.admin.fullName }} ({{group.admin.userName}}) Admin: {{ group.admin.fullName }} ({{group.admin.userName}})
</div> </div>
</div> </div>
<app-subject-list></app-subject-list> <div class="mb-5 border p-3">
<app-subject-main [groupId]="groupId" [adminId]="group.admin.id"></app-subject-main>
</div>
<div class="mb-5 border p-3">
<h3>Users:</h3>
<app-group-users [groupUsers]="group.users"></app-group-users> <app-group-users [groupUsers]="group.users"></app-group-users>
</div>
<div *ngIf="group.admin.id === userId && group.userCandidates" class="mb-5 border p-3">
<h3>Group candidates:</h3>
<app-group-candidates [candidates]="group.userCandidates"></app-group-candidates> <app-group-candidates [candidates]="group.userCandidates"></app-group-candidates>
</div>
</div>
</div> </div>

View File

@ -0,0 +1,7 @@
h3 {
font-weight: 500;
}
.edit-group-wrapper {
width: 80%;
}

View File

@ -1,4 +1,4 @@
import { ActivatedRouteSnapshot, Router } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { GroupService } from './../../services/group.service'; import { GroupService } from './../../services/group.service';
import { Component, OnInit } from '@angular/core'; import { Component, OnInit } from '@angular/core';
import { Group } from '../../interfaces/group.interface'; import { Group } from '../../interfaces/group.interface';
@ -16,12 +16,12 @@ export class GroupEditComponent implements OnInit {
groupId: number; groupId: number;
constructor(private groupService: GroupService, constructor(private groupService: GroupService,
private activatedRouteSnapshot: ActivatedRouteSnapshot, private activatedRoute: ActivatedRoute,
private router: Router) { } private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
this.userId = localStorage.getItem('userId'); this.userId = localStorage.getItem('userId');
this.groupId = this.activatedRouteSnapshot.params['groupId']; this.groupId = this.activatedRoute.snapshot.params['groupId'];
this.group$ = this.groupService.getGroup(this.groupId); this.group$ = this.groupService.getGroup(this.groupId);
} }

View File

@ -1,4 +1,4 @@
<div class="list-container mt-5"> <div class="list-container">
<div> <div>
<div *ngFor="let group of groupsObject" class="group-list-item d-flex justify-content-between mb-2 p-3"> <div *ngFor="let group of groupsObject" class="group-list-item d-flex justify-content-between mb-2 p-3">
<div class="subject-data"> <div class="subject-data">

View File

@ -1,4 +1,4 @@
<div class="list-container mt-5"> <div class="list-container">
<div> <div>
<div *ngFor="let user of groupUsers" class="group-list-item d-flex justify-content-between mb-2 p-3"> <div *ngFor="let user of groupUsers" class="group-list-item d-flex justify-content-between mb-2 p-3">
<div class="subject-data"> <div class="subject-data">

View File

@ -8,7 +8,7 @@ import { NewGroupComponent } from './components/new-group/new-group.component';
const routes: Routes = [ const routes: Routes = [
{ path: '', component: GroupMainComponent }, { path: '', component: GroupMainComponent },
{ path: 'add-new', component: NewGroupComponent }, { path: 'add-new', component: NewGroupComponent },
{ path: 'edit/:id', component: GroupEditComponent } { path: 'edit/:groupId', component: GroupEditComponent }
]; ];
@NgModule({ @NgModule({

View File

@ -17,12 +17,14 @@ export class SubjectEditComponent implements OnInit {
subject: Subject; subject: Subject;
subjectForm: FormGroup; subjectForm: FormGroup;
subjectId: number; subjectId: number;
groupId: number;
constructor(private activatedRoute: ActivatedRoute, constructor(private activatedRoute: ActivatedRoute,
private subjectService: SubjectService, private subjectService: SubjectService,
private router: Router) { } private router: Router) { }
ngOnInit(): void { ngOnInit(): void {
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;
@ -37,6 +39,7 @@ export class SubjectEditComponent implements OnInit {
createEmptySubject(): Subject { createEmptySubject(): Subject {
return { return {
id: null, id: null,
groupId: this.groupId,
name: '', name: '',
lectureTeacher: '', lectureTeacher: '',
labTeacher: '', labTeacher: '',
@ -51,6 +54,7 @@ export class SubjectEditComponent implements OnInit {
createSubjectForm(): FormGroup { createSubjectForm(): FormGroup {
return new FormGroup({ return new FormGroup({
id: new FormControl(null), id: new FormControl(null),
groupId: new FormControl(this.groupId),
name: new FormControl('', Validators.required), name: new FormControl('', Validators.required),
lectureTeacher: new FormControl(''), lectureTeacher: new FormControl(''),
labTeacher: new FormControl(''), labTeacher: new FormControl(''),
@ -138,11 +142,11 @@ export class SubjectEditComponent implements OnInit {
onSubjectSave(): void { onSubjectSave(): void {
if (this.subjectId) { if (this.subjectId) {
this.subjectService.update(this.subjectForm.value).subscribe(() => { this.subjectService.update(this.subjectForm.value).subscribe(() => {
this.router.navigateByUrl('/'); this.router.navigateByUrl('/group/edit/' + this.groupId);
}); });
} else { } else {
this.subjectService.add(this.subjectForm.value).subscribe(() => { this.subjectService.add(this.subjectForm.value).subscribe(() => {
this.router.navigateByUrl('/'); this.router.navigateByUrl('/group/edit/' + this.groupId);
}); });
} }
} }

View File

@ -1,4 +1,4 @@
<div class="list-container mt-5"> <div class="list-container">
<div class="d-flex justify-content-end"> <div class="d-flex justify-content-end">
<button (click)="onAddNew()" class="btn btn-primary mb-3">Add new</button> <button (click)="onAddNew()" class="btn btn-primary mb-3">Add new</button>
</div> </div>
@ -23,8 +23,8 @@
</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 (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 (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>
</div> </div>
</div> </div>

View File

@ -9,6 +9,8 @@ import { Subject } from '../../interfaces/subject.interface';
export class ListComponent implements OnInit { export class ListComponent implements OnInit {
@Input() subjects: Subject[]; @Input() subjects: Subject[];
@Input() userId: string;
@Input() adminId: string;
@Output() deleteRequest = new EventEmitter<number>(); @Output() deleteRequest = new EventEmitter<number>();
@Output() deleteSubject = new EventEmitter<number>(); @Output() deleteSubject = new EventEmitter<number>();
@Output() addNewSubject = new EventEmitter<void>(); @Output() addNewSubject = new EventEmitter<void>();

View File

@ -1,16 +1,28 @@
<div class="d-flex justify-content-center"> <div>
<div class="lists-container"> <div>
<div>
<h3>Subjects:</h3>
<app-subject-list <app-subject-list
[subjects]="subjects$ | async" [subjects]="subjects$ | async"
[userId]="userId"
[adminId]="adminId"
(addNewSubject)="onAddNewSubject()" (addNewSubject)="onAddNewSubject()"
(deleteRequest)="onAddDeleteRequest($event)" (deleteRequest)="onAddDeleteRequest($event)"
(deleteSubject)="onDeleteSubject($event)" (deleteSubject)="onDeleteSubject($event)"
(editSubject)="onEditSubject($event)"> (editSubject)="onEditSubject($event)">
</app-subject-list> </app-subject-list>
</div>
<div *ngIf="userId === adminId">
<div *ngIf="subjectDeleteRequests$ | async as subjectDeleteRequests">
<div *ngIf="subjectDeleteRequests.length > 0">
<h3>Subjects delete requests:</h3>
<app-subject-delete-request-list <app-subject-delete-request-list
[subjectDeleteRequests]="subjectDeleteRequests$ | async" [subjectDeleteRequests]="subjectDeleteRequests"
(approveDeletion)="onApproveDeletion($event)" (approveDeletion)="onApproveDeletion($event)"
(cancelDeletion)="onCancelDeletion($event)"> (cancelDeletion)="onCancelDeletion($event)">
</app-subject-delete-request-list> </app-subject-delete-request-list>
</div> </div>
</div>
</div>
</div>
</div> </div>

View File

@ -1,3 +0,0 @@
.lists-container {
width: 80%;
}

View File

@ -14,6 +14,8 @@ import { Router } from '@angular/router';
export class SubjectMainComponent implements OnInit { export class SubjectMainComponent implements OnInit {
@Input() groupId: number; @Input() groupId: number;
@Input() adminId: string;
userId: string;
subjects$: Observable<Subject[]>; subjects$: Observable<Subject[]>;
subjectDeleteRequests$: Observable<SubjectDeleteRequest[]>; subjectDeleteRequests$: Observable<SubjectDeleteRequest[]>;
@ -22,12 +24,13 @@ export class SubjectMainComponent implements OnInit {
private subjectDeleteRequestService: SubjectDeleteRequestService) { } private subjectDeleteRequestService: SubjectDeleteRequestService) { }
ngOnInit(): void { ngOnInit(): void {
this.subjects$ = this.subjectService.getListByGroupId(Number(localStorage.getItem('userId'))); this.userId = localStorage.getItem('userId');
this.subjects$ = this.subjectService.getListByGroupId(Number(this.groupId));
this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId); this.subjectDeleteRequests$ = this.subjectDeleteRequestService.getListByGroupId(this.groupId);
} }
onAddNewSubject(): void { onAddNewSubject(): void {
this.router.navigateByUrl('/new-subject'); this.router.navigateByUrl('/subject/new-subject/' + this.groupId);
} }
onApproveDeletion(deletionRequestId: number): void { onApproveDeletion(deletionRequestId: number): void {
@ -60,7 +63,7 @@ export class SubjectMainComponent implements OnInit {
} }
onEditSubject(id: number): void { onEditSubject(id: number): void {
this.router.navigateByUrl(`/edit/${id}`); this.router.navigateByUrl(`subject/edit/${id}/${this.groupId}`);
} }
} }

View File

@ -4,6 +4,7 @@ import { Comment } from './comment.interface';
export interface Subject { export interface Subject {
id?: number; id?: number;
groupId?: number;
name: string; name: string;
lectureTeacher: string; lectureTeacher: string;
labTeacher: string; labTeacher: string;

View File

@ -6,8 +6,8 @@ import { SubjectEditComponent } from './components/subject-edit/subject-edit.com
const routes: Routes = [ const routes: Routes = [
{ path: '', component: SubjectMainComponent }, { path: '', component: SubjectMainComponent },
{ path: 'new-subject', component: SubjectEditComponent }, { path: 'new-subject/:groupId', component: SubjectEditComponent },
{ path: 'edit/:id', component: SubjectEditComponent } { path: 'edit/:id/:groupId', component: SubjectEditComponent }
]; ];
@NgModule({ @NgModule({