diff --git a/frontend/src/components/CourseOutline.vue b/frontend/src/components/CourseOutline.vue index 479c8aec..094cc9dc 100644 --- a/frontend/src/components/CourseOutline.vue +++ b/frontend/src/components/CourseOutline.vue @@ -23,119 +23,135 @@ 'border-2 rounded-md py-2 px-2': showOutline && outline.data?.length, }" > - - - -
- {{ chapter.title }} -
-
- - - - -
-
- - - - -
- - - + +
+ + + + + +
+ + + +
+
+
- - + + { $dialog({ title: __('Delete this lesson?'), @@ -287,6 +317,14 @@ const updateOutline = (e) => { }) } +const updateChapterOrder = (e) => { + updateChapterIndex.submit({ + chapter: e.item.__draggable_context.element.name, + course: props.courseName, + idx: e.newIndex, + }) +} + const deleteChapter = createResource({ url: 'lms.lms.api.delete_chapter', makeParams(values) { diff --git a/lms/lms/api.py b/lms/lms/api.py index d12dc507..7d0a61fd 100644 --- a/lms/lms/api.py +++ b/lms/lms/api.py @@ -676,6 +676,27 @@ def update_index(lessons, chapter): ) +@frappe.whitelist() +def update_chapter_index(chapter, course, idx): + """Update the index of a chapter within a course""" + chapters = frappe.get_all( + "Chapter Reference", + {"parent": course}, + pluck="chapter", + order_by="idx", + ) + + if chapter in chapters: + chapters.remove(chapter) + + chapters.insert(idx, chapter) + + for i, chapter_name in enumerate(chapters): + frappe.db.set_value( + "Chapter Reference", {"chapter": chapter_name, "parent": course}, "idx", i + 1 + ) + + @frappe.whitelist(allow_guest=True) def get_categories(doctype, filters): categoryOptions = []