Sort rooms by Newbook category order, numeric room name collation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
44653c51e4
commit
d25e3421a8
1 changed files with 13 additions and 11 deletions
|
|
@ -167,22 +167,22 @@ export async function fetchGridData(startDate, days, settings, forceRefresh = fa
|
|||
const dates = []
|
||||
for (let i = 0; i < days; i++) dates.push(offsetDate(startDate, i))
|
||||
|
||||
const grid = {}
|
||||
const rooms = []
|
||||
const grid = {}
|
||||
const rooms = []
|
||||
const categoryOrder = []
|
||||
|
||||
for (const booking of resp.data) {
|
||||
const siteId = booking.site_id || ''
|
||||
const siteName = booking.site_name || ''
|
||||
if (!siteId || !siteName) continue
|
||||
|
||||
const category = (booking.category_name || 'Uncategorized').trim()
|
||||
|
||||
if (!grid[siteId]) {
|
||||
grid[siteId] = {
|
||||
site_name: siteName,
|
||||
category: (booking.category_name || 'Uncategorized').trim(),
|
||||
cells: {},
|
||||
}
|
||||
grid[siteId] = { site_name: siteName, category, cells: {} }
|
||||
rooms.push(siteId)
|
||||
}
|
||||
if (!categoryOrder.includes(category)) categoryOrder.push(category)
|
||||
|
||||
const checkin = (booking.booking_arrival || '').slice(0, 10)
|
||||
const checkout = (booking.booking_departure || '').slice(0, 10)
|
||||
|
|
@ -207,11 +207,13 @@ export async function fetchGridData(startDate, days, settings, forceRefresh = fa
|
|||
}
|
||||
}
|
||||
|
||||
// Sort by category then room name
|
||||
// Sort by Newbook's natural category order, then room name numerically
|
||||
const collator = new Intl.Collator(undefined, { numeric: true, sensitivity: 'base' })
|
||||
rooms.sort((a, b) => {
|
||||
const ac = grid[a].category, bc = grid[b].category
|
||||
if (ac !== bc) return ac.localeCompare(bc)
|
||||
return grid[a].site_name.localeCompare(grid[b].site_name)
|
||||
const ai = categoryOrder.indexOf(grid[a].category)
|
||||
const bi = categoryOrder.indexOf(grid[b].category)
|
||||
if (ai !== bi) return ai - bi
|
||||
return collator.compare(grid[a].site_name, grid[b].site_name)
|
||||
})
|
||||
|
||||
const result = { dates, rooms, grid }
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue