|
150 | 150 | /> |
151 | 151 | </Draggable> |
152 | 152 | </div> |
153 | | - |
154 | 153 | <LpCategorySection |
155 | | - v-for="[cat, list] in categorizedGroups" |
| 154 | + v-for="[cat, list, isSession] in categorizedGroups" |
156 | 155 | :key="cat.iid || cat.title" |
157 | 156 | :buildDates="buildDates" |
158 | 157 | :canAutoLaunch="canAutoLaunch" |
|
161 | 160 | :canExportScorm="canExportScorm" |
162 | 161 | :category="cat" |
163 | 162 | :list="list" |
| 163 | + :isSessionCategory="isSession" |
164 | 164 | :ringDash="ringDash" |
165 | 165 | :ringValue="ringValue" |
166 | 166 | :title="cat.title" |
|
176 | 176 | @toggle-publish="onTogglePublish" |
177 | 177 | @export-pdf="onExportPdf" |
178 | 178 | /> |
| 179 | + |
179 | 180 | </template> |
180 | 181 | </div> |
181 | 182 | <ExportPdfDialog |
@@ -420,18 +421,84 @@ const load = async () => { |
420 | 421 | } |
421 | 422 | onMounted(load) |
422 | 423 |
|
423 | | -const categorizedGroups = computed(() => { |
424 | | - const rows = [] |
| 424 | +// build the candidate fields object |
| 425 | +function inspectCategorySessionCandidates(cat) { |
| 426 | + const c = { |
| 427 | + sid: cat?.sid, session: cat?.session, sessionId: cat?.sessionId, |
| 428 | + courseSessionId: cat?.courseSessionId, course_session: cat?.course_session, |
| 429 | + session_iid: cat?.session_iid, |
| 430 | + } |
| 431 | + if (Array.isArray(cat?.resourceLinkListFromEntity)) { |
| 432 | + cat.resourceLinkListFromEntity.forEach((l, i) => { |
| 433 | + c[`resourceLink_${i}_session`] = l?.session |
| 434 | + c[`resourceLink_${i}_courseSessionId`] = l?.courseSessionId ?? l?.course_session |
| 435 | + }) |
| 436 | + } |
| 437 | + return c |
| 438 | +} |
425 | 439 |
|
426 | | - for (const cat of categories.value) { |
427 | | - const list = catLists.value[cat.iid] ?? [] |
| 440 | +function extractNumbersFromValue(v) { |
| 441 | + if (v == null) return [] |
| 442 | + if (typeof v === "number") return Number.isFinite(v) ? [v] : [] |
| 443 | + if (typeof v === "string") { |
| 444 | + const m = v.match(/-?\d+/g) |
| 445 | + return m ? m.map(Number).filter(Number.isFinite) : [] |
| 446 | + } |
| 447 | + if (Array.isArray(v)) return v.flatMap(extractNumbersFromValue) |
| 448 | + if (typeof v === "object") return Object.values(v).flatMap(extractNumbersFromValue) |
| 449 | + return [] |
| 450 | +} |
428 | 451 |
|
429 | | - if (canEdit.value || list.length) { |
430 | | - rows.push([cat, list]) |
431 | | - } |
| 452 | +function getCategorySessionId(cat) { |
| 453 | + if (!cat || typeof cat !== "object") return { catSid: 0, hasSessionField: false, candidates: {} } |
| 454 | + const candidates = inspectCategorySessionCandidates(cat) |
| 455 | + for (const val of Object.values(candidates)) { |
| 456 | + if (val == null || String(val).trim() === "") continue |
| 457 | + const nums = extractNumbersFromValue(val) |
| 458 | + const found = nums.find(n => n !== 0) |
| 459 | + if (found !== undefined) return { catSid: Number(found), hasSessionField: true, candidates } |
432 | 460 | } |
| 461 | + const hasSessionField = Object.values(candidates).some(v => v != null && String(v).trim() !== "") |
| 462 | + return { catSid: 0, hasSessionField, candidates } |
| 463 | +} |
433 | 464 |
|
434 | | - return rows |
| 465 | +const filteredCategories = computed(() => { |
| 466 | + if (!Array.isArray(categories.value)) return [] |
| 467 | + const s = Number(sid.value) || 0 |
| 468 | + const lpCatIdsInItems = new Set((items.value ?? []).map(lp => lp?.category?.iid).filter(id => id != null)) |
| 469 | +
|
| 470 | + const matchesSessionValue = (candidates, sNum) => { |
| 471 | + if (!candidates || typeof candidates !== "object") return false |
| 472 | + return Object.values(candidates).some(v => { |
| 473 | + if (v == null || String(v).trim() === "") return false |
| 474 | + if (Number(String(v)) === sNum) return true |
| 475 | + if (extractNumbersFromValue(v).some(n => n === sNum)) return true |
| 476 | + if (String(v).trim() === String(sNum)) return true |
| 477 | + return false |
| 478 | + }) |
| 479 | + } |
| 480 | +
|
| 481 | + return categories.value.filter(cat => { |
| 482 | + const { catSid, hasSessionField, candidates } = getCategorySessionId(cat) |
| 483 | + if (s > 0) { |
| 484 | + if (catSid === s) return true |
| 485 | + if (hasSessionField && matchesSessionValue(candidates, s)) return true |
| 486 | + if (!hasSessionField && catSid === 0) return true |
| 487 | + if (lpCatIdsInItems.has(cat.iid)) return true |
| 488 | + return false |
| 489 | + } |
| 490 | + return !hasSessionField && catSid === 0 |
| 491 | + }) |
| 492 | +}) |
| 493 | +
|
| 494 | +const categorizedGroups = computed(() => { |
| 495 | + const cats = filteredCategories.value ?? [] |
| 496 | + return cats.map(cat => { |
| 497 | + const list = (catLists.value[cat.iid] ?? []).slice() |
| 498 | + const { catSid, hasSessionField } = getCategorySessionId(cat) |
| 499 | + const isSessionCategory = !!(hasSessionField && catSid !== 0) |
| 500 | + return [cat, list, isSessionCategory] |
| 501 | + }).filter(([_, list]) => (list && list.length) || canEdit.value) |
435 | 502 | }) |
436 | 503 |
|
437 | 504 | function rebuildListsFromItems() { |
|
0 commit comments