Room planner: pull category sort order from settings global_config
Category ordering on the default view now uses the admin-configured sort_order from global_config.newbook.rooms rather than the raw NewBook site_category_order. Falls back to NewBook order if the settings row is absent. Also overrides category_order on each room. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
9ef047900b
commit
1ab864f4e3
1 changed files with 19 additions and 9 deletions
|
|
@ -135,18 +135,23 @@ export async function roomRoutes(app) {
|
||||||
const canSeeRate = hasCap(req, 'rate_details')
|
const canSeeRate = hasCap(req, 'rate_details')
|
||||||
const canSeeAllNotes = hasCap(req, 'view_all_notes')
|
const canSeeAllNotes = hasCap(req, 'view_all_notes')
|
||||||
|
|
||||||
// Load config for note type visibility
|
// Load config in parallel: note visibility, exclusions, settings category order
|
||||||
const cfgRow = await pool.query(`SELECT value FROM config WHERE key = 'visible_note_types'`)
|
const [cfgRow, excRow, settingsRow] = await Promise.all([
|
||||||
|
pool.query(`SELECT value FROM config WHERE key = 'visible_note_types'`),
|
||||||
|
pool.query(`SELECT key, value FROM config WHERE key IN ('excluded_categories','hide_excluded_categories')`),
|
||||||
|
pool.query(`SELECT value FROM global_config WHERE key = 'newbook.rooms'`),
|
||||||
|
])
|
||||||
const visibleNoteTypes = cfgRow.rows[0]?.value || []
|
const visibleNoteTypes = cfgRow.rows[0]?.value || []
|
||||||
|
|
||||||
// Load exclusion config
|
|
||||||
const excRow = await pool.query(
|
|
||||||
`SELECT key, value FROM config WHERE key IN ('excluded_categories','hide_excluded_categories')`
|
|
||||||
)
|
|
||||||
const cfgMap = Object.fromEntries(excRow.rows.map(r => [r.key, r.value]))
|
const cfgMap = Object.fromEntries(excRow.rows.map(r => [r.key, r.value]))
|
||||||
const excludedCategories = cfgMap.excluded_categories || []
|
const excludedCategories = cfgMap.excluded_categories || []
|
||||||
const hideExcluded = cfgMap.hide_excluded_categories ?? false
|
const hideExcluded = cfgMap.hide_excluded_categories ?? false
|
||||||
|
|
||||||
|
// Build category sort-order map from settings (admin-configured) — keyed by category id
|
||||||
|
const settingsCatOrder = {}
|
||||||
|
for (const cat of settingsRow.rows[0]?.value?.categories ?? []) {
|
||||||
|
settingsCatOrder[String(cat.id)] = cat.sort_order ?? 999
|
||||||
|
}
|
||||||
|
|
||||||
// Fetch from NewBook in parallel
|
// Fetch from NewBook in parallel
|
||||||
let sites, bookings, tasks
|
let sites, bookings, tasks
|
||||||
try {
|
try {
|
||||||
|
|
@ -167,10 +172,11 @@ export async function roomRoutes(app) {
|
||||||
site.site_category_id ?? site.category_id ?? site.category?.id ?? ''
|
site.site_category_id ?? site.category_id ?? site.category?.id ?? ''
|
||||||
)
|
)
|
||||||
if (catId && !categoryMap[catId]) {
|
if (catId && !categoryMap[catId]) {
|
||||||
|
const nbOrder = site.site_category_order ?? site.category_order ?? site.category?.order ?? 999
|
||||||
categoryMap[catId] = {
|
categoryMap[catId] = {
|
||||||
id: catId,
|
id: catId,
|
||||||
name: site.site_category_name ?? site.category_name ?? site.category?.name ?? catId,
|
name: site.site_category_name ?? site.category_name ?? site.category?.name ?? catId,
|
||||||
order: site.site_category_order ?? site.category_order ?? site.category?.order ?? 999,
|
order: settingsCatOrder[catId] ?? nbOrder,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -184,6 +190,10 @@ export async function roomRoutes(app) {
|
||||||
|
|
||||||
const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow)
|
const classified = classifyRoom(site, bookings, viewDate, yesterday, tomorrow)
|
||||||
|
|
||||||
|
// Override category_order with settings value if available
|
||||||
|
const catOrderOverride = settingsCatOrder[catId]
|
||||||
|
if (catOrderOverride !== undefined) classified.category_order = catOrderOverride
|
||||||
|
|
||||||
// Filter booking data per capabilities
|
// Filter booking data per capabilities
|
||||||
if (classified.booking) {
|
if (classified.booking) {
|
||||||
classified.booking = filterBookingData(
|
classified.booking = filterBookingData(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue