Skip to content

Commit dd750fd

Browse files
Merge pull request #7163 from christianbeeznest/fixes-updates196
Learnpath: Fix vuedraggable item slot requirement in Learning Path list
2 parents 7c3fd96 + 88beb35 commit dd750fd

File tree

1 file changed

+62
-56
lines changed

1 file changed

+62
-56
lines changed

assets/vue/views/lp/LpList.vue

Lines changed: 62 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -125,50 +125,50 @@
125125
@end="onEndUncat"
126126
@start="draggingUncat = true"
127127
>
128-
<LpRowItem
129-
v-for="(element, elIdx) in uncatList"
130-
:key="elIdx"
131-
:buildDates="buildDates"
132-
:canAutoLaunch="canAutoLaunch"
133-
:canEdit="canEdit"
134-
:canExportPdf="canExportPdf"
135-
:canExportScorm="canExportScorm"
136-
:lp="element"
137-
:ringDash="ringDash"
138-
:ringValue="ringValue"
139-
@build="onBuild"
140-
@delete="onDelete"
141-
@edit="goEdit"
142-
@open="openLegacy"
143-
@report="onReport"
144-
@settings="onSettings"
145-
@toggle-auto-launch="onToggleAutoLaunch"
146-
@toggle-visible="onToggleVisible"
147-
@toggle-publish="onTogglePublish"
148-
@export-scorm="onExportScorm"
149-
@export-pdf="onExportPdf"
150-
/>
128+
<template #item="{ element }">
129+
<LpRowItem
130+
:buildDates="buildDates"
131+
:canAutoLaunch="canAutoLaunch"
132+
:canEdit="canEdit"
133+
:canExportPdf="canExportPdf"
134+
:canExportScorm="canExportScorm"
135+
:lp="element"
136+
:ringDash="ringDash"
137+
:ringValue="ringValue"
138+
@build="onBuild"
139+
@delete="onDelete"
140+
@edit="goEdit"
141+
@open="openLegacy"
142+
@report="onReport"
143+
@settings="onSettings"
144+
@toggle-auto-launch="onToggleAutoLaunch"
145+
@toggle-visible="onToggleVisible"
146+
@toggle-publish="onTogglePublish"
147+
@export-scorm="onExportScorm"
148+
@export-pdf="onExportPdf"
149+
/>
150+
</template>
151151
</Draggable>
152152
</div>
153153
<LpCategorySection
154-
v-for="[cat, list, isSession] in categorizedGroups"
155-
:key="cat.iid || cat.title"
154+
v-for="group in categorizedGroups"
155+
:key="group?.[0]?.iid || group?.[0]?.title"
156+
:category="group[0]"
157+
:list="group[1]"
158+
:isSessionCategory="group[2]"
156159
:buildDates="buildDates"
157160
:canAutoLaunch="canAutoLaunch"
158161
:canEdit="canEdit"
159162
:canExportPdf="canExportPdf"
160163
:canExportScorm="canExportScorm"
161-
:category="cat"
162-
:isSessionCategory="isSession"
163-
:list="list"
164164
:ringDash="ringDash"
165165
:ringValue="ringValue"
166-
:title="cat.title"
166+
:title="group[0]?.title"
167167
@build="onBuild"
168168
@delete="onDelete"
169169
@edit="goEdit"
170170
@open="openLegacy"
171-
@reorder="(ids) => onReorderCategory(cat, ids)"
171+
@reorder="(ids) => onReorderCategory(group[0], ids)"
172172
@report="onReport"
173173
@settings="onSettings"
174174
@toggle-auto-launch="onToggleAutoLaunch"
@@ -391,11 +391,14 @@ const load = async () => {
391391
392392
rawCanEdit.value = !!allowed
393393
394-
categories.value = await lpService.getLpCategories({
394+
const catRes = await lpService.getLpCategories({
395395
cid: course.value?.id,
396396
sid: session.value?.id ?? 0,
397397
})
398398
399+
const cats = catRes?.["hydra:member"] ?? catRes ?? []
400+
categories.value = Array.isArray(cats) ? cats : []
401+
399402
const res = await lpService.getLearningPaths({
400403
"resourceNode.parent": node,
401404
sid: session.value?.id ?? 0,
@@ -437,14 +440,18 @@ function hasSession(cat) {
437440
}
438441
439442
const categorizedGroups = computed(() => {
443+
const cats = Array.isArray(categories.value) ? categories.value : []
440444
const rows = []
441445
442-
for (const cat of categories.value) {
443-
const list = catLists.value[cat.iid] ?? []
446+
for (const cat of cats) {
447+
if (!cat) continue
448+
449+
const list = catLists.value && cat.iid ? (catLists.value[cat.iid] ?? []) : []
450+
const safeList = Array.isArray(list) ? list : []
444451
const isSessionCategory = hasSession(cat)
445452
446-
if (canEdit.value || list.length) {
447-
rows.push([cat, list, isSessionCategory])
453+
if (canEdit.value || safeList.length) {
454+
rows.push([cat, safeList, isSessionCategory])
448455
}
449456
}
450457
@@ -501,30 +508,29 @@ function applyOrderWithinContext(predicate, orderedIds) {
501508
}
502509
503510
async function sendReorder(orderedIds, { categoryId } = {}) {
511+
const payload = {
512+
courseId: course.value?.id,
513+
sessionId: session.value?.id,
514+
sid: session.value?.id, // keep both, depending on backend/service
515+
categoryId: categoryId ?? null,
516+
ids: orderedIds,
517+
order: orderedIds,
518+
}
519+
504520
if (lpService?.reorder) {
505-
await lpService.reorder({
506-
courseId: course.value?.id,
507-
sessionId: session.value?.id,
508-
categoryId: categoryId ?? null,
509-
ids: orderedIds,
510-
})
511-
} else {
512-
const resp = await fetch("/api/learning_paths/reorder", {
513-
method: "POST",
514-
headers: { "Content-Type": "application/json" },
515-
body: JSON.stringify({
516-
courseId: course.value?.id,
517-
sid: session.value?.id,
518-
categoryId: categoryId ?? null,
519-
order: orderedIds,
520-
}),
521-
})
521+
await lpService.reorder(payload)
522+
return
523+
}
522524
523-
if (!resp.ok) {
524-
const txt = await resp.text().catch(() => "")
525+
const resp = await fetch("/api/learning_paths/reorder", {
526+
method: "POST",
527+
headers: { "Content-Type": "application/json" },
528+
body: JSON.stringify(payload),
529+
})
525530
526-
throw new Error(`Reorder failed: ${resp.status} ${txt}`)
527-
}
531+
if (!resp.ok) {
532+
const txt = await resp.text().catch(() => "")
533+
throw new Error(`Reorder failed: ${resp.status} ${txt}`)
528534
}
529535
}
530536

0 commit comments

Comments
 (0)