From bafef0f6b38226c7d59103ca81b111a95dcc759c Mon Sep 17 00:00:00 2001 From: Cyril Rouillon Date: Wed, 29 May 2024 16:47:17 +0200 Subject: [PATCH] upgrade UI --- backend/services/lotDb.js | 1 + backend/services/saleDb.js | 1 + client/src/app/core/services/api.service.ts | 27 +++++++++++------ .../loading-sale-dialog.component.ts | 16 +++++++++- .../sale-detail-page.component.ts | 1 + .../sales-page/sales-page.component.html | 30 ++++++++++++++----- .../sales/sales-page/sales-page.component.ts | 29 ++++++++++-------- 7 files changed, 75 insertions(+), 30 deletions(-) diff --git a/backend/services/lotDb.js b/backend/services/lotDb.js index 2c27b48..346cd26 100644 --- a/backend/services/lotDb.js +++ b/backend/services/lotDb.js @@ -27,6 +27,7 @@ const LotDb = class async post(newDocument) { + delete newDocument._id; let result = await this.collection.insertOne(newDocument); return result; } diff --git a/backend/services/saleDb.js b/backend/services/saleDb.js index 65eaa92..fcb5280 100644 --- a/backend/services/saleDb.js +++ b/backend/services/saleDb.js @@ -27,6 +27,7 @@ const SaleDb = class async post(newDocument) { + delete newDocument._id; let result = await this.collection.insertOne(newDocument); return result; } diff --git a/client/src/app/core/services/api.service.ts b/client/src/app/core/services/api.service.ts index 01a962c..bdcd49a 100644 --- a/client/src/app/core/services/api.service.ts +++ b/client/src/app/core/services/api.service.ts @@ -37,29 +37,37 @@ export class apiService { return this.http.get(this.ApiURL+'/sale/getSaleInfos/'+encodeUrl); } - prepareSale(saleInfo: SaleInfo): Observable { + prepareSale(Sale: Sale): Observable { - let follow = this.http.get(this.ApiURL+'/sale/prepareSale/'+saleInfo._id); + let follow = this.http.get(this.ApiURL+'/sale/prepareSale/'+Sale._id); return follow } - followSale(saleInfo: SaleInfo): Observable { + followSale(Sale: Sale): Observable { - let follow = this.http.get(this.ApiURL+'/sale/followSale/'+saleInfo._id); + let follow = this.http.get(this.ApiURL+'/sale/followSale/'+Sale._id); return follow } - // CRUD DB Sale + resetSaleToReady(_id: String): void { + this.getSale(_id).subscribe((sale: Sale) => { + sale.status = "ready"; + this.updateSale(sale).subscribe(); + }); + } + + // Sale CRUD + getSale(_id: String): Observable { return this.http.get(this.ApiURL+'/sale/sale/'+_id); } - saveSale(saleInfo: SaleInfo): Observable { - return this.http.post(this.ApiURL+'/sale/sale', saleInfo); + saveSale(Sale: Sale): Observable { + return this.http.post(this.ApiURL+'/sale/sale', Sale); } - updateSale(saleInfo: SaleInfo): Observable { - return this.http.put(this.ApiURL+'/sale/sale/'+saleInfo._id, saleInfo); + updateSale(Sale: Sale): Observable { + return this.http.put(this.ApiURL+'/sale/sale/'+Sale._id, Sale); } deleteSale(_id: String): Observable { @@ -67,6 +75,7 @@ export class apiService { } // Function DB Sale + getAllSale(): Observable { return this.http.get(this.ApiURL+'/sale/getAll'); diff --git a/client/src/app/features/sales/sales-page/loading-sale-dialog/loading-sale-dialog.component.ts b/client/src/app/features/sales/sales-page/loading-sale-dialog/loading-sale-dialog.component.ts index 8c938d6..b69ff8f 100644 --- a/client/src/app/features/sales/sales-page/loading-sale-dialog/loading-sale-dialog.component.ts +++ b/client/src/app/features/sales/sales-page/loading-sale-dialog/loading-sale-dialog.component.ts @@ -7,6 +7,8 @@ import { apiService } from 'src/app/core/services/api.service'; // Models import { SaleInfo } from 'src/app/core/services/model/saleInfo.interface'; +import { Sale } from 'src/app/core/services/model/sale.interface'; + @Component({ selector: 'loading-sale-dialog-dialog', @@ -56,7 +58,19 @@ export class LoadingSaleDialogComponent implements OnInit { } save(): void { - this.apiService.saveSale(this.SaleInfo).subscribe( SaleInfo => { + const Sale: Sale = { + _id: { $oid: '' }, + idPlatform: this.SaleInfo.idPlatform, + platform: this.SaleInfo.platform, + url: this.SaleInfo.url, + title: this.SaleInfo.title, + date: this.SaleInfo.date, + location: this.SaleInfo.location, + saleHouseName: this.SaleInfo.saleHouseName, + status: "ready" + } + + this.apiService.saveSale(Sale).subscribe( Sale => { this.dialogRef.close(true); }); } diff --git a/client/src/app/features/sales/sales-page/sale-detail-page/sale-detail-page.component.ts b/client/src/app/features/sales/sales-page/sale-detail-page/sale-detail-page.component.ts index 54cac1c..195eedd 100644 --- a/client/src/app/features/sales/sales-page/sale-detail-page/sale-detail-page.component.ts +++ b/client/src/app/features/sales/sales-page/sale-detail-page/sale-detail-page.component.ts @@ -14,6 +14,7 @@ import { NotificationService } from 'src/app/core/services/notification.service' //Models import { Sale } from 'src/app/core/services/model/sale.interface'; import { Lot } from 'src/app/core/services/model/lot.interface'; +import { SaleInfo } from 'src/app/core/services/model/saleInfo.interface'; @Component({ selector: 'app-favorites-page', diff --git a/client/src/app/features/sales/sales-page/sales-page.component.html b/client/src/app/features/sales/sales-page/sales-page.component.html index afcea8f..9d9ab91 100644 --- a/client/src/app/features/sales/sales-page/sales-page.component.html +++ b/client/src/app/features/sales/sales-page/sales-page.component.html @@ -60,34 +60,48 @@ Plateforme - Interencheres + {{element.platform}} - + - + - + + + + + Action + + + format_list_numbered Prepare + play_arrow Follow + stop Stop Following + Reset to Ready + delete Delete + + - + @@ -126,7 +140,7 @@ Plateforme - Interencheres + {{element.platform}} diff --git a/client/src/app/features/sales/sales-page/sales-page.component.ts b/client/src/app/features/sales/sales-page/sales-page.component.ts index 74063a5..aa57f6e 100644 --- a/client/src/app/features/sales/sales-page/sales-page.component.ts +++ b/client/src/app/features/sales/sales-page/sales-page.component.ts @@ -7,7 +7,8 @@ import * as moment from 'moment'; // Services import { apiService } from 'src/app/core/services/api.service'; import { NotificationService } from 'src/app/core/services/notification.service'; -import { SaleInfo } from 'src/app/core/services/model/saleInfo.interface'; + +import { Sale } from 'src/app/core/services/model/sale.interface'; @Component({ selector: 'app-favorites-page', @@ -18,7 +19,7 @@ export class SalesPageComponent implements OnInit { url: string = ''; refreshSalesId: any; - displayedColumns: string[] = ['title', 'date', 'house', 'plateform', 'prepare', 'follow', 'delete']; + displayedColumns: string[] = ['title', 'date', 'house', 'plateform', 'action']; displayedColumnsOld: string[] = ['title', 'date', 'house', 'plateform', 'postProcessing', 'delete']; futureSales = [] @@ -48,14 +49,14 @@ export class SalesPageComponent implements OnInit { refreshSales(): void { this.apiService.getAllSale().subscribe((data: any) => { console.log(data); - const today = moment(); + const today = moment().startOf('day'); this.futureSales = data - .filter((element: SaleInfo) => moment(element.date).isAfter(today)) + .filter((element: Sale) => moment(element.date).isAfter(today)) .sort((a: any, b: any) => moment(a.date).isAfter(b.date) ? 1 : -1); this.pastSales = data - .filter((element: SaleInfo) => moment(element.date).isBefore(today)) + .filter((element: Sale) => moment(element.date).isBefore(today)) .sort((a: any, b: any) => moment(a.date).isAfter(b.date) ? 1 : -1); }); } @@ -67,9 +68,9 @@ export class SalesPageComponent implements OnInit { }, 5000); } - prepareSale(saleInfo: SaleInfo): void { + prepareSale(Sale: Sale): void { - this.apiService.prepareSale(saleInfo).subscribe( data => { + this.apiService.prepareSale(Sale).subscribe( data => { console.log(data); this.refreshSales(); this.notificationService.openSnackBar("Prepare Sale"); @@ -77,9 +78,9 @@ export class SalesPageComponent implements OnInit { }) } - followSale(saleInfo: SaleInfo): void { + followSale(Sale: Sale): void { - this.apiService.followSale(saleInfo).subscribe( data => { + this.apiService.followSale(Sale).subscribe( data => { console.log(data); this.refreshSales(); this.notificationService.openSnackBar("Sale followed"); @@ -87,9 +88,9 @@ export class SalesPageComponent implements OnInit { }) } - stopFollowSale(saleInfo: SaleInfo): void { - saleInfo.status = "askStop"; - this.apiService.updateSale(saleInfo).subscribe( data => { + stopFollowSale(Sale: Sale): void { + Sale.status = "askStop"; + this.apiService.updateSale(Sale).subscribe( data => { this.refreshSales(); this.notificationService.openSnackBar("Sale Stopping..."); }) @@ -102,6 +103,10 @@ export class SalesPageComponent implements OnInit { }) } + resetToReady(_id: string): void { + this.apiService.resetSaleToReady(_id) + } + navigateToSaleDetail(id: string) { console.log(id); clearInterval(this.refreshSalesId);