diff --git a/backend/entrypoint.sh b/backend/entrypoint.sh index 8013e19..cd79e27 100644 --- a/backend/entrypoint.sh +++ b/backend/entrypoint.sh @@ -5,8 +5,6 @@ echo "DB_URL: $DB_URL" echo "DB_USERNAME: $DB_USERNAME" echo "SPRING_DATASOURCE_URL: $SPRING_DATASOURCE_URL" echo "SLICER_PATH: $SLICER_PATH" -echo "--- ALL ENV VARS ---" -env echo "----------------------------------------------------------------" # Determine which environment variables to use for database connection diff --git a/frontend/src/app/features/calculator/calculator-page.component.ts b/frontend/src/app/features/calculator/calculator-page.component.ts index d8b1dbb..2f67113 100644 --- a/frontend/src/app/features/calculator/calculator-page.component.ts +++ b/frontend/src/app/features/calculator/calculator-page.component.ts @@ -226,9 +226,10 @@ export class CalculatorPageComponent implements OnInit { this.step.set('quote'); } - onItemChange(event: {id?: string, fileName: string, quantity: number}) { + onItemChange(event: {id?: string, index: number, fileName: string, quantity: number}) { // 1. Update local form for consistency (UI feedback) if (this.uploadForm) { + this.uploadForm.updateItemQuantityByIndex(event.index, event.quantity); this.uploadForm.updateItemQuantityByName(event.fileName, event.quantity); } diff --git a/frontend/src/app/features/calculator/components/quote-result/quote-result.component.ts b/frontend/src/app/features/calculator/components/quote-result/quote-result.component.ts index 3320816..a97b1b8 100644 --- a/frontend/src/app/features/calculator/components/quote-result/quote-result.component.ts +++ b/frontend/src/app/features/calculator/components/quote-result/quote-result.component.ts @@ -22,7 +22,7 @@ export class QuoteResultComponent implements OnDestroy { result = input.required(); consult = output(); proceed = output(); - itemChange = output<{id?: string, fileName: string, quantity: number}>(); + itemChange = output<{id?: string, index: number, fileName: string, quantity: number}>(); // Local mutable state for items to handle quantity changes items = signal([]); @@ -83,6 +83,7 @@ export class QuoteResultComponent implements OnDestroy { this.itemChange.emit({ id: item.id, + index, fileName: item.fileName, quantity: normalizedQty }); diff --git a/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts b/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts index 9bacf3f..eb9d39d 100644 --- a/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts +++ b/frontend/src/app/features/calculator/components/upload-form/upload-form.component.ts @@ -199,11 +199,28 @@ export class UploadFormComponent implements OnInit { } } - updateItemQuantityByName(fileName: string, quantity: number) { + updateItemQuantityByIndex(index: number, quantity: number) { + if (!Number.isInteger(index) || index < 0) return; + const normalizedQty = this.normalizeQuantity(quantity); + this.items.update(current => { + if (index >= current.length) return current; + const updated = [...current]; + updated[index] = { ...updated[index], quantity: normalizedQty }; + return updated; + }); + } + + updateItemQuantityByName(fileName: string, quantity: number) { + const targetName = this.normalizeFileName(fileName); + const normalizedQty = this.normalizeQuantity(quantity); + + this.items.update(current => { + let matched = false; return current.map(item => { - if (item.file.name === fileName) { - return { ...item, quantity }; + if (!matched && this.normalizeFileName(item.file.name) === targetName) { + matched = true; + return { ...item, quantity: normalizedQty }; } return item; }); @@ -239,14 +256,9 @@ export class UploadFormComponent implements OnInit { updateItemQuantity(index: number, event: Event) { const input = event.target as HTMLInputElement; - let val = parseInt(input.value, 10); - if (isNaN(val) || val < 1) val = 1; - - this.items.update(current => { - const updated = [...current]; - updated[index] = { ...updated[index], quantity: val }; - return updated; - }); + const parsed = parseInt(input.value, 10); + const quantity = Number.isFinite(parsed) ? parsed : 1; + this.updateItemQuantityByIndex(index, quantity); } updateItemColor(index: number, newSelection: string | { colorName: string; filamentVariantId?: number }) { @@ -387,4 +399,19 @@ export class UploadFormComponent implements OnInit { this.form.get('itemsTouched')?.setValue(true); } } + + private normalizeQuantity(quantity: number): number { + if (!Number.isFinite(quantity) || quantity < 1) { + return 1; + } + return Math.floor(quantity); + } + + private normalizeFileName(fileName: string): string { + return (fileName || '') + .split(/[\\/]/) + .pop() + ?.trim() + .toLowerCase() ?? ''; + } }