fixed problem with group list

This commit is contained in:
JakubWalkowiak 2020-12-29 00:18:22 +01:00
parent 0ec6d1821d
commit 1c47280a68
10 changed files with 34 additions and 14 deletions

View File

@ -1,6 +1,6 @@
<div class="list-container mt-5">
<div>
<div *ngFor="let group of groups" 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>
Name: {{ group.name }}

View File

@ -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<number>();
@Output() show = new EventEmitter<number>();
groupsObject: Group[];
constructor() { }
ngOnInit(): void {
if (!this.groupsObject) {
this.groupsObject = [];
}
}
onShow(groupId: number): void {

View File

@ -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) {

View File

@ -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');
});
}
}

View File

@ -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({

View File

@ -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,

View File

@ -1,3 +1,4 @@
import { User } from 'src/app/user/interfaces/user.interface';
import { GroupBase } from "./group-base.interface";
export interface GroupSaveModel extends GroupBase {

View File

@ -13,7 +13,7 @@ export class GroupService {
constructor(private http: HttpClient) { }
add(group: GroupSaveModel): Observable<void> {
return this.http.post<void>(environment.host + environment.apiEndpoints.groups, group);
return this.http.post<void>(environment.host + environment.apiEndpoints.groups.add, group);
}
getAllGroups(): Observable<Group[]> {

View File

@ -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');
});

View File

@ -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'
},