Step RowFiltering done

This commit is contained in:
Roman Krček
2025-07-17 16:34:02 +02:00
parent c6ea10e1d6
commit 3ea48272b2
4 changed files with 466 additions and 19 deletions

View File

@@ -17,7 +17,8 @@
{ key: 'surname', label: 'Last Name', required: true },
{ key: 'nationality', label: 'Nationality', required: true },
{ key: 'birthday', label: 'Birthday', required: true },
{ key: 'pictureUrl', label: 'Photo URL', required: true }
{ key: 'pictureUrl', label: 'Photo URL', required: true },
{ key: 'alreadyPrinted', label: 'Already Printed', required: false }
];
let mappedIndices = {
@@ -25,7 +26,8 @@
surname: -1,
nationality: -1,
birthday: -1,
pictureUrl: -1
pictureUrl: -1,
alreadyPrinted: -1
};
// Load available sheets when component mounts
@@ -63,7 +65,8 @@
surname: -1,
nationality: -1,
birthday: -1,
pictureUrl: -1
pictureUrl: -1,
alreadyPrinted: -1
};
mappingComplete = false;
@@ -112,7 +115,8 @@
surname: -1,
nationality: -1,
birthday: -1,
pictureUrl: -1
pictureUrl: -1,
alreadyPrinted: -1
};
// Auto-mapping patterns
@@ -121,7 +125,8 @@
surname: /last[\s_-]*name|surname|family[\s_-]*name|nachname/i,
nationality: /nationality|country|nation/i,
birthday: /birth|date[\s_-]*of[\s_-]*birth|birthday|dob/i,
pictureUrl: /photo|picture|image|url|avatar/i
pictureUrl: /photo|picture|image|url|avatar/i,
alreadyPrinted: /already[\s_-]*printed|printed|status/i
};
sheetHeaders.forEach((header, index) => {
@@ -133,6 +138,27 @@
}
});
// If "Already Printed" column wasn't found, try to find the first empty column
if (mappedIndices.alreadyPrinted === -1 && previewData.length > 0) {
// Check up to 26 columns (A-Z) or the number of headers, whichever is larger
const maxColumns = Math.max(sheetHeaders.length, 26);
for (let colIndex = 0; colIndex < maxColumns; colIndex++) {
// Check if this column is empty (all preview rows are empty for this column)
const isEmpty = previewData.every(row => !row[colIndex] || String(row[colIndex]).trim() === '');
// Also check if this column isn't already mapped to another field
const isAlreadyMapped = Object.entries(mappedIndices).some(([field, index]) =>
field !== 'alreadyPrinted' && index === colIndex
);
if (isEmpty && !isAlreadyMapped) {
mappedIndices.alreadyPrinted = colIndex;
break;
}
}
}
updateMappingStatus();
}
@@ -156,7 +182,8 @@
surname: savedSheet.columnMapping.surname ?? -1,
nationality: savedSheet.columnMapping.nationality ?? -1,
birthday: savedSheet.columnMapping.birthday ?? -1,
pictureUrl: savedSheet.columnMapping.pictureUrl ?? -1
pictureUrl: savedSheet.columnMapping.pictureUrl ?? -1,
alreadyPrinted: savedSheet.columnMapping.alreadyPrinted ?? -1
};
updateMappingStatus();
@@ -173,7 +200,16 @@
}
function updateMappingStatus() {
mappingComplete = Object.values(mappedIndices).every(index => index !== -1);
// Only check required fields for completion
const requiredIndices = {
name: mappedIndices.name,
surname: mappedIndices.surname,
nationality: mappedIndices.nationality,
birthday: mappedIndices.birthday,
pictureUrl: mappedIndices.pictureUrl
};
mappingComplete = Object.values(requiredIndices).every(index => index !== -1);
// Update the column mapping store
columnMapping.set({
@@ -181,7 +217,8 @@
surname: mappedIndices.surname,
nationality: mappedIndices.nationality,
birthday: mappedIndices.birthday,
pictureUrl: mappedIndices.pictureUrl
pictureUrl: mappedIndices.pictureUrl,
alreadyPrinted: mappedIndices.alreadyPrinted
});
}
@@ -204,7 +241,8 @@
surname: mappedIndices.surname,
nationality: mappedIndices.nationality,
birthday: mappedIndices.birthday,
pictureUrl: mappedIndices.pictureUrl
pictureUrl: mappedIndices.pictureUrl,
alreadyPrinted: mappedIndices.alreadyPrinted
};
if (sheetIndex !== -1) {
@@ -370,8 +408,13 @@
class="w-full px-3 py-2 border border-gray-300 rounded-md bg-white text-gray-900 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-blue-500"
>
<option value={-1}>-- Select column --</option>
{#each sheetHeaders as header, index}
<option value={index}>{header}</option>
{#each Array.from({length: Math.max(sheetHeaders.length, 26)}, (_, i) => i) as index}
<option value={index}>
{sheetHeaders[index] || `Column ${String.fromCharCode(65 + index)}`}
{#if !sheetHeaders[index]}
(empty)
{/if}
</option>
{/each}
</select>
</div>
@@ -387,10 +430,10 @@
<table class="min-w-full divide-y divide-gray-200 border border-gray-200 rounded-lg">
<thead class="bg-gray-50">
<tr>
{#each sheetHeaders as header, index}
{#each Array.from({length: Math.max(sheetHeaders.length, previewData[0]?.length || 0, 26)}, (_, i) => i) as index}
<th class="px-3 py-2 text-left text-xs font-medium text-gray-500 uppercase tracking-wider
{Object.values(mappedIndices).includes(index) ? 'bg-blue-100' : ''}">
{header}
{sheetHeaders[index] || `Column ${String.fromCharCode(65 + index)}`}
{#if Object.values(mappedIndices).includes(index)}
<div class="text-blue-600 text-xs mt-1">
{requiredFields.find(f => mappedIndices[f.key] === index)?.label}
@@ -403,10 +446,10 @@
<tbody class="bg-white divide-y divide-gray-200">
{#each previewData as row}
<tr>
{#each row as cell, index}
{#each Array.from({length: Math.max(sheetHeaders.length, row.length, 26)}, (_, i) => i) as index}
<td class="px-3 py-2 text-sm text-gray-500 max-w-xs truncate
{Object.values(mappedIndices).includes(index) ? 'bg-blue-50' : ''}">
{cell}
{row[index] || ''}
</td>
{/each}
</tr>