fix(front-end): quantity changes and normalization
Some checks failed
Build, Test, Deploy and Analysis / qodana (push) Failing after 12s
Build, Test, Deploy and Analysis / test-backend (push) Successful in 37s
Build, Test, Deploy and Analysis / build-and-push (push) Successful in 25s
Build, Test, Deploy and Analysis / deploy (push) Successful in 10s

This commit is contained in:
2026-03-03 12:05:00 +01:00
parent 90bdb5384d
commit c680486157
4 changed files with 42 additions and 15 deletions

View File

@@ -5,8 +5,6 @@ echo "DB_URL: $DB_URL"
echo "DB_USERNAME: $DB_USERNAME" echo "DB_USERNAME: $DB_USERNAME"
echo "SPRING_DATASOURCE_URL: $SPRING_DATASOURCE_URL" echo "SPRING_DATASOURCE_URL: $SPRING_DATASOURCE_URL"
echo "SLICER_PATH: $SLICER_PATH" echo "SLICER_PATH: $SLICER_PATH"
echo "--- ALL ENV VARS ---"
env
echo "----------------------------------------------------------------" echo "----------------------------------------------------------------"
# Determine which environment variables to use for database connection # Determine which environment variables to use for database connection

View File

@@ -226,9 +226,10 @@ export class CalculatorPageComponent implements OnInit {
this.step.set('quote'); 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) // 1. Update local form for consistency (UI feedback)
if (this.uploadForm) { if (this.uploadForm) {
this.uploadForm.updateItemQuantityByIndex(event.index, event.quantity);
this.uploadForm.updateItemQuantityByName(event.fileName, event.quantity); this.uploadForm.updateItemQuantityByName(event.fileName, event.quantity);
} }

View File

@@ -22,7 +22,7 @@ export class QuoteResultComponent implements OnDestroy {
result = input.required<QuoteResult>(); result = input.required<QuoteResult>();
consult = output<void>(); consult = output<void>();
proceed = output<void>(); proceed = output<void>();
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 // Local mutable state for items to handle quantity changes
items = signal<QuoteItem[]>([]); items = signal<QuoteItem[]>([]);
@@ -83,6 +83,7 @@ export class QuoteResultComponent implements OnDestroy {
this.itemChange.emit({ this.itemChange.emit({
id: item.id, id: item.id,
index,
fileName: item.fileName, fileName: item.fileName,
quantity: normalizedQty quantity: normalizedQty
}); });

View File

@@ -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 => { 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 => { return current.map(item => {
if (item.file.name === fileName) { if (!matched && this.normalizeFileName(item.file.name) === targetName) {
return { ...item, quantity }; matched = true;
return { ...item, quantity: normalizedQty };
} }
return item; return item;
}); });
@@ -239,14 +256,9 @@ export class UploadFormComponent implements OnInit {
updateItemQuantity(index: number, event: Event) { updateItemQuantity(index: number, event: Event) {
const input = event.target as HTMLInputElement; const input = event.target as HTMLInputElement;
let val = parseInt(input.value, 10); const parsed = parseInt(input.value, 10);
if (isNaN(val) || val < 1) val = 1; const quantity = Number.isFinite(parsed) ? parsed : 1;
this.updateItemQuantityByIndex(index, quantity);
this.items.update(current => {
const updated = [...current];
updated[index] = { ...updated[index], quantity: val };
return updated;
});
} }
updateItemColor(index: number, newSelection: string | { colorName: string; filamentVariantId?: number }) { updateItemColor(index: number, newSelection: string | { colorName: string; filamentVariantId?: number }) {
@@ -387,4 +399,19 @@ export class UploadFormComponent implements OnInit {
this.form.get('itemsTouched')?.setValue(true); 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() ?? '';
}
} }