added main group list

This commit is contained in:
Jakub Walkowiak 2020-12-21 23:12:12 +01:00
parent 23d22b00e5
commit 86f2d02a26
18 changed files with 282 additions and 0 deletions

View File

@ -0,0 +1 @@
<p>group-edit works!</p>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupEditComponent } from './group-edit.component';
describe('GroupEditComponent', () => {
let component: GroupEditComponent;
let fixture: ComponentFixture<GroupEditComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GroupEditComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupEditComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,15 @@
import { Component, OnInit } from '@angular/core';
@Component({
selector: 'app-group-edit',
templateUrl: './group-edit.component.html',
styleUrls: ['./group-edit.component.scss']
})
export class GroupEditComponent implements OnInit {
constructor() { }
ngOnInit(): void {
}
}

View File

@ -0,0 +1,21 @@
<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 class="subject-data">
<div>
Name: {{ group.name }}
</div>
<div>
Year: {{ group.year }}
</div>
<div>
Admin: {{ group.admin.fullName }} ({{group.admin.userName}})
</div>
</div>
<div class="group-buttons d-flex align-items-center">
<button *ngIf="group.isUserInGroup" (click)="onShow(group.id)" class="btn btn-primary">Show</button>
<button *ngIf="!group.isUserInGroup" (click)="onJoinRequest(group.id)" class="btn btn-primary">Send join request</button>
</div>
</div>
</div>
</div>

View File

@ -0,0 +1,5 @@
.list-container {
.group-list-item {
border: 1px solid black;
}
}

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupListComponent } from './group-list.component';
describe('GroupListComponent', () => {
let component: GroupListComponent;
let fixture: ComponentFixture<GroupListComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GroupListComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupListComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,28 @@
import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core';
import { Group } from '../../interfaces/group.interface';
@Component({
selector: 'app-group-list',
templateUrl: './group-list.component.html',
styleUrls: ['./group-list.component.scss']
})
export class GroupListComponent implements OnInit {
@Input() groups: Group[];
@Output() joinRequest = new EventEmitter<number>();
@Output() show = new EventEmitter<number>();
constructor() { }
ngOnInit(): void {
}
onShow(groupId: number): void {
this.show.emit(groupId);
}
onJoinRequest(groupId: number): void {
this.joinRequest.emit(groupId);
}
}

View File

@ -0,0 +1,18 @@
<div class="d-flex justify-content-end">
<button (click)="onAddNew()" class="btn btn-primary mb-3">Add new group</button>
</div>
<mat-tab-group>
<mat-tab label="My groups">
<app-group-list
[groups]="userGroups"
(show)="onShow($event)">
</app-group-list>
</mat-tab>
<mat-tab label="All groups">
<app-group-list
[groups]="allGroups"
(joinRequest)="onJoinRequest($event)"
(show)="onShow($event)">
</app-group-list>
</mat-tab>
</mat-tab-group>

View File

@ -0,0 +1,25 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { GroupMainComponent } from './group-main.component';
describe('GroupMainComponent', () => {
let component: GroupMainComponent;
let fixture: ComponentFixture<GroupMainComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ GroupMainComponent ]
})
.compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(GroupMainComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
});

View File

@ -0,0 +1,32 @@
import { GroupService } from './../../services/group.service';
import { Component, OnInit } from '@angular/core';
import { Group } from '../../interfaces/group.interface';
@Component({
selector: 'app-group-main',
templateUrl: './group-main.component.html',
styleUrls: ['./group-main.component.scss']
})
export class GroupMainComponent implements OnInit {
userGroups: Group[];
allGroups: Group[];
constructor(private groupService: GroupService) { }
ngOnInit(): void {
}
onAddNew(): void {
}
onShow(groupId: number) {
}
onJoinRequest(groupId: number) {
}
}

View File

@ -0,0 +1,15 @@
import { NgModule } from '@angular/core';
import { Routes, RouterModule } from '@angular/router';
const routes: Routes = [
{ path: '', component: GroupMainComponent },
{ path: 'new-group', component: GroupEditComponent },
{ path: 'edit/:id', component: GrouptEditComponent }
];
@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class GroupRoutingModule { }

View File

@ -0,0 +1,17 @@
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { GroupMainComponent } from './components/group-main/group-main.component';
import { GroupListComponent } from './components/group-list/group-list.component';
import { GroupEditComponent } from './components/group-edit/group-edit.component';
import {MatTabsModule} from '@angular/material/tabs';
@NgModule({
declarations: [GroupMainComponent, GroupListComponent, GroupEditComponent],
imports: [
CommonModule,
MatTabsModule,
]
})
export class GroupModule { }

View File

@ -0,0 +1,11 @@
import { User } from "src/app/user/interfaces/user.interface";
export interface Group {
id: number;
name: string;
year: number;
admin: User;
users: User[];
userCandidates: User[];
isUserInGroup?: boolean;
}

View File

@ -0,0 +1,16 @@
import { TestBed } from '@angular/core/testing';
import { GroupService } from './group.service';
describe('GroupService', () => {
let service: GroupService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(GroupService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});

View File

@ -0,0 +1,22 @@
import { Observable } from 'rxjs';
import { Injectable } from '@angular/core';
import { environment } from 'src/environments/environment';
import { Group } from '../interfaces/group.interface';
import { HttpClient } from '@angular/common/http';
@Injectable({
providedIn: 'root'
})
export class GroupService {
constructor(private http: HttpClient) { }
add(group: Group): Observable<void> {
return this.http.post<void>(environment.host + environment.apiEndpoints.groups, group);
}
getAllGroups(): Observable<Group[]> {
return this.http.get<Group[]>(environment.host + environment.apiEndpoints.groups.getAll);
}
}

View File

@ -12,6 +12,12 @@ export const environment = {
users: {
register: 'api/users/register',
login: 'api/users/login'
},
groups: {
getAll: 'api/groups/all',
getUserGroups: 'api/groups/user-groups',
create: 'api/groups/create',
delete: 'api/groups/delete'
}
}
};