From 9530d1b57f4ff4a7af36a485bbe26cb3a7f481a9 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Sat, 19 Mar 2022 19:55:42 +0100 Subject: [PATCH 1/8] Add profile and settings page placeholders; Expand routing --- .../bot-settings/bot-settings.component.html | 1 + .../bot-settings/bot-settings.component.scss | 0 .../bot-settings.component.spec.ts | 25 +++++++++++++++++++ .../bot-settings/bot-settings.component.ts | 15 +++++++++++ .../app/Views/header/header.component.html | 11 ++++++++ .../app/Views/profile/profile.component.html | 1 + .../app/Views/profile/profile.component.scss | 0 .../Views/profile/profile.component.spec.ts | 25 +++++++++++++++++++ .../app/Views/profile/profile.component.ts | 15 +++++++++++ frontend/src/app/app-routing.module.ts | 9 +++++++ frontend/src/app/app.component.ts | 22 ++++++++-------- frontend/src/app/app.module.ts | 6 +++++ 12 files changed, 119 insertions(+), 11 deletions(-) create mode 100644 frontend/src/app/Views/bot-settings/bot-settings.component.html create mode 100644 frontend/src/app/Views/bot-settings/bot-settings.component.scss create mode 100644 frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts create mode 100644 frontend/src/app/Views/bot-settings/bot-settings.component.ts create mode 100644 frontend/src/app/Views/profile/profile.component.html create mode 100644 frontend/src/app/Views/profile/profile.component.scss create mode 100644 frontend/src/app/Views/profile/profile.component.spec.ts create mode 100644 frontend/src/app/Views/profile/profile.component.ts diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.html b/frontend/src/app/Views/bot-settings/bot-settings.component.html new file mode 100644 index 0000000..58d7a42 --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.html @@ -0,0 +1 @@ +

bot-settings works!

diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.scss b/frontend/src/app/Views/bot-settings/bot-settings.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts b/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts new file mode 100644 index 0000000..7fb7c50 --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { BotSettingsComponent } from './bot-settings.component'; + +describe('BotSettingsComponent', () => { + let component: BotSettingsComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ BotSettingsComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(BotSettingsComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/Views/bot-settings/bot-settings.component.ts b/frontend/src/app/Views/bot-settings/bot-settings.component.ts new file mode 100644 index 0000000..40bd01b --- /dev/null +++ b/frontend/src/app/Views/bot-settings/bot-settings.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-bot-settings', + templateUrl: './bot-settings.component.html', + styleUrls: ['./bot-settings.component.scss'] +}) +export class BotSettingsComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/frontend/src/app/Views/header/header.component.html b/frontend/src/app/Views/header/header.component.html index 531c85e..d07d2df 100644 --- a/frontend/src/app/Views/header/header.component.html +++ b/frontend/src/app/Views/header/header.component.html @@ -5,7 +5,18 @@ mat-icon-button class="example-icon favorite-icon" aria-label="Example icon-button with heart icon" + [matMenuTriggerFor]="menu" > settings + + + + diff --git a/frontend/src/app/Views/profile/profile.component.html b/frontend/src/app/Views/profile/profile.component.html new file mode 100644 index 0000000..9df0576 --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.html @@ -0,0 +1 @@ +

profile works!

diff --git a/frontend/src/app/Views/profile/profile.component.scss b/frontend/src/app/Views/profile/profile.component.scss new file mode 100644 index 0000000..e69de29 diff --git a/frontend/src/app/Views/profile/profile.component.spec.ts b/frontend/src/app/Views/profile/profile.component.spec.ts new file mode 100644 index 0000000..e88012e --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.spec.ts @@ -0,0 +1,25 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { ProfileComponent } from './profile.component'; + +describe('ProfileComponent', () => { + let component: ProfileComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + declarations: [ ProfileComponent ] + }) + .compileComponents(); + }); + + beforeEach(() => { + fixture = TestBed.createComponent(ProfileComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/frontend/src/app/Views/profile/profile.component.ts b/frontend/src/app/Views/profile/profile.component.ts new file mode 100644 index 0000000..29ea4ff --- /dev/null +++ b/frontend/src/app/Views/profile/profile.component.ts @@ -0,0 +1,15 @@ +import { Component, OnInit } from '@angular/core'; + +@Component({ + selector: 'app-profile', + templateUrl: './profile.component.html', + styleUrls: ['./profile.component.scss'] +}) +export class ProfileComponent implements OnInit { + + constructor() { } + + ngOnInit(): void { + } + +} diff --git a/frontend/src/app/app-routing.module.ts b/frontend/src/app/app-routing.module.ts index b1926d3..6d05a46 100644 --- a/frontend/src/app/app-routing.module.ts +++ b/frontend/src/app/app-routing.module.ts @@ -2,6 +2,7 @@ import { NgModule } from '@angular/core'; import { RouterModule, Routes } from '@angular/router'; import { DashboardComponent } from './Views/dashboard/dashboard.component'; import { LoginComponent } from './Views/login/login.component'; +import { ProfileComponent } from './Views/profile/profile.component'; import { RegisterComponent } from './Views/register/register.component'; const routes: Routes = [ @@ -17,6 +18,14 @@ const routes: Routes = [ path: 'register', component: RegisterComponent, }, + { + path: 'profile', + component: ProfileComponent, + }, + { + path: 'settings', + component: ProfileComponent, + }, ]; @NgModule({ diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index e3465f6..2cb0777 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -33,17 +33,17 @@ export class AppComponent { (event as NavigationEnd).url === '/login' || (event as NavigationEnd).url === '/register' ); - if (this.tokenStorage.getToken()) { - this.isLoggedIn = true; - } else { - this.isLoggedIn = false; - } - if ( - this.isLoggedIn === false && - (event as NavigationEnd).url != '/register' - ) { - this.router.navigate(['/login']); - } + // if (this.tokenStorage.getToken()) { + // this.isLoggedIn = true; + // } else { + // this.isLoggedIn = false; + // } + // if ( + // this.isLoggedIn === false && + // (event as NavigationEnd).url != '/register' + // ) { + // this.router.navigate(['/login']); + // } }); } } diff --git a/frontend/src/app/app.module.ts b/frontend/src/app/app.module.ts index ebc1537..1e925aa 100644 --- a/frontend/src/app/app.module.ts +++ b/frontend/src/app/app.module.ts @@ -9,6 +9,7 @@ import { MatButtonModule } from '@angular/material/button'; import { MatGridListModule } from '@angular/material/grid-list'; import { MatCardModule } from '@angular/material/card'; import { MatTableModule } from '@angular/material/table'; +import { MatMenuModule } from '@angular/material/menu'; import { AppRoutingModule } from './app-routing.module'; import { AppComponent } from './app.component'; @@ -17,6 +18,8 @@ import { HeaderComponent } from './Views/header/header.component'; import { BrowserAnimationsModule } from '@angular/platform-browser/animations'; import { DashboardComponent } from './Views/dashboard/dashboard.component'; import { RegisterComponent } from './Views/register/register.component'; +import { ProfileComponent } from './Views/profile/profile.component'; +import { BotSettingsComponent } from './Views/bot-settings/bot-settings.component'; @NgModule({ declarations: [ @@ -25,6 +28,8 @@ import { RegisterComponent } from './Views/register/register.component'; HeaderComponent, DashboardComponent, RegisterComponent, + ProfileComponent, + BotSettingsComponent, ], imports: [ BrowserModule, @@ -38,6 +43,7 @@ import { RegisterComponent } from './Views/register/register.component'; MatTableModule, FormsModule, HttpClientModule, + MatMenuModule, ], providers: [], bootstrap: [AppComponent], From 33c915f4be88a55c1820b7693bd5e4138e93c931 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Sat, 19 Mar 2022 22:11:29 +0100 Subject: [PATCH 2/8] Comment in data code --- frontend/src/app/Services/auth.service.ts | 4 +-- frontend/src/app/Services/data.service.ts | 26 +++++++++---------- .../Views/register/register.component.html | 17 ++++++++++++ .../app/Views/register/register.component.ts | 1 - frontend/src/app/app.component.ts | 22 ++++++++-------- 5 files changed, 43 insertions(+), 27 deletions(-) diff --git a/frontend/src/app/Services/auth.service.ts b/frontend/src/app/Services/auth.service.ts index db051dc..4fcdef9 100644 --- a/frontend/src/app/Services/auth.service.ts +++ b/frontend/src/app/Services/auth.service.ts @@ -12,14 +12,14 @@ const httpOptions = { export class AuthService { constructor(private http: HttpClient) {} login(username: string, password: string): Observable { - return this.http.post(AUTH_API + 'login', { + return this.http.post(AUTH_API + '/login', { username, password, }); } register(username: string, password: string): Observable { return this.http.post( - AUTH_API + 'signup', + AUTH_API + '/register', { username, password, diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index ce44a05..f47d80e 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -1,22 +1,22 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; import { Observable } from 'rxjs'; -const API_URL = 'http://localhost:8080/api/test/'; +const API_URL = 'https://aktienbot.flokaiser.com/api/user'; @Injectable({ providedIn: 'root', }) export class DataService { constructor(private http: HttpClient) {} - // getPublicContent(): Observable { - // return this.http.get(API_URL + 'all', { responseType: 'text' }); - // } - // getUserBoard(): Observable { - // return this.http.get(API_URL + 'user', { responseType: 'text' }); - // } - // getModeratorBoard(): Observable { - // return this.http.get(API_URL + 'mod', { responseType: 'text' }); - // } - // getAdminBoard(): Observable { - // return this.http.get(API_URL + 'admin', { responseType: 'text' }); - // } + getPublicContent(): Observable { + return this.http.get(API_URL + 'all', { responseType: 'text' }); + } + getUserBoard(): Observable { + return this.http.get(API_URL + 'user', { responseType: 'text' }); + } + getModeratorBoard(): Observable { + return this.http.get(API_URL + 'mod', { responseType: 'text' }); + } + getAdminBoard(): Observable { + return this.http.get(API_URL + 'admin', { responseType: 'text' }); + } } diff --git a/frontend/src/app/Views/register/register.component.html b/frontend/src/app/Views/register/register.component.html index 2e2c38c..486f037 100644 --- a/frontend/src/app/Views/register/register.component.html +++ b/frontend/src/app/Views/register/register.component.html @@ -53,6 +53,23 @@ +
+ + +
+
+ Confirmation is required +
+
+
diff --git a/frontend/src/app/Views/register/register.component.ts b/frontend/src/app/Views/register/register.component.ts index 728792b..b015e29 100644 --- a/frontend/src/app/Views/register/register.component.ts +++ b/frontend/src/app/Views/register/register.component.ts @@ -21,7 +21,6 @@ export class RegisterComponent implements OnInit { const { username, password } = this.form; this.authService.register(username, password).subscribe( (data) => { - console.log(data); this.isSuccessful = true; this.isSignUpFailed = false; this.router.navigate(['/login']); diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index 2cb0777..e3465f6 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -33,17 +33,17 @@ export class AppComponent { (event as NavigationEnd).url === '/login' || (event as NavigationEnd).url === '/register' ); - // if (this.tokenStorage.getToken()) { - // this.isLoggedIn = true; - // } else { - // this.isLoggedIn = false; - // } - // if ( - // this.isLoggedIn === false && - // (event as NavigationEnd).url != '/register' - // ) { - // this.router.navigate(['/login']); - // } + if (this.tokenStorage.getToken()) { + this.isLoggedIn = true; + } else { + this.isLoggedIn = false; + } + if ( + this.isLoggedIn === false && + (event as NavigationEnd).url != '/register' + ) { + this.router.navigate(['/login']); + } }); } } From c9122292f170db79a6ddb26ad0c674e4da939c10 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Sat, 19 Mar 2022 22:41:44 +0100 Subject: [PATCH 3/8] Add logout functionality --- frontend/src/app/Services/data.service.ts | 23 ++++++++++--------- .../app/Views/header/header.component.html | 4 ++++ .../src/app/Views/header/header.component.ts | 12 ++++++---- .../app/Views/profile/profile.component.ts | 9 +++----- 4 files changed, 27 insertions(+), 21 deletions(-) diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index f47d80e..bcf65c0 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -1,22 +1,23 @@ import { Injectable } from '@angular/core'; -import { HttpClient } from '@angular/common/http'; +import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; -const API_URL = 'https://aktienbot.flokaiser.com/api/user'; +const API_URL = 'https://aktienbot.flokaiser.com/api/'; +const httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer', + }), +}; @Injectable({ providedIn: 'root', }) export class DataService { constructor(private http: HttpClient) {} getPublicContent(): Observable { - return this.http.get(API_URL + 'all', { responseType: 'text' }); + return this.http.get(API_URL + 'portfolio', { responseType: 'text' }); } - getUserBoard(): Observable { - return this.http.get(API_URL + 'user', { responseType: 'text' }); - } - getModeratorBoard(): Observable { - return this.http.get(API_URL + 'mod', { responseType: 'text' }); - } - getAdminBoard(): Observable { - return this.http.get(API_URL + 'admin', { responseType: 'text' }); + + showStorage() { + console.log(localStorage); } } diff --git a/frontend/src/app/Views/header/header.component.html b/frontend/src/app/Views/header/header.component.html index d07d2df..d72ba56 100644 --- a/frontend/src/app/Views/header/header.component.html +++ b/frontend/src/app/Views/header/header.component.html @@ -18,5 +18,9 @@ ballot Bot Settings + diff --git a/frontend/src/app/Views/header/header.component.ts b/frontend/src/app/Views/header/header.component.ts index 7ab4cf7..e5dc48b 100644 --- a/frontend/src/app/Views/header/header.component.ts +++ b/frontend/src/app/Views/header/header.component.ts @@ -1,15 +1,19 @@ import { Component, OnInit } from '@angular/core'; +import { TokenStorageService } from 'src/app/Services/token.service'; @Component({ selector: 'app-header', templateUrl: './header.component.html', - styleUrls: ['./header.component.scss'] + styleUrls: ['./header.component.scss'], }) export class HeaderComponent implements OnInit { + constructor(private tokenStorage: TokenStorageService) {} - constructor() { } + ngOnInit(): void {} - ngOnInit(): void { + logout() { + console.log('NASE'); + this.tokenStorage.signOut(); + location.reload(); } - } diff --git a/frontend/src/app/Views/profile/profile.component.ts b/frontend/src/app/Views/profile/profile.component.ts index 29ea4ff..89b667f 100644 --- a/frontend/src/app/Views/profile/profile.component.ts +++ b/frontend/src/app/Views/profile/profile.component.ts @@ -3,13 +3,10 @@ import { Component, OnInit } from '@angular/core'; @Component({ selector: 'app-profile', templateUrl: './profile.component.html', - styleUrls: ['./profile.component.scss'] + styleUrls: ['./profile.component.scss'], }) export class ProfileComponent implements OnInit { + constructor() {} - constructor() { } - - ngOnInit(): void { - } - + ngOnInit(): void {} } From 20f89155d040fd65714e847a9fcbbcb8cf563265 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Sat, 19 Mar 2022 22:42:15 +0100 Subject: [PATCH 4/8] Remove console.log statement --- frontend/src/app/Views/header/header.component.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/src/app/Views/header/header.component.ts b/frontend/src/app/Views/header/header.component.ts index e5dc48b..93e7a6c 100644 --- a/frontend/src/app/Views/header/header.component.ts +++ b/frontend/src/app/Views/header/header.component.ts @@ -12,7 +12,6 @@ export class HeaderComponent implements OnInit { ngOnInit(): void {} logout() { - console.log('NASE'); this.tokenStorage.signOut(); location.reload(); } From 95a524dd04776fe4a4063ccdfa1b766853f7c1d8 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Sat, 19 Mar 2022 23:02:47 +0100 Subject: [PATCH 5/8] Fix token storage --- frontend/src/app/Services/data.service.ts | 27 ++++++++++++------- .../src/app/Views/login/login.component.ts | 6 ++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index bcf65c0..45e6617 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -1,20 +1,29 @@ import { Injectable } from '@angular/core'; import { HttpClient, HttpHeaders } from '@angular/common/http'; import { Observable } from 'rxjs'; +import { TokenStorageService } from './token.service'; const API_URL = 'https://aktienbot.flokaiser.com/api/'; -const httpOptions = { - headers: new HttpHeaders({ - 'Content-Type': 'application/json', - Authorization: 'Bearer', - }), -}; @Injectable({ providedIn: 'root', }) export class DataService { - constructor(private http: HttpClient) {} - getPublicContent(): Observable { - return this.http.get(API_URL + 'portfolio', { responseType: 'text' }); + constructor( + private http: HttpClient, + private tokenStorage: TokenStorageService + ) {} + + httpOptions = { + headers: new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer' + this.tokenStorage.getToken(), + }), + }; + + getStockData(): Observable { + return this.http.get(API_URL + 'portfolio', { + headers: this.httpOptions.headers, + responseType: 'text', + }); } showStorage() { diff --git a/frontend/src/app/Views/login/login.component.ts b/frontend/src/app/Views/login/login.component.ts index 9b5bfb5..420e0b2 100644 --- a/frontend/src/app/Views/login/login.component.ts +++ b/frontend/src/app/Views/login/login.component.ts @@ -31,16 +31,14 @@ export class LoginComponent implements OnInit { } onSubmit(): void { const { username, password } = this.form; - console.log(username, password); this.authService.login(username, password).subscribe( (data) => { - this.tokenStorage.saveToken(data.accessToken); - this.tokenStorage.saveUser(data); + this.tokenStorage.saveToken(data.data.token); + this.tokenStorage.saveUser(data.data); this.isLoginFailed = false; this.isLoggedIn = true; this.accountName = username; - console.log(this.isLoggedIn); this.router.navigate(['']); }, (err) => { From 9aa45d28d8c8e5f6c5eb25e67fbe40ef21a6c0e0 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Wed, 23 Mar 2022 19:07:56 +0100 Subject: [PATCH 6/8] Add stock data api call --- frontend/src/app/Services/data.service.ts | 32 +++++++++++-------- .../Views/dashboard/dashboard.component.ts | 8 +++-- 2 files changed, 25 insertions(+), 15 deletions(-) diff --git a/frontend/src/app/Services/data.service.ts b/frontend/src/app/Services/data.service.ts index 45e6617..4419d9f 100644 --- a/frontend/src/app/Services/data.service.ts +++ b/frontend/src/app/Services/data.service.ts @@ -12,21 +12,27 @@ export class DataService { private tokenStorage: TokenStorageService ) {} - httpOptions = { - headers: new HttpHeaders({ - 'Content-Type': 'application/json', - Authorization: 'Bearer' + this.tokenStorage.getToken(), - }), - }; + headers = new HttpHeaders({ + 'Content-Type': 'application/json', + Authorization: 'Bearer ' + this.tokenStorage.getToken(), + }); - getStockData(): Observable { - return this.http.get(API_URL + 'portfolio', { - headers: this.httpOptions.headers, + async getStockData() { + await this.http + .get(API_URL + 'portfolio', { + headers: this.headers, + responseType: 'text', + }) + .subscribe((data) => { + console.log(data); + return data; + }); + } + + getKeywords(): Observable { + return this.http.get(API_URL + 'keywords', { + headers: this.headers, responseType: 'text', }); } - - showStorage() { - console.log(localStorage); - } } diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index 5752606..ecc7a4b 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.ts +++ b/frontend/src/app/Views/dashboard/dashboard.component.ts @@ -1,4 +1,6 @@ import { Component, OnInit } from '@angular/core'; +import { throwToolbarMixedModesError } from '@angular/material/toolbar'; +import { DataService } from 'src/app/Services/data.service'; export interface PeriodicElement { name: string; @@ -46,9 +48,11 @@ const ELEMENT_DATA: PeriodicElement[] = [ styleUrls: ['./dashboard.component.scss'], }) export class DashboardComponent implements OnInit { - constructor() {} + constructor(private dataService: DataService) {} - ngOnInit(): void {} + async ngOnInit() { + const data = await this.dataService.getStockData(); + } displayedColumns: string[] = ['position', 'name', 'weight', 'symbol']; dataSource = ELEMENT_DATA; From be59f274ec6c6b32ab6d58c469cd1c5b767fad19 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Wed, 23 Mar 2022 19:31:34 +0100 Subject: [PATCH 7/8] Add comments --- .../src/app/Views/dashboard/dashboard.component.ts | 2 ++ frontend/src/app/Views/header/header.component.ts | 4 ++++ frontend/src/app/Views/login/login.component.ts | 11 +++++++++++ frontend/src/app/Views/register/register.component.ts | 5 +++++ frontend/src/app/app.component.ts | 7 ++++++- 5 files changed, 28 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/Views/dashboard/dashboard.component.ts b/frontend/src/app/Views/dashboard/dashboard.component.ts index ecc7a4b..ff2d717 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.ts +++ b/frontend/src/app/Views/dashboard/dashboard.component.ts @@ -50,6 +50,8 @@ const ELEMENT_DATA: PeriodicElement[] = [ export class DashboardComponent implements OnInit { constructor(private dataService: DataService) {} + //TODO avoid using ngOnInit() like this + //TODO fix server problems async ngOnInit() { const data = await this.dataService.getStockData(); } diff --git a/frontend/src/app/Views/header/header.component.ts b/frontend/src/app/Views/header/header.component.ts index 93e7a6c..07e63ab 100644 --- a/frontend/src/app/Views/header/header.component.ts +++ b/frontend/src/app/Views/header/header.component.ts @@ -7,10 +7,14 @@ import { TokenStorageService } from 'src/app/Services/token.service'; styleUrls: ['./header.component.scss'], }) export class HeaderComponent implements OnInit { + /** + * @param {TokenStorageService} privatetokenStorage + */ constructor(private tokenStorage: TokenStorageService) {} ngOnInit(): void {} + //logout() clears session storage; All user data is eradicated from it and page is reloaded logout() { this.tokenStorage.signOut(); location.reload(); diff --git a/frontend/src/app/Views/login/login.component.ts b/frontend/src/app/Views/login/login.component.ts index 420e0b2..dac1bc2 100644 --- a/frontend/src/app/Views/login/login.component.ts +++ b/frontend/src/app/Views/login/login.component.ts @@ -18,17 +18,26 @@ export class LoginComponent implements OnInit { errorMessage = ''; accountName = ''; + /** + * @param {AuthService} privateauthService + * @param {TokenStorageService} privatetokenStorage + * @param {Router} privaterouter + */ constructor( private authService: AuthService, private tokenStorage: TokenStorageService, private router: Router ) {} + + //ngOnInit() checks if a ngOnInit(): void { this.tokenStorage.signOut(); if (this.tokenStorage.getToken()) { this.isLoggedIn = true; } } + + //onSubmit() saves valuable information in session storage onSubmit(): void { const { username, password } = this.form; this.authService.login(username, password).subscribe( @@ -47,6 +56,8 @@ export class LoginComponent implements OnInit { } ); } + + //reloadPage() reloads the page reloadPage(): void { window.location.reload(); } diff --git a/frontend/src/app/Views/register/register.component.ts b/frontend/src/app/Views/register/register.component.ts index b015e29..c032d71 100644 --- a/frontend/src/app/Views/register/register.component.ts +++ b/frontend/src/app/Views/register/register.component.ts @@ -15,6 +15,11 @@ export class RegisterComponent implements OnInit { isSuccessful = false; isSignUpFailed = false; errorMessage = ''; + + /** + * @param {AuthService} privateauthService + * @param {Router} privaterouter + */ constructor(private authService: AuthService, private router: Router) {} ngOnInit(): void {} onSubmit(): void { diff --git a/frontend/src/app/app.component.ts b/frontend/src/app/app.component.ts index e3465f6..1a1d467 100644 --- a/frontend/src/app/app.component.ts +++ b/frontend/src/app/app.component.ts @@ -13,8 +13,8 @@ export class AppComponent { * Application title. */ title = 'Aktienbot'; - showHeader = false; + showHeader = false; isLoggedIn = false; /** @@ -26,6 +26,7 @@ export class AppComponent { private router: Router, private tokenStorage: TokenStorageService ) { + //check if it is login or registration page, header should not show there this.router.events .pipe(filter((event) => event instanceof NavigationEnd)) .subscribe((event) => { @@ -33,11 +34,15 @@ export class AppComponent { (event as NavigationEnd).url === '/login' || (event as NavigationEnd).url === '/register' ); + + //check if token already exists from past login if (this.tokenStorage.getToken()) { this.isLoggedIn = true; } else { this.isLoggedIn = false; } + + //prevent user from accessing dashboard if not logged in if ( this.isLoggedIn === false && (event as NavigationEnd).url != '/register' From f25a9293c2bd48f6bc4bdfe9570f5d4db6040cd7 Mon Sep 17 00:00:00 2001 From: kevinpauer Date: Fri, 25 Mar 2022 09:44:12 +0100 Subject: [PATCH 8/8] Improve Add Button --- frontend/src/app/Views/dashboard/dashboard.component.html | 1 + frontend/src/app/Views/dashboard/dashboard.component.scss | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/frontend/src/app/Views/dashboard/dashboard.component.html b/frontend/src/app/Views/dashboard/dashboard.component.html index 48693ac..6e0692a 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.html +++ b/frontend/src/app/Views/dashboard/dashboard.component.html @@ -9,6 +9,7 @@ mat-icon-button class="add-icon" aria-label="Example icon-button with heart icon" + [disableRipple]="true" > add diff --git a/frontend/src/app/Views/dashboard/dashboard.component.scss b/frontend/src/app/Views/dashboard/dashboard.component.scss index 6e05092..7bc1360 100644 --- a/frontend/src/app/Views/dashboard/dashboard.component.scss +++ b/frontend/src/app/Views/dashboard/dashboard.component.scss @@ -47,7 +47,8 @@ .add-icon { transform: scale(2); - padding-top: 1%; + margin-top: 2%; + outline: none !important; } .right-side {