diff --git a/frontend/src/components/BatchStudents.vue b/frontend/src/components/BatchStudents.vue
index d6e336a8..26665db5 100644
--- a/frontend/src/components/BatchStudents.vue
+++ b/frontend/src/components/BatchStudents.vue
@@ -2,7 +2,7 @@
- {{ students.data?.length }} {{ __('Students') }}
+ {{ studentCount.data ?? 0 }} {{ __('Students') }}
@@ -110,6 +115,7 @@
import {
Avatar,
Button,
+ createListResource,
createResource,
FeatherIcon,
ListHeader,
@@ -139,39 +145,47 @@ const props = defineProps({
},
})
-const students = createResource({
- url: 'lms.lms.utils.get_batch_students',
+const studentCount = createResource({
+ url: 'lms.lms.utils.get_batch_student_count',
+ cache: ['batch_student_count', props.batch?.data?.name],
params: {
batch: props.batch?.data?.name,
},
auto: true,
})
-const getStudentColumns = () => {
- let columns = [
- {
- label: 'Full Name',
- key: 'full_name',
- width: '20rem',
- icon: 'user',
- },
- {
- label: 'Progress',
- key: 'progress',
- width: '15rem',
- icon: 'activity',
- },
- {
- label: 'Last Active',
- key: 'last_active',
- width: '10rem',
- align: 'center',
- icon: 'clock',
- },
- ]
+const students = createListResource({
+ doctype: 'LMS Batch Enrollment',
+ url: 'lms.lms.utils.get_batch_students',
+ cache: ['batch_students', props.batch?.data?.name],
+ pageLength: 50,
+ filters: {
+ batch: props.batch?.data?.name,
+ },
+ auto: true,
+})
- return columns
-}
+const studentColumns = [
+ {
+ label: 'Full Name',
+ key: 'full_name',
+ width: '20rem',
+ icon: 'user',
+ },
+ {
+ label: 'Progress',
+ key: 'progress',
+ width: '15rem',
+ icon: 'activity',
+ },
+ {
+ label: 'Last Active',
+ key: 'last_active',
+ width: '10rem',
+ align: 'center',
+ icon: 'clock',
+ },
+]
const openStudentModal = () => {
showStudentModal.value = true
@@ -200,6 +214,7 @@ const removeStudents = (selections, unselectAll) => {
{
onSuccess(data) {
students.reload()
+ studentCount.reload()
props.batch.reload()
toast.success(__('Students deleted successfully'))
unselectAll()
diff --git a/lms/lms/utils.py b/lms/lms/utils.py
index 9bad9eee..998e79c0 100644
--- a/lms/lms/utils.py
+++ b/lms/lms/utils.py
@@ -1354,17 +1354,30 @@ def get_exercise_details(assessment, member):
@frappe.whitelist()
-def get_batch_students(batch):
+def get_batch_students(filters, offset=0, limit_start=0, limit_page_length=None, limit=None):
+ # limit_start and limit_page_length are used for backward compatibility
+ start = limit_start or offset
+ page_length = limit_page_length or limit
+
+ batch = filters.get("batch")
+ if not batch:
+ return []
+
students = []
students_list = frappe.get_all(
- "LMS Batch Enrollment", filters={"batch": batch}, fields=["member", "name"]
+ "LMS Batch Enrollment",
+ filters={"batch": batch},
+ fields=["member", "name"],
+ offset=start,
+ limit=page_length,
+ order_by="creation desc",
)
for student in students_list:
details = get_batch_student_details(student)
calculate_student_progress(batch, details)
students.append(details)
- students = sorted(students, key=lambda x: x.progress, reverse=True)
+
return students