From 71d4f37b9d8e56b334f2d3222353c59e444c2827 Mon Sep 17 00:00:00 2001 From: sairina Date: Fri, 12 Nov 2021 15:19:35 -0800 Subject: [PATCH] Use plugin_data to query db for folders with practice quizzes --- .../src/views/plan/CoachExamsPage/index.vue | 38 +++---------------- kolibri/plugins/coach/kolibri_plugin.py | 11 ++++++ 2 files changed, 16 insertions(+), 33 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CoachExamsPage/index.vue b/kolibri/plugins/coach/assets/src/views/plan/CoachExamsPage/index.vue index b14a838e0b9..345d5957369 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CoachExamsPage/index.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CoachExamsPage/index.vue @@ -148,12 +148,11 @@ import CoreTable from 'kolibri.coreVue.components.CoreTable'; import commonCoreStrings from 'kolibri.coreVue.mixins.commonCoreStrings'; - import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants'; - import { ContentNodeResource, ExamResource } from 'kolibri.resources'; - import { mapGetters } from 'vuex'; + import { ExamResource } from 'kolibri.resources'; import { PageNames } from '../../../constants'; import commonCoach from '../../common'; import PlanHeader from '../../plan/PlanHeader'; + import plugin_data from 'plugin_data'; export default { name: 'CoachExamsPage', @@ -175,14 +174,15 @@ // }, showOpenConfirmationModal: false, showCloseConfirmationModal: false, - practiceQuizzesExist: true, }; }, computed: { - ...mapGetters(['getChannels']), sortedExams() { return this._.orderBy(this.exams, ['date_created'], ['desc']); }, + practiceQuizzesExist() { + return plugin_data.practice_quizzes_exist; + }, // Hidden temporarily per https://github.com/learningequality/kolibri/issues/6174 // Uncomment this once we use the filters again. /* @@ -228,34 +228,6 @@ ]; }, }, - mounted() { - this.$nextTick(() => { - let channelIds = this.getChannels.map(channel => channel.id); - let array = []; - - let results = channelIds.map(id => { - return ContentNodeResource.fetchCollection({ - getParams: { - parent: id, - kind_in: [ContentNodeKinds.TOPIC, ContentNodeKinds.EXERCISE], - contains_quiz: true, - }, - }).then(results => { - if (results.length !== 0) { - array.push(results); - } - }); - }); - - Promise.all(results) - .then(() => { - if (array.length === 0) { - this.practiceQuizzesExist = false; - } - }) - .catch(err => console.log(err)); - }); - }, methods: { handleOpenQuiz(quizId) { let promise = ExamResource.saveModel({ diff --git a/kolibri/plugins/coach/kolibri_plugin.py b/kolibri/plugins/coach/kolibri_plugin.py index 77680896977..5e0c5861c56 100644 --- a/kolibri/plugins/coach/kolibri_plugin.py +++ b/kolibri/plugins/coach/kolibri_plugin.py @@ -43,3 +43,14 @@ class CoachNavItem(NavigationHook): @register_hook class CoachAsset(webpack_hooks.WebpackBundleHook): bundle_id = "app" + + @property + def plugin_data(self): + from kolibri.core.content.models import ContentNode + + practice_quizzes_exist = ContentNode.objects.filter( + available=True, options__contains='"modality": "QUIZ"' + ).exists() + return { + "practice_quizzes_exist": practice_quizzes_exist, + }