From 50a73f50ef362a3d61d0e89c862a509b60ee86a6 Mon Sep 17 00:00:00 2001 From: JakubWalkowiak Date: Wed, 30 Dec 2020 00:29:15 +0100 Subject: [PATCH] fixes in groups --- .../group-edit/group-edit.component.html | 4 +-- .../group-edit/group-edit.component.ts | 5 ++++ src/app/group/group-routing.module.ts | 13 +++++++-- .../group/services/group-candidate.service.ts | 2 +- .../subject-main/subject-main.component.scss | 3 ++ src/app/subject/subject-routing.module.ts | 13 +++++++-- .../user/components/base/base.component.html | 5 ++++ .../user/components/base/base.component.scss | 0 .../components/base/base.component.spec.ts | 25 ++++++++++++++++ .../user/components/base/base.component.ts | 29 +++++++++++++++++++ src/app/user/user.module.ts | 6 +++- src/environments/environment.ts | 6 ++-- 12 files changed, 98 insertions(+), 13 deletions(-) create mode 100644 src/app/user/components/base/base.component.html create mode 100644 src/app/user/components/base/base.component.scss create mode 100644 src/app/user/components/base/base.component.spec.ts create mode 100644 src/app/user/components/base/base.component.ts diff --git a/src/app/group/components/group-edit/group-edit.component.html b/src/app/group/components/group-edit/group-edit.component.html index 8058aa2..a2adfa4 100644 --- a/src/app/group/components/group-edit/group-edit.component.html +++ b/src/app/group/components/group-edit/group-edit.component.html @@ -23,9 +23,9 @@

Users:

-
+

Group candidates:

- +
diff --git a/src/app/group/components/group-edit/group-edit.component.ts b/src/app/group/components/group-edit/group-edit.component.ts index 358ebec..50b7c88 100644 --- a/src/app/group/components/group-edit/group-edit.component.ts +++ b/src/app/group/components/group-edit/group-edit.component.ts @@ -1,8 +1,10 @@ +import { GroupCandidateService } from './../../services/group-candidate.service'; import { Router, ActivatedRoute } from '@angular/router'; import { GroupService } from './../../services/group.service'; import { Component, OnInit } from '@angular/core'; import { Group } from '../../interfaces/group.interface'; import { Observable } from 'rxjs'; +import { User } from 'src/app/user/interfaces/user.interface'; @Component({ selector: 'app-group-edit', @@ -12,10 +14,12 @@ import { Observable } from 'rxjs'; export class GroupEditComponent implements OnInit { group$: Observable; + groupCandidates$: Observable; userId: string; groupId: number; constructor(private groupService: GroupService, + private groupCandidateService: GroupCandidateService, private activatedRoute: ActivatedRoute, private router: Router) { } @@ -23,6 +27,7 @@ export class GroupEditComponent implements OnInit { this.userId = localStorage.getItem('userId'); this.groupId = this.activatedRoute.snapshot.params['groupId']; this.group$ = this.groupService.getGroup(this.groupId); + this.groupCandidates$ = this.groupCandidateService.getList(this.groupId); } onDelete(): void { diff --git a/src/app/group/group-routing.module.ts b/src/app/group/group-routing.module.ts index 91e92f3..1afb715 100644 --- a/src/app/group/group-routing.module.ts +++ b/src/app/group/group-routing.module.ts @@ -1,3 +1,4 @@ +import { BaseComponent } from './../user/components/base/base.component'; import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; import { GroupMainComponent } from './components/group-main/group-main.component'; @@ -6,9 +7,15 @@ import { NewGroupComponent } from './components/new-group/new-group.component'; const routes: Routes = [ - { path: '', component: GroupMainComponent }, - { path: 'add-new', component: NewGroupComponent }, - { path: 'edit/:groupId', component: GroupEditComponent } + { + path: '', + component: BaseComponent, + children: [ + { path: '', component: GroupMainComponent }, + { path: 'add-new', component: NewGroupComponent }, + { path: 'edit/:groupId', component: GroupEditComponent } + ] + } ]; @NgModule({ diff --git a/src/app/group/services/group-candidate.service.ts b/src/app/group/services/group-candidate.service.ts index 81c9b64..319379d 100644 --- a/src/app/group/services/group-candidate.service.ts +++ b/src/app/group/services/group-candidate.service.ts @@ -20,7 +20,7 @@ export class GroupCandidateService { const joinRequest: JoinRequest = { groupId, userId: localStorage.getItem('userId') - } + }; return this.http.post(environment.host + environment.apiEndpoints.groupCandidates.joinRequest, joinRequest); } diff --git a/src/app/subject/components/subject-main/subject-main.component.scss b/src/app/subject/components/subject-main/subject-main.component.scss index e69de29..0abf944 100644 --- a/src/app/subject/components/subject-main/subject-main.component.scss +++ b/src/app/subject/components/subject-main/subject-main.component.scss @@ -0,0 +1,3 @@ +h3 { + font-weight: 500; +} \ No newline at end of file diff --git a/src/app/subject/subject-routing.module.ts b/src/app/subject/subject-routing.module.ts index 0f2afd0..fc138fc 100644 --- a/src/app/subject/subject-routing.module.ts +++ b/src/app/subject/subject-routing.module.ts @@ -1,3 +1,4 @@ +import { BaseComponent } from './../user/components/base/base.component'; import { SubjectMainComponent } from './components/subject-main/subject-main.component'; import { NgModule } from '@angular/core'; import { Routes, RouterModule } from '@angular/router'; @@ -5,9 +6,15 @@ import { SubjectEditComponent } from './components/subject-edit/subject-edit.com const routes: Routes = [ - { path: '', component: SubjectMainComponent }, - { path: 'new-subject/:groupId', component: SubjectEditComponent }, - { path: 'edit/:id/:groupId', component: SubjectEditComponent } + { + path: '', + component: BaseComponent, + children: [ + { path: '', component: SubjectMainComponent }, + { path: 'new-subject/:groupId', component: SubjectEditComponent }, + { path: 'edit/:id/:groupId', component: SubjectEditComponent } + ] + } ]; @NgModule({ diff --git a/src/app/user/components/base/base.component.html b/src/app/user/components/base/base.component.html new file mode 100644 index 0000000..ad1b652 --- /dev/null +++ b/src/app/user/components/base/base.component.html @@ -0,0 +1,5 @@ + + diff --git a/src/app/user/components/base/base.component.scss b/src/app/user/components/base/base.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/src/app/user/components/base/base.component.spec.ts b/src/app/user/components/base/base.component.spec.ts new file mode 100644 index 0000000..5fb761d --- /dev/null +++ b/src/app/user/components/base/base.component.spec.ts @@ -0,0 +1,25 @@ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BaseComponent } from './base.component'; + +describe('BaseComponent', () => { + let component: BaseComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [ BaseComponent ] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(BaseComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/user/components/base/base.component.ts b/src/app/user/components/base/base.component.ts new file mode 100644 index 0000000..be9c012 --- /dev/null +++ b/src/app/user/components/base/base.component.ts @@ -0,0 +1,29 @@ +import { Router } from '@angular/router'; +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-base', + templateUrl: './base.component.html', + styleUrls: ['./base.component.scss'] +}) +export class BaseComponent implements OnInit { + + userName: string; + fullName: string; + + constructor(private router: Router) { } + + ngOnInit(): void { + this.userName = localStorage.getItem('userName'); + this.fullName = localStorage.getItem('fullName'); + } + + onLogout(): void { + localStorage.setItem('token', ''); + localStorage.setItem('userId', ''); + localStorage.setItem('userName', ''); + localStorage.setItem('fullName', ''); + this.router.navigateByUrl('/'); + } + +} diff --git a/src/app/user/user.module.ts b/src/app/user/user.module.ts index 331aec1..cc51447 100644 --- a/src/app/user/user.module.ts +++ b/src/app/user/user.module.ts @@ -6,17 +6,21 @@ import { LoginComponent } from './components/login/login.component'; import { ReactiveFormsModule } from '@angular/forms'; import { MatFormFieldModule } from '@angular/material/form-field'; import { UserRoutingModule } from './user-routing.module'; +import { BaseComponent } from './components/base/base.component'; @NgModule({ - declarations: [RegisterComponent, LoginComponent], + declarations: [RegisterComponent, LoginComponent, BaseComponent], imports: [ CommonModule, ReactiveFormsModule, MatFormFieldModule, MatInputModule, UserRoutingModule + ], + exports: [ + BaseComponent ] }) export class UserModule { } diff --git a/src/environments/environment.ts b/src/environments/environment.ts index 4999794..83bccd4 100644 --- a/src/environments/environment.ts +++ b/src/environments/environment.ts @@ -28,9 +28,9 @@ export const environment = { leave: 'api/groups/leave' }, groupCandidates: { - getList: 'api/group-candidates/list', - joinRequest: 'api/group-candidates/join-request', - delete: 'api/group-candidates/delete' + getList: 'api/groupCandidates/list', + joinRequest: 'api/groupCandidates/join-request', + delete: 'api/groupCandidates/delete' } } };