first commit
This commit is contained in:
+129
@@ -0,0 +1,129 @@
|
||||
import { Component, OnInit, ViewChild, AfterViewInit } from '@angular/core';
|
||||
import { MatDialog } from '@angular/material/dialog';
|
||||
import { Router, ActivatedRoute } from '@angular/router';
|
||||
import { MatPaginator } from '@angular/material/paginator';
|
||||
import { MatTableDataSource } from '@angular/material/table';
|
||||
import { MatSort } from '@angular/material/sort';
|
||||
|
||||
import * as moment from 'moment';
|
||||
|
||||
// Services
|
||||
import { apiService } from 'src/app/core/services/api.service';
|
||||
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';
|
||||
|
||||
@Component({
|
||||
selector: 'app-favorites-page',
|
||||
templateUrl: './sale-detail-page.component.html',
|
||||
styleUrls: ['./sale-detail-page.component.css']
|
||||
})
|
||||
|
||||
|
||||
export class SaleDetailPageComponent implements OnInit, AfterViewInit {
|
||||
|
||||
id: any = '';
|
||||
Sale: Sale;
|
||||
displayedColumns: string[] = ['lotNum', 'title', 'estimateLow', 'estimateHigh', 'price', 'nbrBids'];
|
||||
|
||||
lotList: MatTableDataSource<Lot> = new MatTableDataSource<Lot>();
|
||||
@ViewChild(MatPaginator) paginator?: MatPaginator;
|
||||
@ViewChild(MatSort) sort?: MatSort;
|
||||
|
||||
constructor(
|
||||
private route: ActivatedRoute,
|
||||
private notificationService: NotificationService,
|
||||
private router: Router,
|
||||
public dialog: MatDialog,
|
||||
private apiService: apiService) {
|
||||
|
||||
this.Sale = {
|
||||
_id: { $oid: '' },
|
||||
idPlatform: '',
|
||||
platform: '',
|
||||
url: '',
|
||||
title: '',
|
||||
date: '',
|
||||
location: '',
|
||||
saleHouseName: '',
|
||||
status: '',
|
||||
postProcessing: {
|
||||
nbrLots: 0,
|
||||
duration: 0,
|
||||
durationPerLots: '',
|
||||
totalAmount: 0,
|
||||
averageAmount: '',
|
||||
medianAmount: ''
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
ngOnInit(): void {
|
||||
this.route.paramMap.subscribe(params => {
|
||||
this.id = params.get('id');
|
||||
|
||||
this.getSale();
|
||||
this.getLotList();
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit(): void {
|
||||
|
||||
}
|
||||
|
||||
getSale(){
|
||||
this.apiService.getSale(this.id).subscribe((sale: Sale) => {
|
||||
this.Sale = sale;
|
||||
});
|
||||
}
|
||||
|
||||
getLotList(){
|
||||
this.apiService.getLotsBySale(this.id).subscribe((lotList: Lot[]) => {
|
||||
|
||||
// adding the Bids length info
|
||||
lotList = lotList.map((lot) => {
|
||||
return {...lot, bidsLength: lot.Bids ? lot.Bids.length : 0};
|
||||
});
|
||||
|
||||
// adding the Auctionned ammount info
|
||||
lotList = lotList.map((lot) => {
|
||||
return {...lot, auctionedAmount: lot.auctioned?.amount ? lot.auctioned?.amount : 0};
|
||||
});
|
||||
|
||||
console.log(lotList);
|
||||
this.lotList = new MatTableDataSource(lotList);
|
||||
this.lotList.paginator = this.paginator ?? null;
|
||||
this.lotList.sort = this.sort ?? null;
|
||||
});
|
||||
}
|
||||
|
||||
getDurationInMinutes(duration: number): number {
|
||||
return Math.floor(duration / 60);
|
||||
}
|
||||
|
||||
getTimePerLot(duration: number): string {
|
||||
|
||||
const minutes = Math.floor((duration % 3600) / 60);
|
||||
const seconds = duration % 60;
|
||||
|
||||
let returnString = '';
|
||||
|
||||
if (minutes > 0) {
|
||||
returnString += minutes + 'm ';
|
||||
}
|
||||
returnString += seconds + 's';
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
parseToNumber(value: string | null): number {
|
||||
return parseFloat(value || '0');
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user