Skip to content

Commit

Permalink
refelect filtering in csv export
Browse files Browse the repository at this point in the history
  • Loading branch information
ozer550 committed Dec 16, 2024
1 parent deecb99 commit 46ad24d
Showing 1 changed file with 34 additions and 21 deletions.
55 changes: 34 additions & 21 deletions kolibri/plugins/coach/assets/src/views/lessons/LessonsRootPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -445,15 +426,47 @@
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),
...csvFields.tally(),
...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,
},
Expand Down

0 comments on commit 46ad24d

Please sign in to comment.