This commit is contained in:
Matt 2025-06-12 17:58:25 +02:00
parent da2d965da8
commit be935e2ba6
1 changed files with 40 additions and 5 deletions

View File

@ -943,21 +943,56 @@ const eoiSendToSales = async () => {
}
};
// Natural sort function for alphanumeric berth numbers
const naturalSort = (a: string, b: string): number => {
const regex = /(\d+)|(\D+)/g;
const aParts = a.match(regex) || [];
const bParts = b.match(regex) || [];
for (let i = 0; i < Math.max(aParts.length, bParts.length); i++) {
if (!aParts[i]) return -1;
if (!bParts[i]) return 1;
const aIsNum = /^\d+$/.test(aParts[i]);
const bIsNum = /^\d+$/.test(bParts[i]);
if (aIsNum && bIsNum) {
const diff = parseInt(aParts[i]) - parseInt(bParts[i]);
if (diff !== 0) return diff;
} else if (aIsNum && !bIsNum) {
return -1;
} else if (!aIsNum && bIsNum) {
return 1;
} else {
const diff = aParts[i].localeCompare(bParts[i]);
if (diff !== 0) return diff;
}
}
return 0;
};
// Group berths by first letter
const groupedBerths = computed(() => {
const grouped: Record<string, Berth[]> = {};
const sortedBerths = [...availableBerths.value].sort((a, b) =>
(a['Mooring Number'] || '').localeCompare(b['Mooring Number'] || '')
);
sortedBerths.forEach(berth => {
const firstLetter = (berth['Mooring Number'] || '').charAt(0).toUpperCase();
// First group by letter
availableBerths.value.forEach(berth => {
const mooringNumber = berth['Mooring Number'] || '';
const firstLetter = mooringNumber.charAt(0).toUpperCase();
if (!grouped[firstLetter]) {
grouped[firstLetter] = [];
}
grouped[firstLetter].push(berth);
});
// Sort each group numerically
Object.keys(grouped).forEach(letter => {
grouped[letter].sort((a, b) =>
naturalSort(a['Mooring Number'] || '', b['Mooring Number'] || '')
);
});
// Create flat array with dividers
const result: any[] = [];
Object.keys(grouped).sort().forEach((letter, index) => {