Skip to content

Commit 89b06d5

Browse files
committed
Merge branch 'Ilyassbennanii-new_1966'
2 parents f3c3446 + 0febc72 commit 89b06d5

File tree

2 files changed

+87
-11
lines changed

2 files changed

+87
-11
lines changed

assets/vue/components/lp/LpCategorySection.vue

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ const props = defineProps({
2020
ringDash: { type: Function, required: true },
2121
ringValue: { type: Function, required: true },
2222
buildDates: { type: Function, required: false },
23+
isSessionCategory: { type: Boolean, default: false },
2324
})
2425
const emit = defineEmits([
2526
"open",
@@ -174,7 +175,15 @@ const toggleOpen = () => {
174175
></span>
175176
</template>
176177
177-
<h2 class="text-body-1 font-semibold text-gray-90">{{ displayTitle }}</h2>
178+
<h2 class="text-body-1 font-semibold text-gray-90">
179+
<span>{{ displayTitle }}</span>
180+
<!-- Display the star if it's a session category; remove the check on category.type -->
181+
<span
182+
v-if="isSessionCategory"
183+
class="ml-2 text-warning"
184+
title="Category created for a session"
185+
>★</span>
186+
</h2>
178187
</div>
179188
180189
<div class="flex items-center gap-2">

assets/vue/views/lp/LpList.vue

Lines changed: 77 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,8 @@
150150
/>
151151
</Draggable>
152152
</div>
153-
154153
<LpCategorySection
155-
v-for="[cat, list] in categorizedGroups"
154+
v-for="[cat, list, isSession] in categorizedGroups"
156155
:key="cat.iid || cat.title"
157156
:buildDates="buildDates"
158157
:canAutoLaunch="canAutoLaunch"
@@ -161,6 +160,7 @@
161160
:canExportScorm="canExportScorm"
162161
:category="cat"
163162
:list="list"
163+
:isSessionCategory="isSession"
164164
:ringDash="ringDash"
165165
:ringValue="ringValue"
166166
:title="cat.title"
@@ -176,6 +176,7 @@
176176
@toggle-publish="onTogglePublish"
177177
@export-pdf="onExportPdf"
178178
/>
179+
179180
</template>
180181
</div>
181182
<ExportPdfDialog
@@ -420,18 +421,84 @@ const load = async () => {
420421
}
421422
onMounted(load)
422423
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+
}
425439
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+
}
428451
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 }
432460
}
461+
const hasSessionField = Object.values(candidates).some(v => v != null && String(v).trim() !== "")
462+
return { catSid: 0, hasSessionField, candidates }
463+
}
433464
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)
435502
})
436503
437504
function rebuildListsFromItems() {

0 commit comments

Comments
 (0)