Added function to manage deliveries
This commit is contained in:
@@ -1,13 +1,14 @@
|
||||
<div class="flex gap-17 ml-20">
|
||||
<app-info-card color="#f59e0b" icon="inbox" value="15"
|
||||
<app-info-card color="#f59e0b" icon="inbox" [value]="productsUnderLimitCount()"
|
||||
description="Produits sous le seuil minimal."></app-info-card>
|
||||
<app-info-card color="#3b82f6" icon="team" value="56" description="Partenaires actifs."></app-info-card>
|
||||
<app-info-card color="#10b981" icon="truck" value="8" description="Livreurs partenaires."></app-info-card>
|
||||
<app-info-card color="#ef4444" icon="shop" value="48"
|
||||
description="Fournisseurs travaillant avec nous."></app-info-card>
|
||||
<app-info-card color="#3b82f6" icon="team" [value]="deliversCount()+suppliersCount()"
|
||||
description="Partenaires actifs."></app-info-card>
|
||||
<app-info-card color="#10b981" icon="truck" [value]=deliversCount()
|
||||
description="Livreurs partenaires."></app-info-card>
|
||||
<app-info-card color="#ef4444" icon="shop" [value]="suppliersCount()"
|
||||
description="Fournisseurs partenaires."></app-info-card>
|
||||
</div>
|
||||
|
||||
<div class="mt-10 flex gap-30">
|
||||
<app-delivery-validator></app-delivery-validator>
|
||||
<app-info-table></app-info-table>
|
||||
</div>
|
||||
@@ -1,19 +1,69 @@
|
||||
import {Component} from '@angular/core';
|
||||
import {Component, inject, signal} from '@angular/core';
|
||||
import {InfoCard} from "../../components/info-card/info-card";
|
||||
import {DeliveryValidator} from "../../components/delivery-validator/delivery-validator";
|
||||
import {InfoTable} from "../../components/info-table/info-table";
|
||||
import {NzNotificationService} from "ng-zorro-antd/notification";
|
||||
import {DeliverersService, ProductsService, SuppliersService} from "../../services/api";
|
||||
import {firstValueFrom} from "rxjs";
|
||||
|
||||
@Component({
|
||||
selector: 'app-welcome',
|
||||
imports: [
|
||||
InfoCard,
|
||||
DeliveryValidator,
|
||||
InfoTable,
|
||||
],
|
||||
templateUrl: './welcome.html',
|
||||
styleUrl: './welcome.css'
|
||||
})
|
||||
|
||||
export class Welcome {
|
||||
private productsService = inject(ProductsService);
|
||||
private deliverersService = inject(DeliverersService);
|
||||
private suppliersService = inject(SuppliersService);
|
||||
private notificationsService = inject(NzNotificationService);
|
||||
|
||||
deliversCount = signal<number>(0);
|
||||
suppliersCount = signal<number>(0);
|
||||
productsUnderLimitCount = signal<number>(0);
|
||||
|
||||
async getDeliverers() {
|
||||
try {
|
||||
const deliverers = await firstValueFrom(this.deliverersService.getAllDelivererEndpoint());
|
||||
this.deliversCount.set(deliverers.length);
|
||||
} catch (e) {
|
||||
this.notificationsService.error(
|
||||
'Error',
|
||||
'Error while getting deliverers.',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async getSuppliers() {
|
||||
try {
|
||||
const suppliers = await firstValueFrom(this.suppliersService.getAllSuppliersEndpoint());
|
||||
this.suppliersCount.set(suppliers.length);
|
||||
} catch (e) {
|
||||
this.notificationsService.error(
|
||||
'Error',
|
||||
'Error while getting suppliers.',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async getProductsUnderLimit() {
|
||||
try {
|
||||
const products = await firstValueFrom(this.productsService.getAllProductsUnderLimitEndpoint());
|
||||
this.productsUnderLimitCount.set(products.length);
|
||||
} catch (e) {
|
||||
this.notificationsService.error(
|
||||
'Error',
|
||||
'Error while getting products.',
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
async ngOnInit() {
|
||||
await this.getDeliverers();
|
||||
await this.getSuppliers();
|
||||
await this.getProductsUnderLimit();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user