restore previous version
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
// File: src/app/components/ps-product-dialog/ps-product-dialog.component.ts
|
||||
import { Component, Inject, OnInit, inject, OnDestroy } from '@angular/core';
|
||||
import {Component, Inject, OnInit, inject, OnDestroy} from '@angular/core';
|
||||
import { CommonModule } from '@angular/common';
|
||||
import { FormBuilder, ReactiveFormsModule, Validators } from '@angular/forms';
|
||||
import { MatFormField, MatLabel } from '@angular/material/form-field';
|
||||
@@ -21,7 +20,6 @@ import { catchError, forkJoin, of, Observable } from 'rxjs';
|
||||
import { PsItem } from '../../interfaces/ps-item';
|
||||
import { ProductListItem } from '../../interfaces/product-list-item';
|
||||
import { PrestashopService } from '../../services/prestashop.serivce';
|
||||
import { PsProduct } from '../../interfaces/ps-product'; // si tu as une interface dédiée
|
||||
|
||||
export type ProductDialogData = {
|
||||
mode: 'create' | 'edit';
|
||||
@@ -89,7 +87,6 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
// ---------- Helpers locaux ----------
|
||||
|
||||
// utilisé seulement pour pré-afficher un TTC approximatif à partir du HT de la liste
|
||||
private toTtc(ht: number) {
|
||||
return Math.round(((ht * 1.2) + Number.EPSILON) * 100) / 100;
|
||||
}
|
||||
@@ -151,7 +148,6 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
if (this.mode === 'edit' && this.productRow) {
|
||||
const r = this.productRow;
|
||||
|
||||
// pré-remplissage rapide avec la ligne de liste (HT -> TTC approximatif)
|
||||
const immediateTtc = r.priceHt == null ? 0 : this.toTtc(r.priceHt);
|
||||
this.form.patchValue({
|
||||
name: r.name,
|
||||
@@ -162,7 +158,11 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
});
|
||||
|
||||
const details$ = this.ps.getProductDetails(r.id).pipe(
|
||||
catchError(() => of<PsProduct | null>(null))
|
||||
catchError(() => of({
|
||||
id: r.id, name: r.name, description: '',
|
||||
id_manufacturer: r.id_manufacturer, id_supplier: r.id_supplier,
|
||||
id_category_default: r.id_category_default, priceHt: r.priceHt ?? 0
|
||||
}))
|
||||
);
|
||||
const qty$ = this.ps.getProductQuantity(r.id).pipe(catchError(() => of(0)));
|
||||
const imgs$ = this.ps.getProductImageUrls(r.id).pipe(catchError(() => of<string[]>([])));
|
||||
@@ -172,23 +172,20 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
forkJoin({ details: details$, qty: qty$, imgs: imgs$, flags: flags$ })
|
||||
.subscribe(({ details, qty, imgs, flags }) => {
|
||||
const baseDesc = this.cleanForTextarea(details?.description ?? '');
|
||||
const ttc = this.toTtc(details.priceHt ?? 0);
|
||||
const baseDesc = this.cleanForTextarea(details.description ?? '');
|
||||
this.lastLoadedDescription = baseDesc;
|
||||
|
||||
this.form.patchValue({
|
||||
// description depuis le backend (déjà propre / nettoyée normalement)
|
||||
description: baseDesc,
|
||||
// flags
|
||||
complete: flags.complete,
|
||||
hasManual: flags.hasManual,
|
||||
conditionLabel: flags.conditionLabel || '',
|
||||
// TTC "réel" calculé par le backend (si dispo) sinon on garde la valeur actuelle
|
||||
priceTtc: (details?.priceTtc ?? this.form.value.priceTtc ?? 0),
|
||||
priceTtc: (ttc || this.form.value.priceTtc || 0),
|
||||
quantity: qty,
|
||||
// ids de ref issus du DTO backend
|
||||
categoryId: (details?.categoryId ?? this.form.value.categoryId) ?? null,
|
||||
manufacturerId: (details?.manufacturerId ?? this.form.value.manufacturerId) ?? null,
|
||||
supplierId: (details?.supplierId ?? this.form.value.supplierId) ?? null
|
||||
categoryId: (details.id_category_default ?? this.form.value.categoryId) ?? null,
|
||||
manufacturerId: (details.id_manufacturer ?? this.form.value.manufacturerId) ?? null,
|
||||
supplierId: (details.id_supplier ?? this.form.value.supplierId) ?? null
|
||||
});
|
||||
|
||||
this.existingImageUrls = imgs;
|
||||
@@ -206,7 +203,7 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
const fl = (ev.target as HTMLInputElement).files;
|
||||
|
||||
// Nettoyage des anciens objectURL
|
||||
for (let url of this.previewUrls) {
|
||||
for(let url of this.previewUrls) {
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
this.previewUrls = [];
|
||||
@@ -264,7 +261,7 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
// -------- Save / close --------
|
||||
// -------- Save / close inchangés (à part dto.images) --------
|
||||
|
||||
save() {
|
||||
if (this.form.invalid) return;
|
||||
@@ -272,7 +269,7 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
const v = this.form.getRawValue();
|
||||
const effectiveDescription = (v.description ?? '').trim() || this.lastLoadedDescription;
|
||||
|
||||
const dto: PsProduct = {
|
||||
const dto = {
|
||||
name: v.name!,
|
||||
description: effectiveDescription,
|
||||
categoryId: +v.categoryId!,
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user