From 969ac6feafe9a2325a0aefb5b65da2b10e661d0c Mon Sep 17 00:00:00 2001 From: Jegor Date: Thu, 17 Jun 2021 09:55:40 +0200 Subject: [PATCH] wip: profile component --- Frontend/src/app/app.component.ts | 10 ++++++- Frontend/src/app/app.module.ts | 2 ++ Frontend/src/app/app.routing.ts | 3 +- .../registration/registration.component.ts | 11 +++++-- .../auth/signin/signin.component.ts | 2 +- .../hot-deals-widget.component.html | 8 ++--- .../hot-deals-widget.component.ts | 3 +- .../product-details.component.html | 2 +- .../product-details.component.ts | 6 ++++ .../components/profile/profile.component.html | 21 ++++++++++++++ .../components/profile/profile.component.ts | 29 ++++++++++++++++++- .../components/top-bar/top-bar.component.html | 9 +++--- .../components/top-bar/top-bar.component.ts | 26 +++++++++++++++-- 13 files changed, 113 insertions(+), 19 deletions(-) diff --git a/Frontend/src/app/app.component.ts b/Frontend/src/app/app.component.ts index d45de93..f65d28c 100644 --- a/Frontend/src/app/app.component.ts +++ b/Frontend/src/app/app.component.ts @@ -1,6 +1,8 @@ import {Component, OnDestroy, OnInit} from '@angular/core'; import {NgcCookieConsentService, NgcInitializeEvent, NgcNoCookieLawEvent, NgcStatusChangeEvent} from 'ngx-cookieconsent'; import {Subscription} from 'rxjs'; +import {ApiService} from "./services/api.service"; + @Component({ selector: 'app-root', @@ -19,12 +21,18 @@ export class AppComponent implements OnInit, OnDestroy { private revokeChoiceSubscription: Subscription; private noCookieLawSubscription: Subscription; + isLoggedIn = false; + showUserBoard = false; + username?: string; + constructor( - private ccService: NgcCookieConsentService + private ccService: NgcCookieConsentService, + private api: ApiService ) { } ngOnInit(): void { + // subscribe to cookieconsent observables to react to main events this.popupOpenSubscription = this.ccService.popupOpen$.subscribe( () => { diff --git a/Frontend/src/app/app.module.ts b/Frontend/src/app/app.module.ts index 5da2756..153ae2c 100644 --- a/Frontend/src/app/app.module.ts +++ b/Frontend/src/app/app.module.ts @@ -39,6 +39,7 @@ import { GreetingInfoSliderComponent } from './components/greeting-info-slider/g import { KundenComponent } from './components/kunden/kunden.component'; import { AboutUsComponent } from './components/about-us/about-us.component'; import { ProfileComponent } from './components/profile/profile.component'; +import { ProfilePageComponent } from './pages/profile-page/profile-page.component'; // For cookie popup const cookieConfig: NgcCookieConsentConfig = { @@ -104,6 +105,7 @@ const cookieConfig: NgcCookieConsentConfig = { KundenComponent, AboutUsComponent, ProfileComponent, + ProfilePageComponent, ], imports: [ BrowserModule, diff --git a/Frontend/src/app/app.routing.ts b/Frontend/src/app/app.routing.ts index 58ddb59..2e13ded 100644 --- a/Frontend/src/app/app.routing.ts +++ b/Frontend/src/app/app.routing.ts @@ -12,6 +12,7 @@ import {PrivacyComponent} from './pages/privacy/privacy.component'; import {SigninComponent} from "./components/auth/signin/signin.component"; import {RegistrationComponent} from "./components/auth/registration/registration.component"; import {ProfileComponent} from "./components/profile/profile.component"; +import {ProfilePageComponent} from "./pages/profile-page/profile-page.component"; const routes: Routes = [ {path: '', component: LandingpageComponent, pathMatch: 'full'}, @@ -22,7 +23,7 @@ const routes: Routes = [ {path: 'signin', component: SigninComponent}, {path: 'registration', component: RegistrationComponent}, {path: "product-detail", component: ProductDetailPageComponent}, - {path: "profile", component: ProfileComponent}, + {path: "profile", component: ProfilePageComponent}, {path: '**', component: PageNotFoundPageComponent} ]; diff --git a/Frontend/src/app/components/auth/registration/registration.component.ts b/Frontend/src/app/components/auth/registration/registration.component.ts index ff8c904..a624666 100644 --- a/Frontend/src/app/components/auth/registration/registration.component.ts +++ b/Frontend/src/app/components/auth/registration/registration.component.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { FormBuilder, FormGroup, Validators } from '@angular/forms'; import {ApiService} from "../../../services/api.service"; +import {Router} from "@angular/router"; @Component({ @@ -15,7 +16,8 @@ export class RegistrationComponent implements OnInit { constructor( private formBuilder: FormBuilder, - private api : ApiService + private api : ApiService, + private router: Router ) { } ngOnInit(): void { @@ -32,6 +34,11 @@ export class RegistrationComponent implements OnInit { get me() { return this.form.controls; } onSubmit() { - this.api.registerUser(this.form.value.username, this.form.value.password, this.form.value.email).subscribe(res=>console.log(res)); + this.api.registerUser(this.form.value.username, this.form.value.password, this.form.value.email).subscribe( + res=> { + this.router.navigate(['']); + this.api.saveSessionInfoToLocalStorage(res); + } + ); } } diff --git a/Frontend/src/app/components/auth/signin/signin.component.ts b/Frontend/src/app/components/auth/signin/signin.component.ts index dee46ed..8ca6646 100644 --- a/Frontend/src/app/components/auth/signin/signin.component.ts +++ b/Frontend/src/app/components/auth/signin/signin.component.ts @@ -43,8 +43,8 @@ export class SigninComponent implements OnInit { .subscribe( data => { this.isSuccessful = true; - this.isSignUpFailed = false; this.router.navigate(['']); + this.api.saveSessionInfoToLocalStorage(data); }, err => { this.errorMessage = err.error.message; diff --git a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html index 7def010..947b3f9 100644 --- a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html +++ b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.html @@ -11,16 +11,16 @@
-
+
-
{{productsPricesMap[productId]?.product.name}}
+
{{productsPricesMap[productId]?.product?.name}}
-
Amazon: {{productsPricesMap[productId]?.amazonPrice.price_in_cents}}$
+
Amazon: {{productsPricesMap[productId]?.amazonPrice?.price_in_cents/100}}$
-
Plantshub: {{productsPricesMap[productId]?.lowestPrice.price_in_cents}}
+
Plantshub: {{productsPricesMap[productId]?.lowestPrice?.price_in_cents/100}}
diff --git a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts index 688a951..0fe7af1 100644 --- a/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts +++ b/Frontend/src/app/components/hot-deals-widget/hot-deals-widget.component.ts @@ -86,12 +86,11 @@ export class HotDealsWidgetComponent implements OnInit { this.apiService.getAmazonPrice(id).subscribe( price => { this.amazonPrices.push(price); - this.productsPricesMap[price.product_id].amazonPrice = price; + this.productsPricesMap[price[0].product_id].amazonPrice = price[0]; } ); } ); - console.log(this.amazonPrices); } getSearchedProducts(): void { diff --git a/Frontend/src/app/components/product-details/product-details.component.html b/Frontend/src/app/components/product-details/product-details.component.html index f392f00..cdccfb3 100644 --- a/Frontend/src/app/components/product-details/product-details.component.html +++ b/Frontend/src/app/components/product-details/product-details.component.html @@ -20,7 +20,7 @@ {{product?.short_description}}
-
+
Set Price Alarm
diff --git a/Frontend/src/app/components/product-details/product-details.component.ts b/Frontend/src/app/components/product-details/product-details.component.ts index 54b9c00..1ccae5a 100644 --- a/Frontend/src/app/components/product-details/product-details.component.ts +++ b/Frontend/src/app/components/product-details/product-details.component.ts @@ -117,4 +117,10 @@ export class ProductDetailsComponent implements OnInit { return Math.round(percentage); } + + setPriceAlarm() { + this.apiService.createPriceAlarms(this.productId, 9).subscribe( + alarms => console.log(alarms) + ) + } } diff --git a/Frontend/src/app/components/profile/profile.component.html b/Frontend/src/app/components/profile/profile.component.html index d44b8bf..4bfa28e 100644 --- a/Frontend/src/app/components/profile/profile.component.html +++ b/Frontend/src/app/components/profile/profile.component.html @@ -7,6 +7,27 @@ username: {{ currentUser.username}}

+

+ alarms + {{alarms}} +

+ + + + + + + + + +
ProduktPreis
+ {{productsMap[alarm.product_id]?.name}} + + {{alarm.defined_price/100}} +
+

+ zurück +

diff --git a/Frontend/src/app/components/profile/profile.component.ts b/Frontend/src/app/components/profile/profile.component.ts index dc8fe69..611e06a 100644 --- a/Frontend/src/app/components/profile/profile.component.ts +++ b/Frontend/src/app/components/profile/profile.component.ts @@ -9,7 +9,9 @@ import {ApiService} from "../../services/api.service"; export class ProfileComponent implements OnInit { currentUser: any; - obj:any + obj:any; + alarms: any []; + productsMap: any; constructor(private api: ApiService ) { } @@ -21,5 +23,30 @@ export class ProfileComponent implements OnInit { console.log(this.currentUser); }, ); + + this.getPriceAlarms(); + } + + getPriceAlarms(): void { + this.api.getPriceAlarms().subscribe( + alarms => { + this.alarms = alarms + this.getProductsByIds() + } + ) + } + + getProductsByIds(): void { + let productIds: number []; + this.alarms.forEach( + alarm => {productIds.push(alarm.product_id)} + ); + this.api.getProductsByIds(productIds).subscribe( + products => { + products.forEach( + product => {this.productsMap[product.product_id] = product} + ) + } + ) } } diff --git a/Frontend/src/app/components/top-bar/top-bar.component.html b/Frontend/src/app/components/top-bar/top-bar.component.html index 6a41f7d..944d654 100644 --- a/Frontend/src/app/components/top-bar/top-bar.component.html +++ b/Frontend/src/app/components/top-bar/top-bar.component.html @@ -2,7 +2,7 @@
diff --git a/Frontend/src/app/components/top-bar/top-bar.component.ts b/Frontend/src/app/components/top-bar/top-bar.component.ts index f2e667b..89f5cd0 100644 --- a/Frontend/src/app/components/top-bar/top-bar.component.ts +++ b/Frontend/src/app/components/top-bar/top-bar.component.ts @@ -1,5 +1,6 @@ -import { Component, OnInit } from '@angular/core'; +import {Component, Input, OnInit} from '@angular/core'; import {ApiService} from "../../services/api.service"; +import {Router} from "@angular/router"; @Component({ @@ -10,13 +11,34 @@ import {ApiService} from "../../services/api.service"; export class TopBarComponent implements OnInit { sidenav: any; + isLoggedIn: boolean; + @Input() searchQuery: string; constructor( - private api: ApiService + private api: ApiService, + private router: Router ) { } ngOnInit() { this.api.getUserInfo().subscribe(data=>{console.log(data)}); + + if ( this.api.getSessionInfoFromLocalStorage().session_id != "") { + this.isLoggedIn = true; + } + } + + logout(): void { + localStorage.setItem('session_id', ''); + localStorage.setItem('session_key', ''); + window.location.reload() + } + + getSearchedProducts(): void { + this.api.getProductsByQuery(this.searchQuery).subscribe( + data => { + this.router.navigate([('/registration')]); + } + ); } }