Template mapping and detecting done

This commit is contained in:
2026-07-14 16:26:49 +05:30
parent 360022820d
commit c725014788
2 changed files with 50 additions and 3 deletions

View File

@@ -181,11 +181,11 @@ export class TemplatesComponent implements OnInit {
}
}
// If we found a matching node (at least some overlap), move it from canvas to mappings
// If we found a matching node (at least some overlap), clone it to mappings
if (bestMatchIdx !== -1) {
const matchedNode = page.nodes.splice(bestMatchIdx, 1)[0];
const matchedNode = page.nodes[bestMatchIdx];
// Because *ngFor tracks objects by reference, we clone it to force Angular to render it in the right panel cleanly
// Because *ngFor tracks objects by reference, we clone it
this.mappings[field.pk_template_field_id].push({...matchedNode});
}
}
@@ -289,6 +289,20 @@ export class TemplatesComponent implements OnInit {
// We use event.item.data which perfectly tracks the dragged object regardless of DOM indexes
const clonedNode = JSON.parse(JSON.stringify(event.item.data));
// Sanitize the value if dropped on an AMOUNT or NUMBER field
if (fieldId) {
const field = this.templateFields.find(f => f.pk_template_field_id === fieldId);
if (field && (field.field_type === 'AMOUNT' || field.field_type === 'NUMBER') && clonedNode.text_value) {
const numericText = clonedNode.text_value.replace(/[^\d\.-]/g, '');
const floatValue = parseFloat(numericText);
if (!isNaN(floatValue)) {
clonedNode.text_value = floatValue.toString();
} else {
clonedNode.text_value = '';
}
}
}
// Insert the clone into the destination mapping field
event.container.data.splice(event.currentIndex, 0, clonedNode);