fixed problem with group list
This commit is contained in:
parent
0ec6d1821d
commit
1c47280a68
@ -1,6 +1,6 @@
|
|||||||
<div class="list-container mt-5">
|
<div class="list-container mt-5">
|
||||||
<div>
|
<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 class="subject-data">
|
||||||
<div>
|
<div>
|
||||||
Name: {{ group.name }}
|
Name: {{ group.name }}
|
||||||
|
@ -8,13 +8,25 @@ import { Group } from '../../interfaces/group.interface';
|
|||||||
})
|
})
|
||||||
export class GroupListComponent implements OnInit {
|
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() joinRequest = new EventEmitter<number>();
|
||||||
@Output() show = new EventEmitter<number>();
|
@Output() show = new EventEmitter<number>();
|
||||||
|
|
||||||
|
groupsObject: Group[];
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
|
if (!this.groupsObject) {
|
||||||
|
this.groupsObject = [];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
onShow(groupId: number): void {
|
onShow(groupId: number): void {
|
||||||
|
@ -25,11 +25,11 @@ export class GroupMainComponent implements OnInit {
|
|||||||
}
|
}
|
||||||
|
|
||||||
onAddNew(): void {
|
onAddNew(): void {
|
||||||
this.router.navigateByUrl('/groups/add-new');
|
this.router.navigateByUrl('/group/add-new');
|
||||||
}
|
}
|
||||||
|
|
||||||
onShow(groupId: number) {
|
onShow(groupId: number) {
|
||||||
this.router.navigateByUrl(`/groups/edit/${groupId}`);
|
this.router.navigateByUrl(`/group/edit/${groupId}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
onJoinRequest(groupId: number) {
|
onJoinRequest(groupId: number) {
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { Router } from '@angular/router';
|
||||||
import { GroupService } from './../../services/group.service';
|
import { GroupService } from './../../services/group.service';
|
||||||
import { GroupSaveModel } from './../../interfaces/group-save-model.interface';
|
import { GroupSaveModel } from './../../interfaces/group-save-model.interface';
|
||||||
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
import { Component, EventEmitter, OnInit, Output } from '@angular/core';
|
||||||
@ -12,7 +13,7 @@ export class NewGroupComponent implements OnInit {
|
|||||||
|
|
||||||
groupForm: FormGroup;
|
groupForm: FormGroup;
|
||||||
|
|
||||||
constructor(private groupService: GroupService) { }
|
constructor(private groupService: GroupService, private router: Router) { }
|
||||||
|
|
||||||
ngOnInit(): void {
|
ngOnInit(): void {
|
||||||
this.groupForm = this.createGroupForm();
|
this.groupForm = this.createGroupForm();
|
||||||
@ -30,8 +31,10 @@ export class NewGroupComponent implements OnInit {
|
|||||||
name: this.groupForm.controls.name.value,
|
name: this.groupForm.controls.name.value,
|
||||||
year: this.groupForm.controls.year.value,
|
year: this.groupForm.controls.year.value,
|
||||||
adminId: localStorage.getItem('userId')
|
adminId: localStorage.getItem('userId')
|
||||||
}
|
};
|
||||||
this.groupService.add(this.groupForm.value);
|
this.groupService.add(group).subscribe(() => {
|
||||||
|
this.router.navigateByUrl('/group');
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,14 @@
|
|||||||
import { NgModule } from '@angular/core';
|
import { NgModule } from '@angular/core';
|
||||||
import { Routes, RouterModule } from '@angular/router';
|
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 = [
|
const routes: Routes = [
|
||||||
{ path: '', component: GroupMainComponent },
|
{ path: '', component: GroupMainComponent },
|
||||||
{ path: 'new-group', component: GroupEditComponent },
|
{ path: 'add-new', component: NewGroupComponent },
|
||||||
{ path: 'edit/:id', component: GrouptEditComponent }
|
{ path: 'edit/:id', component: GroupEditComponent }
|
||||||
];
|
];
|
||||||
|
|
||||||
@NgModule({
|
@NgModule({
|
||||||
|
@ -15,6 +15,7 @@ import { SubjectRoutingModule } from '../subject/subject-routing.module';
|
|||||||
import { ReactiveFormsModule } from '@angular/forms';
|
import { ReactiveFormsModule } from '@angular/forms';
|
||||||
import { MatCheckboxModule } from '@angular/material/checkbox';
|
import { MatCheckboxModule } from '@angular/material/checkbox';
|
||||||
import { MatButtonModule } from '@angular/material/button';
|
import { MatButtonModule } from '@angular/material/button';
|
||||||
|
import { GroupRoutingModule } from './group-routing.module';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -26,7 +27,7 @@ import { MatButtonModule } from '@angular/material/button';
|
|||||||
MatTableModule,
|
MatTableModule,
|
||||||
MatInputModule,
|
MatInputModule,
|
||||||
MatFormFieldModule,
|
MatFormFieldModule,
|
||||||
SubjectRoutingModule,
|
GroupRoutingModule,
|
||||||
ReactiveFormsModule,
|
ReactiveFormsModule,
|
||||||
MatCheckboxModule,
|
MatCheckboxModule,
|
||||||
MatButtonModule,
|
MatButtonModule,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import { User } from 'src/app/user/interfaces/user.interface';
|
||||||
import { GroupBase } from "./group-base.interface";
|
import { GroupBase } from "./group-base.interface";
|
||||||
|
|
||||||
export interface GroupSaveModel extends GroupBase {
|
export interface GroupSaveModel extends GroupBase {
|
||||||
|
@ -13,7 +13,7 @@ export class GroupService {
|
|||||||
constructor(private http: HttpClient) { }
|
constructor(private http: HttpClient) { }
|
||||||
|
|
||||||
add(group: GroupSaveModel): Observable<void> {
|
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[]> {
|
getAllGroups(): Observable<Group[]> {
|
||||||
|
@ -43,7 +43,7 @@ export class RegisterComponent implements OnInit {
|
|||||||
userName: this.registerForm.get('userName').value,
|
userName: this.registerForm.get('userName').value,
|
||||||
fullName: this.registerForm.get('fullName').value,
|
fullName: this.registerForm.get('fullName').value,
|
||||||
password: this.registerForm.get(['passwordForm', 'password']).value
|
password: this.registerForm.get(['passwordForm', 'password']).value
|
||||||
}
|
};
|
||||||
this.userSerice.register(user).subscribe(() => {
|
this.userSerice.register(user).subscribe(() => {
|
||||||
this.router.navigateByUrl('/user/login');
|
this.router.navigateByUrl('/user/login');
|
||||||
});
|
});
|
||||||
|
@ -20,10 +20,10 @@ export const environment = {
|
|||||||
login: 'api/users/login'
|
login: 'api/users/login'
|
||||||
},
|
},
|
||||||
groups: {
|
groups: {
|
||||||
getAll: 'api/groups/all',
|
getAll: 'api/groups/list',
|
||||||
getById: 'api/groups/get-by-id',
|
getById: 'api/groups/get-by-id',
|
||||||
getCurrentUserGroups: 'api/groups/current-user-groups',
|
getCurrentUserGroups: 'api/groups/current-user-groups',
|
||||||
create: 'api/groups/create',
|
add: 'api/groups/add',
|
||||||
delete: 'api/groups/delete',
|
delete: 'api/groups/delete',
|
||||||
leave: 'api/groups/leave'
|
leave: 'api/groups/leave'
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user