fixes
This commit is contained in:
parent
da2d965da8
commit
be935e2ba6
|
|
@ -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
|
// Group berths by first letter
|
||||||
const groupedBerths = computed(() => {
|
const groupedBerths = computed(() => {
|
||||||
const grouped: Record<string, Berth[]> = {};
|
const grouped: Record<string, Berth[]> = {};
|
||||||
const sortedBerths = [...availableBerths.value].sort((a, b) =>
|
|
||||||
(a['Mooring Number'] || '').localeCompare(b['Mooring Number'] || '')
|
|
||||||
);
|
|
||||||
|
|
||||||
sortedBerths.forEach(berth => {
|
// First group by letter
|
||||||
const firstLetter = (berth['Mooring Number'] || '').charAt(0).toUpperCase();
|
availableBerths.value.forEach(berth => {
|
||||||
|
const mooringNumber = berth['Mooring Number'] || '';
|
||||||
|
const firstLetter = mooringNumber.charAt(0).toUpperCase();
|
||||||
if (!grouped[firstLetter]) {
|
if (!grouped[firstLetter]) {
|
||||||
grouped[firstLetter] = [];
|
grouped[firstLetter] = [];
|
||||||
}
|
}
|
||||||
grouped[firstLetter].push(berth);
|
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
|
// Create flat array with dividers
|
||||||
const result: any[] = [];
|
const result: any[] = [];
|
||||||
Object.keys(grouped).sort().forEach((letter, index) => {
|
Object.keys(grouped).sort().forEach((letter, index) => {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue