From 1c47280a68abafbf92e00b1393358eabe7957401 Mon Sep 17 00:00:00 2001 From: JakubWalkowiak Date: Tue, 29 Dec 2020 00:18:22 +0100 Subject: [PATCH] fixed problem with group list --- .../group-list/group-list.component.html | 2 +- .../components/group-list/group-list.component.ts | 14 +++++++++++++- .../components/group-main/group-main.component.ts | 4 ++-- .../components/new-group/new-group.component.ts | 9 ++++++--- src/app/group/group-routing.module.ts | 7 +++++-- src/app/group/group.module.ts | 3 ++- .../group/interfaces/group-save-model.interface.ts | 1 + src/app/group/services/group.service.ts | 2 +- .../user/components/register/register.component.ts | 2 +- src/environments/environment.ts | 4 ++-- 10 files changed, 34 insertions(+), 14 deletions(-) diff --git a/src/app/group/components/group-list/group-list.component.html b/src/app/group/components/group-list/group-list.component.html index 18dc4d3..71872f8 100644 --- a/src/app/group/components/group-list/group-list.component.html +++ b/src/app/group/components/group-list/group-list.component.html @@ -1,6 +1,6 @@
-
+
Name: {{ group.name }} diff --git a/src/app/group/components/group-list/group-list.component.ts b/src/app/group/components/group-list/group-list.component.ts index 5ce8060..70e51c3 100644 --- a/src/app/group/components/group-list/group-list.component.ts +++ b/src/app/group/components/group-list/group-list.component.ts @@ -8,13 +8,25 @@ import { Group } from '../../interfaces/group.interface'; }) export class GroupListComponent implements OnInit { - @Input() groups: Group[]; + @Input() set groups(groups) { + if (groups) { + this.groupsObject = groups.map(g => { + g.isUserInGroup = !!g.users.find(u => u.id === localStorage.getItem('userId')); + return g; + }); + } + } @Output() joinRequest = new EventEmitter(); @Output() show = new EventEmitter(); + groupsObject: Group[]; + constructor() { } ngOnInit(): void { + if (!this.groupsObject) { + this.groupsObject = []; + } } onShow(groupId: number): void { diff --git a/src/app/group/components/group-main/group-main.component.ts b/src/app/group/components/group-main/group-main.component.ts index 8ecdbcf..397f1ad 100644 --- a/src/app/group/components/group-main/group-main.component.ts +++ b/src/app/group/components/group-main/group-main.component.ts @@ -25,11 +25,11 @@ export class GroupMainComponent implements OnInit { } onAddNew(): void { - this.router.navigateByUrl('/groups/add-new'); + this.router.navigateByUrl('/group/add-new'); } onShow(groupId: number) { - this.router.navigateByUrl(`/groups/edit/${groupId}`); + this.router.navigateByUrl(`/group/edit/${groupId}`); } onJoinRequest(groupId: number) { diff --git a/src/app/group/components/new-group/new-group.component.ts b/src/app/group/components/new-group/new-group.component.ts index d2012db..004afab 100644 --- a/src/app/group/components/new-group/new-group.component.ts +++ b/src/app/group/components/new-group/new-group.component.ts @@ -1,3 +1,4 @@ +import { Router } from '@angular/router'; import { GroupService } from './../../services/group.service'; import { GroupSaveModel } from './../../interfaces/group-save-model.interface'; import { Component, EventEmitter, OnInit, Output } from '@angular/core'; @@ -12,7 +13,7 @@ export class NewGroupComponent implements OnInit { groupForm: FormGroup; - constructor(private groupService: GroupService) { } + constructor(private groupService: GroupService, private router: Router) { } ngOnInit(): void { this.groupForm = this.createGroupForm(); @@ -30,8 +31,10 @@ export class NewGroupComponent implements OnInit { name: this.groupForm.controls.name.value, year: this.groupForm.controls.year.value, adminId: localStorage.getItem('userId') - } - this.groupService.add(this.groupForm.value); + }; + this.groupService.add(group).subscribe(() => { + this.router.navigateByUrl('/group'); + }); } } diff --git a/src/app/group/group-routing.module.ts b/src/app/group/group-routing.module.ts index e99f6ac..e05f7fb 100644 --- a/src/app/group/group-routing.module.ts +++ b/src/app/group/group-routing.module.ts @@ -1,11 +1,14 @@ import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; +import { GroupMainComponent } from './components/group-main/group-main.component'; +import { GroupEditComponent } from './components/group-edit/group-edit.component'; +import { NewGroupComponent } from './components/new-group/new-group.component'; const routes: Routes = [ { path: '', component: GroupMainComponent }, - { path: 'new-group', component: GroupEditComponent }, - { path: 'edit/:id', component: GrouptEditComponent } + { path: 'add-new', component: NewGroupComponent }, + { path: 'edit/:id', component: GroupEditComponent } ]; @NgModule({ diff --git a/src/app/group/group.module.ts b/src/app/group/group.module.ts index 2d1bbc0..f647f4d 100644 --- a/src/app/group/group.module.ts +++ b/src/app/group/group.module.ts @@ -15,6 +15,7 @@ import { SubjectRoutingModule } from '../subject/subject-routing.module'; import { ReactiveFormsModule } from '@angular/forms'; import { MatCheckboxModule } from '@angular/material/checkbox'; import { MatButtonModule } from '@angular/material/button'; +import { GroupRoutingModule } from './group-routing.module'; @@ -26,7 +27,7 @@ import { MatButtonModule } from '@angular/material/button'; MatTableModule, MatInputModule, MatFormFieldModule, - SubjectRoutingModule, + GroupRoutingModule, ReactiveFormsModule, MatCheckboxModule, MatButtonModule, diff --git a/src/app/group/interfaces/group-save-model.interface.ts b/src/app/group/interfaces/group-save-model.interface.ts index 57530a6..1c14c78 100644 --- a/src/app/group/interfaces/group-save-model.interface.ts +++ b/src/app/group/interfaces/group-save-model.interface.ts @@ -1,3 +1,4 @@ +import { User } from 'src/app/user/interfaces/user.interface'; import { GroupBase } from "./group-base.interface"; export interface GroupSaveModel extends GroupBase { diff --git a/src/app/group/services/group.service.ts b/src/app/group/services/group.service.ts index 8053fda..2dd2d29 100644 --- a/src/app/group/services/group.service.ts +++ b/src/app/group/services/group.service.ts @@ -13,7 +13,7 @@ export class GroupService { constructor(private http: HttpClient) { } add(group: GroupSaveModel): Observable { - return this.http.post(environment.host + environment.apiEndpoints.groups, group); + return this.http.post(environment.host + environment.apiEndpoints.groups.add, group); } getAllGroups(): Observable { diff --git a/src/app/user/components/register/register.component.ts b/src/app/user/components/register/register.component.ts index 7562a81..d2e680c 100644 --- a/src/app/user/components/register/register.component.ts +++ b/src/app/user/components/register/register.component.ts @@ -43,7 +43,7 @@ export class RegisterComponent implements OnInit { userName: this.registerForm.get('userName').value, fullName: this.registerForm.get('fullName').value, password: this.registerForm.get(['passwordForm', 'password']).value - } + }; this.userSerice.register(user).subscribe(() => { this.router.navigateByUrl('/user/login'); }); diff --git a/src/environments/environment.ts b/src/environments/environment.ts index fb6177b..4999794 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -20,10 +20,10 @@ export const environment = { login: 'api/users/login' }, groups: { - getAll: 'api/groups/all', + getAll: 'api/groups/list', getById: 'api/groups/get-by-id', getCurrentUserGroups: 'api/groups/current-user-groups', - create: 'api/groups/create', + add: 'api/groups/add', delete: 'api/groups/delete', leave: 'api/groups/leave' },