fix(pres_mgmt): use tmp_sort_2 for presentation sort in Pres Mgmt and Launcher
Compute presentation-specific tmp_sort_1/tmp_sort_2 in specific_processor,
overriding the generic values from _process_generic_props which had two bugs:
- priority encoded as 0/1 ASC (backwards — true should sort first)
- sort stored as unpadded string ("10" < "2" lexicographically)
- start_datetime and code not included (presentation-specific fields)
New encoding: priority(inv)_sort(8-padded)_start_datetime_code[_name]
Both liveQueries (Pres Mgmt session page, Launcher session view) now use
.sortBy('tmp_sort_2') — cleaner and uses the indexed field.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -680,6 +680,20 @@ export async function process_ae_obj__event_presentation_props({
|
|||||||
if (obj.event_session_id_random)
|
if (obj.event_session_id_random)
|
||||||
obj.event_session_id = obj.event_session_id_random;
|
obj.event_session_id = obj.event_session_id_random;
|
||||||
if (obj.event_id_random) obj.event_id = obj.event_id_random;
|
if (obj.event_id_random) obj.event_id = obj.event_id_random;
|
||||||
|
|
||||||
|
// Override generic tmp_sort_* with presentation-specific encoding.
|
||||||
|
// WHY: Generic _process_generic_props encodes priority as 0/1 ASC (backwards)
|
||||||
|
// and sort as an unpadded string ("10" < "2"). Presentations also need
|
||||||
|
// start_datetime and code in the sort chain, which are not generic fields.
|
||||||
|
// Desired order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||||
|
// Encoding trick: invert priority so true→'0' sorts before false→'1' ascending.
|
||||||
|
const p = obj.priority ? '0' : '1';
|
||||||
|
const s = String(Number(obj.sort ?? 0)).padStart(8, '0');
|
||||||
|
const dt = obj.start_datetime ?? '';
|
||||||
|
const code = obj.code ?? '';
|
||||||
|
const name = obj.name ?? '';
|
||||||
|
obj.tmp_sort_1 = `${p}_${s}_${dt}_${code}`;
|
||||||
|
obj.tmp_sort_2 = `${p}_${s}_${dt}_${code}_${name}`;
|
||||||
return obj;
|
return obj;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -91,9 +91,8 @@ let lq__event_file_obj_li = $derived.by(() => {
|
|||||||
|
|
||||||
// Event Presentation
|
// Event Presentation
|
||||||
// WHY: $derived.by — captures id in the outer closure so a new Observable is
|
// WHY: $derived.by — captures id in the outer closure so a new Observable is
|
||||||
// created whenever the session changes. Multi-field sort requires toArray() + JS
|
// created whenever the session changes. tmp_sort_2 encodes the full sort chain:
|
||||||
// comparator since Dexie's sortBy() is single-field only.
|
// priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||||
// Order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
|
||||||
let lq__event_presentation_obj_li = $derived.by(() => {
|
let lq__event_presentation_obj_li = $derived.by(() => {
|
||||||
const id = slct__event_session_id;
|
const id = slct__event_session_id;
|
||||||
return liveQuery(async () => {
|
return liveQuery(async () => {
|
||||||
@@ -103,32 +102,10 @@ let lq__event_presentation_obj_li = $derived.by(() => {
|
|||||||
console.log(`[LQ] Fetching presentations for session: ${id}`);
|
console.log(`[LQ] Fetching presentations for session: ${id}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
const results = await db_events.presentation
|
return await db_events.presentation
|
||||||
.where('event_session_id')
|
.where('event_session_id')
|
||||||
.equals(id)
|
.equals(id)
|
||||||
.toArray();
|
.sortBy('tmp_sort_2');
|
||||||
return results.sort((a, b) => {
|
|
||||||
// priority DESC (true first)
|
|
||||||
const pa = a.priority ? 1 : 0;
|
|
||||||
const pb = b.priority ? 1 : 0;
|
|
||||||
if (pb !== pa) return pb - pa;
|
|
||||||
// sort ASC
|
|
||||||
const sa = a.sort ?? 0;
|
|
||||||
const sb = b.sort ?? 0;
|
|
||||||
if (sa !== sb) return sa - sb;
|
|
||||||
// start_datetime ASC
|
|
||||||
const da = a.start_datetime ?? '';
|
|
||||||
const db_val = b.start_datetime ?? '';
|
|
||||||
if (da !== db_val) return da < db_val ? -1 : 1;
|
|
||||||
// code ASC
|
|
||||||
const ca = a.code ?? '';
|
|
||||||
const cb = b.code ?? '';
|
|
||||||
if (ca !== cb) return ca < cb ? -1 : 1;
|
|
||||||
// name ASC
|
|
||||||
const na = a.name ?? '';
|
|
||||||
const nb = b.name ?? '';
|
|
||||||
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -67,40 +67,18 @@ let lq__event_session_obj = $derived(
|
|||||||
);
|
);
|
||||||
|
|
||||||
// 2. Presentation List Observable
|
// 2. Presentation List Observable
|
||||||
// WHY: Dexie sortBy() is single-field only. Multi-field sort requires toArray() + JS comparator.
|
// WHY: tmp_sort_2 encodes priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
||||||
// Desired order: priority DESC → sort ASC → start_datetime ASC → code ASC → name ASC
|
// as a lexicographically correct string. See process_ae_obj__event_presentation_props.
|
||||||
let lq__event_presentation_obj_li = $derived(
|
let lq__event_presentation_obj_li = $derived(
|
||||||
liveQuery(async () => {
|
liveQuery(async () => {
|
||||||
if (log_lvl)
|
if (log_lvl)
|
||||||
console.log(
|
console.log(
|
||||||
`[LQ] Querying Presentations for Session: ${url_session_id}`
|
`[LQ] Querying Presentations for Session: ${url_session_id}`
|
||||||
);
|
);
|
||||||
const results = await db_events.presentation
|
return await db_events.presentation
|
||||||
.where('event_session_id')
|
.where('event_session_id')
|
||||||
.equals(url_session_id)
|
.equals(url_session_id)
|
||||||
.toArray();
|
.sortBy('tmp_sort_2');
|
||||||
return results.sort((a, b) => {
|
|
||||||
// priority DESC (true first)
|
|
||||||
const pa = a.priority ? 1 : 0;
|
|
||||||
const pb = b.priority ? 1 : 0;
|
|
||||||
if (pb !== pa) return pb - pa;
|
|
||||||
// sort ASC
|
|
||||||
const sa = a.sort ?? 0;
|
|
||||||
const sb = b.sort ?? 0;
|
|
||||||
if (sa !== sb) return sa - sb;
|
|
||||||
// start_datetime ASC
|
|
||||||
const da = a.start_datetime ?? '';
|
|
||||||
const db_val = b.start_datetime ?? '';
|
|
||||||
if (da !== db_val) return da < db_val ? -1 : 1;
|
|
||||||
// code ASC
|
|
||||||
const ca = a.code ?? '';
|
|
||||||
const cb = b.code ?? '';
|
|
||||||
if (ca !== cb) return ca < cb ? -1 : 1;
|
|
||||||
// name ASC
|
|
||||||
const na = a.name ?? '';
|
|
||||||
const nb = b.name ?? '';
|
|
||||||
return na < nb ? -1 : na > nb ? 1 : 0;
|
|
||||||
});
|
|
||||||
})
|
})
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user