|
125 | 125 | @end="onEndUncat" |
126 | 126 | @start="draggingUncat = true" |
127 | 127 | > |
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> |
151 | 151 | </Draggable> |
152 | 152 | </div> |
153 | 153 | <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]" |
156 | 159 | :buildDates="buildDates" |
157 | 160 | :canAutoLaunch="canAutoLaunch" |
158 | 161 | :canEdit="canEdit" |
159 | 162 | :canExportPdf="canExportPdf" |
160 | 163 | :canExportScorm="canExportScorm" |
161 | | - :category="cat" |
162 | | - :isSessionCategory="isSession" |
163 | | - :list="list" |
164 | 164 | :ringDash="ringDash" |
165 | 165 | :ringValue="ringValue" |
166 | | - :title="cat.title" |
| 166 | + :title="group[0]?.title" |
167 | 167 | @build="onBuild" |
168 | 168 | @delete="onDelete" |
169 | 169 | @edit="goEdit" |
170 | 170 | @open="openLegacy" |
171 | | - @reorder="(ids) => onReorderCategory(cat, ids)" |
| 171 | + @reorder="(ids) => onReorderCategory(group[0], ids)" |
172 | 172 | @report="onReport" |
173 | 173 | @settings="onSettings" |
174 | 174 | @toggle-auto-launch="onToggleAutoLaunch" |
@@ -391,11 +391,14 @@ const load = async () => { |
391 | 391 |
|
392 | 392 | rawCanEdit.value = !!allowed |
393 | 393 |
|
394 | | - categories.value = await lpService.getLpCategories({ |
| 394 | + const catRes = await lpService.getLpCategories({ |
395 | 395 | cid: course.value?.id, |
396 | 396 | sid: session.value?.id ?? 0, |
397 | 397 | }) |
398 | 398 |
|
| 399 | + const cats = catRes?.["hydra:member"] ?? catRes ?? [] |
| 400 | + categories.value = Array.isArray(cats) ? cats : [] |
| 401 | +
|
399 | 402 | const res = await lpService.getLearningPaths({ |
400 | 403 | "resourceNode.parent": node, |
401 | 404 | sid: session.value?.id ?? 0, |
@@ -437,14 +440,18 @@ function hasSession(cat) { |
437 | 440 | } |
438 | 441 |
|
439 | 442 | const categorizedGroups = computed(() => { |
| 443 | + const cats = Array.isArray(categories.value) ? categories.value : [] |
440 | 444 | const rows = [] |
441 | 445 |
|
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 : [] |
444 | 451 | const isSessionCategory = hasSession(cat) |
445 | 452 |
|
446 | | - if (canEdit.value || list.length) { |
447 | | - rows.push([cat, list, isSessionCategory]) |
| 453 | + if (canEdit.value || safeList.length) { |
| 454 | + rows.push([cat, safeList, isSessionCategory]) |
448 | 455 | } |
449 | 456 | } |
450 | 457 |
|
@@ -501,30 +508,29 @@ function applyOrderWithinContext(predicate, orderedIds) { |
501 | 508 | } |
502 | 509 |
|
503 | 510 | 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 | +
|
504 | 520 | 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 | + } |
522 | 524 |
|
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 | + }) |
525 | 530 |
|
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}`) |
528 | 534 | } |
529 | 535 | } |
530 | 536 |
|
|
0 commit comments