wip: profile

This commit is contained in:
Jegor 2021-06-17 17:52:27 +02:00
parent 012de346e8
commit a6a5b58e25
6 changed files with 45 additions and 8 deletions

View File

@ -23,8 +23,12 @@
{{product?.short_description}}
</div>
</div>
<div class="priceAlarm" (click)="setPriceAlarm()">
Set Price Alarm
<div class="priceAlarm" *ngIf="!isLoggedIn" routerLink="/signin">
Login to set a price alarm
</div>
<div class="priceAlarm" *ngIf="isLoggedIn">
<input type="search" id="s" name="price" [(ngModel)]="price">
<div (click)="setPriceAlarm()">Set Price Alarm</div>
</div>
<div class="bestPriceContainer">
<div class="bestPrice">

View File

@ -34,6 +34,8 @@ export class ProductDetailsComponent implements OnInit {
vendorMap = {};
@ViewChild('chart') chart: ChartComponent;
public chartOptions: ChartOptions;
isLoggedIn: boolean;
price: any;
constructor(
private apiService: ApiService
@ -44,6 +46,9 @@ export class ProductDetailsComponent implements OnInit {
this.getProduct();
this.getVendors();
this.getPrices();
if (this.apiService.getSessionInfoFromLocalStorage().session_id != "") {
this.isLoggedIn = true;
}
}
getProduct(): void {
@ -119,8 +124,10 @@ export class ProductDetailsComponent implements OnInit {
}
setPriceAlarm() {
this.apiService.createPriceAlarms(this.productId, 9).subscribe(
this.apiService.createPriceAlarms(this.productId, this.price*100).subscribe(
alarms => console.log(alarms)
)
}
}

View File

@ -16,7 +16,7 @@
</div>
<div class="align-items-center align-content-center col-md-3 border-left mt-1">
<div class="d-flex flex-row align-items-center">
<h4 class="mr-1">${{product.price}}</h4>
<h4 class="mr-1">${{pricesMap[product.product_id]?.price_in_cents/100}}</h4>
</div>
<div class="d-flex flex-column mt-4"><button class="btn btn-primary btn-sm" type="button" (click)="clickedProduct(product)">Details</button>
</div>

View File

@ -10,6 +10,7 @@ import {ActivatedRoute, Router} from '@angular/router';
})
export class ProductListComponent implements OnInit {
products: Product[] = [];
pricesMap: any = {};
@Input() numberOfProducts: number;
@Input() showProductPicture: boolean;
@Input() searchQuery: string;
@ -53,9 +54,27 @@ export class ProductListComponent implements OnInit {
}
getProducts(): void {
this.apiService.getProducts().subscribe(products => this.products = products);
this.apiService.getProducts().subscribe(products => {
this.products = products;
this.getPrices();
});
}
getPrices(): void {
const productIds: number[] = [];
this.products.forEach(
product => productIds.push(product.product_id)
)
this.apiService.getProductsByIds(productIds).subscribe(
prices => {
prices.forEach(price => {
this.pricesMap[price.product_id] = price;
})
}
)
}
getSearchedProducts(): void {
this.apiService.getProductsByQuery(this.searchQuery).subscribe(products => this.products = products);
}
@ -64,4 +83,5 @@ export class ProductListComponent implements OnInit {
this.router.navigate([('/product/' + product.product_id)]);
}
}

View File

@ -78,6 +78,7 @@
<tr>
<th>Produkt</th>
<th>Preis</th>
<th>Ändern</th>
<th>Löschen</th>
</tr>
<tr *ngFor="let alarm of alarms">
@ -88,7 +89,10 @@
{{alarm.defined_price/100}}
</td>
<td>
<img class="delete" src="../assets/images/Delete_icon-icons.com_55931.png" (click)="delete()">
<img class="delete" src="../assets/images/Delete_icon-icons.com_55931.png" (click)="delete(alarm.alarm_id)">
</td>
<td>
<img class="delete" src="../assets/images/Delete_icon-icons.com_55931.png" (click)="delete(alarm.alarm_id)">
</td>
</tr>
</table>

View File

@ -50,7 +50,9 @@ export class ProfileComponent implements OnInit {
)
}
delete() {
delete(id:number): void {
this.api.deletePriceAlarm(id).subscribe(
res => window.location.reload()
)
}
}