Compare commits
2 Commits
9763289c2f
...
00f45ae6c7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
00f45ae6c7 | ||
|
|
1a5d3a570a |
@@ -47,6 +47,21 @@ th, td {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.product-list-root {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
.product-list-loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 10;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
mat-paginator {
|
||||
width: 100%;
|
||||
overflow: hidden;
|
||||
|
||||
@@ -1,16 +1,27 @@
|
||||
<section class="crud">
|
||||
<div class="toolbar">
|
||||
<button mat-raised-button color="primary" (click)="create()">
|
||||
<button mat-raised-button
|
||||
color="primary"
|
||||
(click)="create()"
|
||||
[disabled]="isLoading">
|
||||
<mat-icon>add</mat-icon> Nouveau produit
|
||||
</button>
|
||||
|
||||
<mat-form-field appearance="outline" class="filter">
|
||||
<mat-label>Filtrer</mat-label>
|
||||
<input matInput [formControl]="filterCtrl" placeholder="Nom, ID, catégorie, marque, fournisseur…">
|
||||
<input matInput
|
||||
[formControl]="filterCtrl"
|
||||
placeholder="Nom, ID, catégorie, marque, fournisseur…"
|
||||
[disabled]="isLoading">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
|
||||
<div class="mat-elevation-z2">
|
||||
<div class="mat-elevation-z2 product-list-root">
|
||||
<!-- Overlay de chargement -->
|
||||
<div class="product-list-loading-overlay" *ngIf="isLoading">
|
||||
<mat-spinner diameter="48"></mat-spinner>
|
||||
</div>
|
||||
|
||||
<table mat-table [dataSource]="dataSource" matSort>
|
||||
|
||||
<ng-container matColumnDef="id">
|
||||
@@ -51,8 +62,19 @@
|
||||
<ng-container matColumnDef="actions">
|
||||
<th mat-header-cell *matHeaderCellDef>Actions</th>
|
||||
<td mat-cell *matCellDef="let el">
|
||||
<button mat-icon-button (click)="edit(el)" aria-label="edit"><mat-icon>edit</mat-icon></button>
|
||||
<button mat-icon-button color="warn" (click)="remove(el)" aria-label="delete"><mat-icon>delete</mat-icon></button>
|
||||
<button mat-icon-button
|
||||
aria-label="edit"
|
||||
(click)="edit(el)"
|
||||
[disabled]="isLoading">
|
||||
<mat-icon>edit</mat-icon>
|
||||
</button>
|
||||
<button mat-icon-button
|
||||
color="warn"
|
||||
aria-label="delete"
|
||||
(click)="remove(el)"
|
||||
[disabled]="isLoading">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
</td>
|
||||
</ng-container>
|
||||
|
||||
@@ -60,10 +82,17 @@
|
||||
<tr mat-row *matRowDef="let row; columns: displayed;"></tr>
|
||||
|
||||
<tr class="mat-row" *matNoDataRow>
|
||||
<td class="mat-cell" [attr.colspan]="displayed.length">Aucune donnée.</td>
|
||||
<td class="mat-cell" [attr.colspan]="displayed.length">
|
||||
Aucune donnée.
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
|
||||
<mat-paginator [pageSizeOptions]="[5,10,25,100]" [pageSize]="10" aria-label="Pagination"></mat-paginator>
|
||||
<mat-paginator
|
||||
[pageSizeOptions]="[5,10,25,100]"
|
||||
[pageSize]="10"
|
||||
aria-label="Pagination"
|
||||
[disabled]="isLoading">
|
||||
</mat-paginator>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
@@ -13,7 +13,8 @@ import {MatButton, MatIconButton} from '@angular/material/button';
|
||||
import {MatIcon} from '@angular/material/icon';
|
||||
import {FormBuilder, ReactiveFormsModule} from '@angular/forms';
|
||||
import {MatDialog, MatDialogModule} from '@angular/material/dialog';
|
||||
import {forkJoin} from 'rxjs';
|
||||
import {MatProgressSpinnerModule} from '@angular/material/progress-spinner';
|
||||
import {forkJoin, finalize} from 'rxjs';
|
||||
|
||||
import {PsItem} from '../../interfaces/ps-item';
|
||||
import {ProductListItem} from '../../interfaces/product-list-item';
|
||||
@@ -32,7 +33,8 @@ import {ProductDialogData, PsProductDialogComponent} from '../ps-product-dialog/
|
||||
MatSortModule, MatPaginatorModule,
|
||||
MatFormField, MatLabel, MatInput,
|
||||
MatButton, MatIconButton, MatIcon,
|
||||
MatDialogModule
|
||||
MatDialogModule,
|
||||
MatProgressSpinnerModule
|
||||
]
|
||||
})
|
||||
export class PsProductCrudComponent implements OnInit {
|
||||
@@ -40,26 +42,24 @@ export class PsProductCrudComponent implements OnInit {
|
||||
private readonly ps = inject(PrestashopService);
|
||||
private readonly dialog = inject(MatDialog);
|
||||
|
||||
// référentiels
|
||||
categories: PsItem[] = [];
|
||||
manufacturers: PsItem[] = [];
|
||||
suppliers: PsItem[] = [];
|
||||
|
||||
// maps d’affichage
|
||||
private catMap = new Map<number, string>();
|
||||
private manMap = new Map<number, string>();
|
||||
private supMap = new Map<number, string>();
|
||||
|
||||
// table
|
||||
displayed: string[] = ['id', 'name', 'category', 'manufacturer', 'supplier', 'priceTtc', 'quantity', 'actions'];
|
||||
dataSource = new MatTableDataSource<any>([]);
|
||||
@ViewChild(MatPaginator) paginator!: MatPaginator;
|
||||
@ViewChild(MatSort) sort!: MatSort;
|
||||
@ViewChild(MatTable) table!: MatTable<any>;
|
||||
|
||||
// filtre
|
||||
filterCtrl = this.fb.control<string>('');
|
||||
|
||||
isLoading = false;
|
||||
|
||||
ngOnInit(): void {
|
||||
forkJoin({
|
||||
cats: this.ps.list('categories'),
|
||||
@@ -73,6 +73,7 @@ export class PsProductCrudComponent implements OnInit {
|
||||
this.manMap = new Map(this.manufacturers.map(x => [x.id, x.name]));
|
||||
this.suppliers = sups ?? [];
|
||||
this.supMap = new Map(this.suppliers.map(x => [x.id, x.name]));
|
||||
|
||||
this.reload();
|
||||
},
|
||||
error: err => {
|
||||
@@ -80,7 +81,6 @@ export class PsProductCrudComponent implements OnInit {
|
||||
}
|
||||
});
|
||||
|
||||
// filtre client
|
||||
this.filterCtrl.valueChanges.subscribe(v => {
|
||||
this.dataSource.filter = (v ?? '').toString().trim().toLowerCase();
|
||||
if (this.paginator) this.paginator.firstPage();
|
||||
@@ -133,10 +133,24 @@ export class PsProductCrudComponent implements OnInit {
|
||||
}
|
||||
|
||||
reload() {
|
||||
this.ps.listProducts().subscribe(p => this.bindProducts(p));
|
||||
this.isLoading = true;
|
||||
this.ps.listProducts()
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
this.isLoading = false;
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: p => this.bindProducts(p),
|
||||
error: err => {
|
||||
console.error('Erreur lors du chargement des produits', err);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
create() {
|
||||
if (this.isLoading) return;
|
||||
|
||||
const data: ProductDialogData = {
|
||||
mode: 'create',
|
||||
refs: {
|
||||
@@ -145,12 +159,16 @@ export class PsProductCrudComponent implements OnInit {
|
||||
suppliers: this.suppliers
|
||||
}
|
||||
};
|
||||
this.dialog.open(PsProductDialogComponent, {width: '900px', data}).afterClosed().subscribe(ok => {
|
||||
this.dialog.open(PsProductDialogComponent, {width: '900px', data})
|
||||
.afterClosed()
|
||||
.subscribe(ok => {
|
||||
if (ok) this.reload();
|
||||
});
|
||||
}
|
||||
|
||||
edit(row: ProductListItem & { priceHt?: number }) {
|
||||
if (this.isLoading) return;
|
||||
|
||||
const data: ProductDialogData = {
|
||||
mode: 'edit',
|
||||
productRow: row,
|
||||
@@ -160,16 +178,29 @@ export class PsProductCrudComponent implements OnInit {
|
||||
suppliers: this.suppliers
|
||||
}
|
||||
};
|
||||
this.dialog.open(PsProductDialogComponent, {width: '900px', data}).afterClosed().subscribe(ok => {
|
||||
this.dialog.open(PsProductDialogComponent, {width: '900px', data})
|
||||
.afterClosed()
|
||||
.subscribe(ok => {
|
||||
if (ok) this.reload();
|
||||
});
|
||||
}
|
||||
|
||||
remove(row: ProductListItem) {
|
||||
if (this.isLoading) return;
|
||||
if (!confirm(`Supprimer le produit "${row.name}" (#${row.id}) ?`)) return;
|
||||
this.ps.deleteProduct(row.id).subscribe({
|
||||
|
||||
this.isLoading = true;
|
||||
this.ps.deleteProduct(row.id)
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: () => this.reload(),
|
||||
error: (e: unknown) => alert('Erreur: ' + (e instanceof Error ? e.message : String(e)))
|
||||
error: (e: unknown) => {
|
||||
this.isLoading = false;
|
||||
alert('Erreur: ' + (e instanceof Error ? e.message : String(e)));
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -76,6 +76,24 @@
|
||||
font-size: 40px;
|
||||
}
|
||||
|
||||
/* Bouton de suppression (croix rouge) */
|
||||
.carousel-delete-btn {
|
||||
position: absolute;
|
||||
top: 6px;
|
||||
right: 6px;
|
||||
background: rgba(255, 255, 255, 0.9);
|
||||
border-radius: 4px;
|
||||
padding: 2px;
|
||||
box-shadow: 0 1px 4px rgba(0, 0, 0, 0.25);
|
||||
}
|
||||
|
||||
.carousel-delete-btn mat-icon {
|
||||
font-size: 20px;
|
||||
width: 20px;
|
||||
height: 20px;
|
||||
color: #e53935;
|
||||
}
|
||||
|
||||
/* Bandeau de vignettes */
|
||||
|
||||
.carousel-thumbs {
|
||||
@@ -85,15 +103,42 @@
|
||||
}
|
||||
|
||||
.thumb-item {
|
||||
position: relative;
|
||||
width: 64px;
|
||||
height: 64px;
|
||||
border-radius: 4px;
|
||||
overflow: hidden;
|
||||
overflow: hidden; /* tu peux laisser comme ça */
|
||||
border: 2px solid transparent;
|
||||
flex: 0 0 auto;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
/* Bouton de suppression sur les vignettes */
|
||||
.thumb-delete-btn {
|
||||
position: absolute;
|
||||
top: 2px;
|
||||
right: 2px;
|
||||
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
min-width: 18px;
|
||||
padding: 0;
|
||||
|
||||
line-height: 18px;
|
||||
|
||||
background: transparent;
|
||||
border-radius: 0;
|
||||
box-shadow: none;
|
||||
}
|
||||
|
||||
.thumb-delete-btn mat-icon {
|
||||
font-size: 16px;
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
|
||||
color: #e53935; /* rouge discret mais lisible */
|
||||
}
|
||||
|
||||
.thumb-item.active {
|
||||
border-color: #1976d2;
|
||||
}
|
||||
@@ -118,3 +163,19 @@
|
||||
.thumb-placeholder mat-icon {
|
||||
font-size: 28px;
|
||||
}
|
||||
|
||||
.dialog-root {
|
||||
position: relative;
|
||||
}
|
||||
|
||||
/* Overlay plein écran dans le dialog pendant la sauvegarde */
|
||||
.dialog-loading-overlay {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
background: rgba(255, 255, 255, 0.6);
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
z-index: 50;
|
||||
pointer-events: all;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,14 @@
|
||||
<h2 mat-dialog-title>{{ mode === 'create' ? 'Nouveau produit' : 'Modifier le produit' }}</h2>
|
||||
|
||||
<div mat-dialog-content class="grid" [formGroup]="form">
|
||||
<div class="dialog-root">
|
||||
<!-- Overlay de chargement -->
|
||||
@if (isSaving) {
|
||||
<div class="dialog-loading-overlay">
|
||||
<mat-spinner diameter="48"></mat-spinner>
|
||||
</div>
|
||||
}
|
||||
|
||||
<div mat-dialog-content class="grid" [formGroup]="form">
|
||||
|
||||
<!-- CARROUSEL IMAGES -->
|
||||
<div class="col-12 carousel">
|
||||
@@ -31,6 +39,23 @@
|
||||
[disabled]="carouselItems.length <= 1">
|
||||
<mat-icon>chevron_right</mat-icon>
|
||||
</button>
|
||||
|
||||
<!-- Bouton de suppression (croix rouge) -->
|
||||
@if (carouselItems.length && !carouselItems[currentIndex].isPlaceholder) {
|
||||
<button mat-icon-button
|
||||
class="carousel-delete-btn"
|
||||
(click)="onDeleteCurrentImage()">
|
||||
<mat-icon>delete</mat-icon>
|
||||
</button>
|
||||
}
|
||||
|
||||
<!-- Bouton suivant -->
|
||||
<button mat-icon-button
|
||||
class="carousel-nav-btn right"
|
||||
(click)="next()"
|
||||
[disabled]="carouselItems.length <= 1">
|
||||
<mat-icon>chevron_right</mat-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<!-- Bandeau de vignettes -->
|
||||
@@ -40,6 +65,14 @@
|
||||
[class.active]="i === currentIndex"
|
||||
(click)="onThumbClick(i)">
|
||||
@if (!item.isPlaceholder) {
|
||||
|
||||
<!-- Bouton suppression vignette -->
|
||||
<button mat-icon-button
|
||||
class="thumb-delete-btn"
|
||||
(click)="onDeleteThumb(i, $event)">
|
||||
<mat-icon>close</mat-icon>
|
||||
</button>
|
||||
|
||||
<img class="thumb-img" [src]="item.src" alt="Vignette produit">
|
||||
} @else {
|
||||
<div class="thumb-placeholder" (click)="fileInput.click()">
|
||||
@@ -126,12 +159,25 @@
|
||||
<mat-label>Quantité</mat-label>
|
||||
<input matInput type="number" step="1" min="0" formControlName="quantity">
|
||||
</mat-form-field>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Actions -->
|
||||
<div mat-dialog-actions>
|
||||
<button mat-button (click)="close()">Annuler</button>
|
||||
<button mat-raised-button color="primary" (click)="save()" [disabled]="form.invalid">
|
||||
{{ mode === 'create' ? 'Créer' : 'Enregistrer' }}
|
||||
<mat-dialog-actions align="end">
|
||||
<button mat-button
|
||||
(click)="close()"
|
||||
[disabled]="isSaving">
|
||||
Annuler
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button mat-raised-button
|
||||
color="primary"
|
||||
(click)="save()"
|
||||
[disabled]="form.invalid || isSaving">
|
||||
@if (!isSaving) {
|
||||
Enregistrer
|
||||
} @else {
|
||||
Enregistrement...
|
||||
}
|
||||
</button>
|
||||
</mat-dialog-actions>
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
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';
|
||||
import { MatInput } from '@angular/material/input';
|
||||
import { MatSelectModule } from '@angular/material/select';
|
||||
import { MatCheckbox } from '@angular/material/checkbox';
|
||||
import { MatButton, MatIconButton } from '@angular/material/button';
|
||||
import {CommonModule} from '@angular/common';
|
||||
import {FormBuilder, ReactiveFormsModule, Validators} from '@angular/forms';
|
||||
import {MatFormField, MatLabel} from '@angular/material/form-field';
|
||||
import {MatInput} from '@angular/material/input';
|
||||
import {MatSelectModule} from '@angular/material/select';
|
||||
import {MatCheckbox} from '@angular/material/checkbox';
|
||||
import {MatButton, MatIconButton} from '@angular/material/button';
|
||||
import {
|
||||
MatDialogRef,
|
||||
MAT_DIALOG_DATA,
|
||||
@@ -13,13 +13,14 @@ import {
|
||||
MatDialogContent,
|
||||
MatDialogTitle
|
||||
} from '@angular/material/dialog';
|
||||
import { MatIcon } from '@angular/material/icon';
|
||||
import {MatIcon} from '@angular/material/icon';
|
||||
|
||||
import { catchError, forkJoin, of, Observable } from 'rxjs';
|
||||
import {catchError, forkJoin, of, Observable, finalize} from 'rxjs';
|
||||
|
||||
import { PsItem } from '../../interfaces/ps-item';
|
||||
import { ProductListItem } from '../../interfaces/product-list-item';
|
||||
import { PrestashopService } from '../../services/prestashop.serivce';
|
||||
import {PsItem} from '../../interfaces/ps-item';
|
||||
import {ProductListItem} from '../../interfaces/product-list-item';
|
||||
import {PrestashopService} from '../../services/prestashop.serivce';
|
||||
import {MatProgressSpinner} from '@angular/material/progress-spinner';
|
||||
|
||||
export type ProductDialogData = {
|
||||
mode: 'create' | 'edit';
|
||||
@@ -38,7 +39,7 @@ type CarouselItem = { src: string; isPlaceholder: boolean };
|
||||
CommonModule, ReactiveFormsModule,
|
||||
MatFormField, MatLabel, MatInput, MatSelectModule, MatCheckbox,
|
||||
MatButton, MatDialogActions, MatDialogContent, MatDialogTitle,
|
||||
MatIcon, MatIconButton
|
||||
MatIcon, MatIconButton, MatProgressSpinner
|
||||
]
|
||||
})
|
||||
export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
@@ -48,7 +49,10 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
constructor(
|
||||
@Inject(MAT_DIALOG_DATA) public data: ProductDialogData,
|
||||
private readonly dialogRef: MatDialogRef<PsProductDialogComponent>
|
||||
) {}
|
||||
) {
|
||||
}
|
||||
|
||||
isSaving = false;
|
||||
|
||||
mode!: 'create' | 'edit';
|
||||
categories: PsItem[] = [];
|
||||
@@ -167,11 +171,11 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
const qty$ = this.ps.getProductQuantity(r.id).pipe(catchError(() => of(0)));
|
||||
const imgs$ = this.ps.getProductImageUrls(r.id).pipe(catchError(() => of<string[]>([])));
|
||||
const flags$ = this.ps.getProductFlags(r.id).pipe(
|
||||
catchError(() => of({ complete: false, hasManual: false, conditionLabel: undefined }))
|
||||
catchError(() => of({complete: false, hasManual: false, conditionLabel: undefined}))
|
||||
);
|
||||
|
||||
forkJoin({ details: details$, qty: qty$, imgs: imgs$, flags: flags$ })
|
||||
.subscribe(({ details, qty, imgs, flags }) => {
|
||||
forkJoin({details: details$, qty: qty$, imgs: imgs$, flags: flags$})
|
||||
.subscribe(({details, qty, imgs, flags}) => {
|
||||
const ttc = this.toTtc(details.priceHt ?? 0);
|
||||
const baseDesc = this.cleanForTextarea(details.description ?? '');
|
||||
this.lastLoadedDescription = baseDesc;
|
||||
@@ -203,7 +207,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 = [];
|
||||
@@ -224,12 +228,12 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
|
||||
private buildCarousel() {
|
||||
const items: CarouselItem[] = [
|
||||
...this.existingImageUrls.map(u => ({ src: u, isPlaceholder: false })),
|
||||
...this.previewUrls.map(u => ({ src: u, isPlaceholder: false }))
|
||||
...this.existingImageUrls.map(u => ({src: u, isPlaceholder: false})),
|
||||
...this.previewUrls.map(u => ({src: u, isPlaceholder: false}))
|
||||
];
|
||||
|
||||
// placeholder en dernier
|
||||
items.push({ src: '', isPlaceholder: true });
|
||||
items.push({src: '', isPlaceholder: true});
|
||||
|
||||
this.carouselItems = items;
|
||||
if (!this.carouselItems.length) {
|
||||
@@ -261,10 +265,13 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
}
|
||||
}
|
||||
|
||||
// -------- Save / close inchangés (à part dto.images) --------
|
||||
// -------- Save / close --------
|
||||
|
||||
save() {
|
||||
if (this.form.invalid) return;
|
||||
if (this.form.invalid || this.isSaving) return;
|
||||
|
||||
this.isSaving = true;
|
||||
this.dialogRef.disableClose = true;
|
||||
|
||||
const v = this.form.getRawValue();
|
||||
const effectiveDescription = (v.description ?? '').trim() || this.lastLoadedDescription;
|
||||
@@ -275,7 +282,7 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
categoryId: +v.categoryId!,
|
||||
manufacturerId: +v.manufacturerId!,
|
||||
supplierId: +v.supplierId!,
|
||||
images: this.images, // toujours les fichiers sélectionnés
|
||||
images: this.images,
|
||||
complete: !!v.complete,
|
||||
hasManual: !!v.hasManual,
|
||||
conditionLabel: v.conditionLabel || undefined,
|
||||
@@ -291,13 +298,99 @@ export class PsProductDialogComponent implements OnInit, OnDestroy {
|
||||
op$ = this.ps.updateProduct(this.productRow.id, dto) as Observable<unknown>;
|
||||
}
|
||||
|
||||
op$.subscribe({
|
||||
op$
|
||||
.pipe(
|
||||
finalize(() => {
|
||||
// si la boîte de dialogue est encore ouverte, on réactive tout
|
||||
this.isSaving = false;
|
||||
this.dialogRef.disableClose = false;
|
||||
})
|
||||
)
|
||||
.subscribe({
|
||||
next: () => this.dialogRef.close(true),
|
||||
error: (e: unknown) => alert('Erreur: ' + (e instanceof Error ? e.message : String(e)))
|
||||
error: (e: unknown) =>
|
||||
alert('Erreur: ' + (e instanceof Error ? e.message : String(e)))
|
||||
});
|
||||
}
|
||||
|
||||
/** Extrait l'id_image depuis une URL FO Presta (.../img/p/.../<id>.jpg) */
|
||||
private extractImageIdFromUrl(url: string): number | null {
|
||||
const m = /\/(\d+)\.(?:jpg|jpeg|png|gif)$/i.exec(url);
|
||||
if (!m) return null;
|
||||
const id = Number(m[1]);
|
||||
return Number.isFinite(id) ? id : null;
|
||||
}
|
||||
|
||||
/** Suppression générique d'une image à l'index donné (carrousel + vignettes) */
|
||||
private deleteImageAtIndex(idx: number) {
|
||||
if (!this.carouselItems.length) return;
|
||||
|
||||
const item = this.carouselItems[idx];
|
||||
if (!item || item.isPlaceholder) return;
|
||||
|
||||
const existingCount = this.existingImageUrls.length;
|
||||
|
||||
// --- Cas 1 : image existante (déjà chez Presta) ---
|
||||
if (idx < existingCount) {
|
||||
if (!this.productRow) return; // sécurité
|
||||
|
||||
const url = this.existingImageUrls[idx];
|
||||
const imageId = this.extractImageIdFromUrl(url);
|
||||
if (!imageId) {
|
||||
alert('Impossible de déterminer l’ID de l’image à supprimer.');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!confirm('Supprimer cette image du produit ?')) return;
|
||||
|
||||
this.ps.deleteProductImage(this.productRow.id, imageId).subscribe({
|
||||
next: () => {
|
||||
// On la retire du tableau local et on reconstruit le carrousel
|
||||
this.existingImageUrls.splice(idx, 1);
|
||||
this.buildCarousel();
|
||||
|
||||
// Repositionnement de l’index si nécessaire
|
||||
if (this.currentIndex >= this.carouselItems.length - 1) {
|
||||
this.currentIndex = Math.max(0, this.carouselItems.length - 2);
|
||||
}
|
||||
},
|
||||
error: (e: unknown) => {
|
||||
alert('Erreur lors de la suppression de l’image : ' + (e instanceof Error ? e.message : String(e)));
|
||||
}
|
||||
});
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
// --- Cas 2 : image locale (nouvelle) ---
|
||||
const localIdx = idx - existingCount;
|
||||
if (localIdx >= 0 && localIdx < this.previewUrls.length) {
|
||||
if (!confirm('Retirer cette image de la sélection ?')) return;
|
||||
|
||||
this.previewUrls.splice(localIdx, 1);
|
||||
this.images.splice(localIdx, 1);
|
||||
this.buildCarousel();
|
||||
|
||||
if (this.currentIndex >= this.carouselItems.length - 1) {
|
||||
this.currentIndex = Math.max(0, this.carouselItems.length - 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// utilisée par la grande image
|
||||
onDeleteCurrentImage() {
|
||||
if (!this.carouselItems.length) return;
|
||||
this.deleteImageAtIndex(this.currentIndex);
|
||||
}
|
||||
|
||||
// utilisée par la croix sur une vignette
|
||||
onDeleteThumb(index: number, event: MouseEvent) {
|
||||
event.stopPropagation();
|
||||
this.deleteImageAtIndex(index);
|
||||
}
|
||||
|
||||
close() {
|
||||
if (this.isSaving) return;
|
||||
this.dialogRef.close(false);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -516,6 +516,16 @@ export class PrestashopService {
|
||||
);
|
||||
}
|
||||
|
||||
deleteProductImage(productId: number, imageId: number) {
|
||||
// Presta : DELETE /images/products/{id_product}/{id_image}
|
||||
return this.http.delete(
|
||||
`${this.base}/images/products/${productId}/${imageId}`,
|
||||
{ responseType: 'text' }
|
||||
).pipe(
|
||||
map(() => true)
|
||||
);
|
||||
}
|
||||
|
||||
// -------- Stock (quantité) — gestion fine via stock_availables
|
||||
|
||||
getProductQuantity(productId: number) {
|
||||
|
||||
@@ -2,4 +2,5 @@ export const environment = {
|
||||
production: true,
|
||||
apiUrl: '/gameovergne-api/api',
|
||||
psUrl: '/gameovergne-api/api/ps',
|
||||
indexBase: '/gameovergne/',
|
||||
};
|
||||
|
||||
@@ -2,4 +2,5 @@ export const environment = {
|
||||
production: false,
|
||||
apiUrl: 'http://localhost:3000/api',
|
||||
psUrl: '/ps',
|
||||
indexBase: '/',
|
||||
};
|
||||
@@ -3,13 +3,17 @@
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Game Over'gne App</title>
|
||||
<base href="/gameovergne/">
|
||||
<script>
|
||||
import {environment} from "./environments/environment.prod";
|
||||
document.write('<base href="' + environment.indexBase + '">');
|
||||
</script>
|
||||
<base href="/">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<link rel="icon" type="image/x-icon" href="favicon.ico">
|
||||
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500&display=swap" rel="stylesheet">
|
||||
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
|
||||
</head>
|
||||
<body class="mat-typography">
|
||||
<app-root></app-root>
|
||||
<app-root></app-root>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user