From 46ad24d557e8db52d6f58c1e1588f6fd03e7bc51 Mon Sep 17 00:00:00 2001 From: ozer550 Date: Mon, 16 Dec 2024 18:02:15 +0530 Subject: [PATCH] refelect filtering in csv export --- .../src/views/lessons/LessonsRootPage.vue | 55 ++++++++++++------- 1 file changed, 34 insertions(+), 21 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/lessons/LessonsRootPage.vue b/kolibri/plugins/coach/assets/src/views/lessons/LessonsRootPage.vue index 459dc54bedd..a35ec53232b 100644 --- a/kolibri/plugins/coach/assets/src/views/lessons/LessonsRootPage.vue +++ b/kolibri/plugins/coach/assets/src/views/lessons/LessonsRootPage.vue @@ -247,26 +247,7 @@ ...mapState('classSummary', { classId: 'id' }), ...mapState('lessonsRoot', ['lessons', 'learnerGroups']), sortedLessons() { - const sorted = this._.orderBy(this.lessons, ['date_created'], ['desc']); - const allLessons = sorted.map(lesson => { - const learners = this.getLearnersForLesson(lesson); - const sortedLesson = { - totalLearners: learners.length, - tally: this.getLessonStatusTally(lesson.id, learners), - groupNames: this.getGroupNames(lesson.assignments), - recipientNames: this.getRecipientNamesForLesson(lesson), - hasAssignments: learners.length > 0, - }; - Object.assign(sortedLesson, lesson); - return sortedLesson; - }); - - if (this.filterRecipents.label === this.entireClassLabel$()) { - return allLessons; - } - return allLessons.filter(lesson => { - return lesson.recipientNames.includes(this.filterRecipents.label); - }); + return this.getFilteredLessons(); }, userHasDismissedModal() { return Lockr.get(LESSON_VISIBILITY_MODAL_DISMISSED); @@ -445,7 +426,39 @@ this.showLessonIsVisibleModal = false; this.showLessonIsNotVisibleModal = false; }, + getFilteredLessons() { + const sorted = this._.orderBy(this.lessons, ['date_created'], ['desc']); + const allLessons = sorted.map(lesson => { + const learners = this.getLearnersForLesson(lesson); + const sortedLesson = { + totalLearners: learners.length, + tally: this.getLessonStatusTally(lesson.id, learners), + groupNames: this.getGroupNames(lesson.assignments), + recipientNames: this.getRecipientNamesForLesson(lesson), + hasAssignments: learners.length > 0, + }; + Object.assign(sortedLesson, lesson); + return sortedLesson; + }); + + let lessonToReturn = allLessons; + + if (this.filterSelection.value !== 'filterLessonAll') { + const isVisibleFilter = this.filterSelection.value === 'filterLessonVisible'; + lessonToReturn = lessonToReturn.filter(lesson => lesson.active === isVisibleFilter); + } + + if (this.filterRecipents.label !== this.entireClassLabel$()) { + lessonToReturn = lessonToReturn.filter(lesson => { + return lesson.recipientNames.includes(this.filterRecipents.label); + }); + } + + return lessonToReturn; + }, exportCSV() { + const filteredLessons = this.getFilteredLessons(); + const columns = [ ...csvFields.title(), ...csvFields.recipients(this.className), @@ -453,7 +466,7 @@ ...csvFields.allLearners('totalLearners'), ]; const fileName = this.$tr('printLabel', { className: this.className }); - new CSVExporter(columns, fileName).export(this.sortedLessons); + new CSVExporter(columns, fileName).export(filteredLessons); }, bytesForHumans, },