From a8349c3852cdce2629d8bc002c602e163abeefa6 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Wed, 31 Jan 2024 16:58:27 +0300 Subject: [PATCH 01/10] number of resources updates on selection --- .../src/views/plan/CreateExamPage/ResourceSelection.vue | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index ea22d166a0f..6072b2615aa 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -325,7 +325,7 @@ // topic's descendants are selected out of its total descendants -- basically answering // "How many resources in the working resource_pool are from this topic?" // Tracked in https://github.com/learningequality/kolibri/issues/11741 - return () => ''; + return () => { this.workingResourcePool.length }; // let count = 0; // let total = 0; // if (this.ancestorCounts[content.id]) { @@ -401,10 +401,8 @@ }, toggleTopicInWorkingResources(isChecked) { if (isChecked) { - this.isSelectAllChecked = true; this.addToWorkingResourcePool(this.contentList); } else { - this.isSelectAllChecked = false; this.resetWorkingResourcePool(); } }, From 6ea994a8adf63bb316da0b8c0c2ed28073048e91 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Wed, 31 Jan 2024 23:09:11 +0300 Subject: [PATCH 02/10] added function to render the number of resources in the folder --- .../plan/CreateExamPage/ResourceSelection.vue | 38 ++++++++++--------- .../strings/enhancedQuizManagementStrings.js | 4 ++ 2 files changed, 24 insertions(+), 18 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 6072b2615aa..7e4e113ef04 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -129,6 +129,7 @@ //selectFoldersOrExercises$, numberOfSelectedResources$, numberOfResources$, + selectedResourcesInformation$, } = enhancedQuizManagementStrings; // TODO let's not use text for this @@ -294,6 +295,7 @@ addToWorkingResourcePool, removeFromWorkingResourcePool, showBookmarks, + selectedResourcesInformation$ }; }, props: { @@ -320,12 +322,14 @@ this.contentList.some(content => workingResourceIds.includes(content.id)) ); }, - selectionMetadata(/*content*/) { + // selectionMetadata(content) { + // console.log(content); + // return ()=>{}; // TODO This should return a function that returns a string telling us how many of this // topic's descendants are selected out of its total descendants -- basically answering // "How many resources in the working resource_pool are from this topic?" // Tracked in https://github.com/learningequality/kolibri/issues/11741 - return () => { this.workingResourcePool.length }; + // return () => { this.workingResourcePool.length }; // let count = 0; // let total = 0; // if (this.ancestorCounts[content.id]) { @@ -334,15 +338,16 @@ // } // if (count) { // return this.$tr('selectionInformation', { - // count, - // total, + // '32', + // '45', // }); // } // return ''; // return function() { // console.log('Dynamic function called'); // }; - }, + // }, + getBookmarksLink() { // Inject the showBookmarks parameter so that // the resourceSelection component now renderes only the @@ -431,19 +436,16 @@ this.$router.replace(this.closePanelRoute); }, - // selectionMetadata(content) { - // if (content.kind === ContentNodeKinds.TOPIC) { - // const count = content.exercises.filter(exercise => - // Boolean(this.selectedExercises[exercise.id]) - // ).length; - // if (count === 0) { - // return ''; - // } - // const total = content.exercises.length; - // return this.$tr('total_number', { count, total }); - // } - // return ''; - // }, + selectionMetadata(content) { + if (content.kind === ContentNodeKinds.TOPIC) { + const count = this.workingResourcePool.length; + const total = content.children.results.length; + console.log(content); + console.log(this.workingResourcePool); + return this.selectedResourcesInformation$({ count, total }); + } + return ''; + }, }, }; diff --git a/packages/kolibri-common/strings/enhancedQuizManagementStrings.js b/packages/kolibri-common/strings/enhancedQuizManagementStrings.js index 7e14036b316..039a606f141 100644 --- a/packages/kolibri-common/strings/enhancedQuizManagementStrings.js +++ b/packages/kolibri-common/strings/enhancedQuizManagementStrings.js @@ -150,4 +150,8 @@ export const enhancedQuizManagementStrings = createTranslator('EnhancedQuizManag numberOfResources: { message: '{count, number} {count, plural, one {resource selected} other {resources selected}}', }, + selectedResourcesInformation: { + message: + '{count, number, integer} of {total, number, integer} {total, plural, one {resource selected} other {resources selected}}', + }, }); From 609c3077ec42aadc0d673f3012d99034a860b1a4 Mon Sep 17 00:00:00 2001 From: Jacob Pierce Date: Thu, 1 Feb 2024 14:40:50 -0800 Subject: [PATCH 03/10] get exercise counts -- and make sure channels are treated as topics for this --- .../src/composables/useQuizResources.js | 37 +++++++++++++------ .../plan/CreateExamPage/ResourceSelection.vue | 2 +- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/composables/useQuizResources.js b/kolibri/plugins/coach/assets/src/composables/useQuizResources.js index d6efb4e5f87..52962abb7e8 100644 --- a/kolibri/plugins/coach/assets/src/composables/useQuizResources.js +++ b/kolibri/plugins/coach/assets/src/composables/useQuizResources.js @@ -47,31 +47,44 @@ export default function useQuizResources({ topicId } = {}) { * the_resources have been updated, filtering out all topics which do not have assessments */ async function annotateTopicsWithDescendantCounts(topicIds = []) { - return ContentNodeResource.fetchDescendantsAssessments(topicIds) - .then(({ data: topicsWithDescendantCounts }) => { + const promises = [ + ContentNodeResource.fetchDescendantsAssessments(topicIds), + ContentNodeResource.fetchDescendants(topicIds, { + descendant__kind: ContentNodeKinds.EXERCISE, + }), + ]; + return Promise.all(promises) + .then(([{ data: topicsWithAssessmentCounts }, { data: exerciseDescendants }]) => { const childrenWithAnnotatedTopics = get(_resources) .map(node => { // We'll map so that the topics are updated in place with the num_assessments, others // are left as-is - if (node.kind === ContentNodeKinds.TOPIC) { - const topic = topicsWithDescendantCounts.find(t => t.id === node.id); - if (topic) { - node.num_assessments = topic.num_assessments; + if ([ContentNodeKinds.TOPIC, ContentNodeKinds.CHANNEL].includes(node.kind)) { + const topicWithAssessments = topicsWithAssessmentCounts.find(t => t.id === node.id); + if (topicWithAssessments) { + node.num_assessments = topicWithAssessments.num_assessments; } + exerciseDescendants.forEach(exercise => { + if (exercise.ancestor_id === node.id) { + node.num_exercises ? (node.num_exercises += 1) : (node.num_exercises = 1); + } + }); + if (!validateObject(node, QuizExercise)) { - logger.warn('Topic node was not a valid QuizExercise after annotation:', node); + logger.error('Topic node was not a valid QuizExercise after annotation:', node); } } return node; }) .filter(node => { // Only keep topics which have assessments in them to begin with - if (node.kind !== ContentNodeKinds.TOPIC) { - return true; - } - return node.num_assessments > 0; + return ( + node.kind === ContentNodeKinds.EXERCISE || + ([ContentNodeKinds.TOPIC, ContentNodeKinds.CHANNEL].includes(node.kind) && + node.num_assessments > 0) + ); }); - set(_resources, childrenWithAnnotatedTopics); + setResources(childrenWithAnnotatedTopics); }) .catch(e => { // TODO Work out best UX for this situation -- it may depend on if we're fetching more diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 7e4e113ef04..bfa5f43af25 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -228,7 +228,7 @@ // to the value of the channels (treating those channels as the topics) -- we then // call this annotateTopicsWithDescendantCounts method to ensure that the channels are // annotated with their num_assessments and those without assessments are filtered out - annotateTopicsWithDescendantCounts(channels.value.map(c => c.id)).then(() => { + annotateTopicsWithDescendantCounts(resources.value.map(c => c.id)).then(() => { _loading.value = false; }); }); From cc1c2aac7ac4de585df14b07104ef3ad323c1339 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:43:11 +0300 Subject: [PATCH 04/10] displays proper count --- .../plan/CreateExamPage/ResourceSelection.vue | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index bfa5f43af25..6600dbec3f1 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -311,7 +311,16 @@ isSelectAllChecked() { // Returns true if all the resources in the topic are in the working resource pool const workingResourceIds = this.workingResourcePool.map(wr => wr.id); - return this.contentList.every(content => workingResourceIds.includes(content.id)); + if(this.contentList.every(content => workingResourceIds.includes(content.id))){ + this.contentList.forEach(resource => { + if(resource.kind === ContentNodeKinds.TOPIC){ + this.addToWorkingResourcePool(resource.children.results); + } + }); + return true; + }else{ + return false; + } }, selectAllIndeterminate() { // Returns true if some, but not all, of the resources in the topic are in the working @@ -439,9 +448,7 @@ selectionMetadata(content) { if (content.kind === ContentNodeKinds.TOPIC) { const count = this.workingResourcePool.length; - const total = content.children.results.length; - console.log(content); - console.log(this.workingResourcePool); + const total = content.num_exercises; return this.selectedResourcesInformation$({ count, total }); } return ''; From b20ee86aad4136f199ed93901d0de2cc55fee112 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Fri, 2 Feb 2024 19:44:48 +0300 Subject: [PATCH 05/10] displays proper count --- .../plan/CreateExamPage/ResourceSelection.vue | 51 ++++++++++--------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 6600dbec3f1..d0f59ab7d01 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -295,7 +295,7 @@ addToWorkingResourcePool, removeFromWorkingResourcePool, showBookmarks, - selectedResourcesInformation$ + selectedResourcesInformation$, }; }, props: { @@ -311,14 +311,15 @@ isSelectAllChecked() { // Returns true if all the resources in the topic are in the working resource pool const workingResourceIds = this.workingResourcePool.map(wr => wr.id); - if(this.contentList.every(content => workingResourceIds.includes(content.id))){ + + if (this.contentList.every(content => workingResourceIds.includes(content.id))) { this.contentList.forEach(resource => { - if(resource.kind === ContentNodeKinds.TOPIC){ + if (resource.kind === ContentNodeKinds.TOPIC) { this.addToWorkingResourcePool(resource.children.results); } }); return true; - }else{ + } else { return false; } }, @@ -334,27 +335,27 @@ // selectionMetadata(content) { // console.log(content); // return ()=>{}; - // TODO This should return a function that returns a string telling us how many of this - // topic's descendants are selected out of its total descendants -- basically answering - // "How many resources in the working resource_pool are from this topic?" - // Tracked in https://github.com/learningequality/kolibri/issues/11741 - // return () => { this.workingResourcePool.length }; - // let count = 0; - // let total = 0; - // if (this.ancestorCounts[content.id]) { - // count = this.ancestorCounts[content.id].count; - // total = this.ancestorCounts[content.id].total; - // } - // if (count) { - // return this.$tr('selectionInformation', { - // '32', - // '45', - // }); - // } - // return ''; - // return function() { - // console.log('Dynamic function called'); - // }; + // TODO This should return a function that returns a string telling us how many of this + // topic's descendants are selected out of its total descendants -- basically answering + // "How many resources in the working resource_pool are from this topic?" + // Tracked in https://github.com/learningequality/kolibri/issues/11741 + // return () => { this.workingResourcePool.length }; + // let count = 0; + // let total = 0; + // if (this.ancestorCounts[content.id]) { + // count = this.ancestorCounts[content.id].count; + // total = this.ancestorCounts[content.id].total; + // } + // if (count) { + // return this.$tr('selectionInformation', { + // '32', + // '45', + // }); + // } + // return ''; + // return function() { + // console.log('Dynamic function called'); + // }; // }, getBookmarksLink() { From 91f6ed02d75f0384d9fc1cacf4f15ea8a53b079f Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Mon, 5 Feb 2024 16:38:12 +0300 Subject: [PATCH 06/10] cleanup console.log --- .../plan/CreateExamPage/ResourceSelection.vue | 25 ------------------- 1 file changed, 25 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index d0f59ab7d01..d607757cbe0 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -332,31 +332,6 @@ this.contentList.some(content => workingResourceIds.includes(content.id)) ); }, - // selectionMetadata(content) { - // console.log(content); - // return ()=>{}; - // TODO This should return a function that returns a string telling us how many of this - // topic's descendants are selected out of its total descendants -- basically answering - // "How many resources in the working resource_pool are from this topic?" - // Tracked in https://github.com/learningequality/kolibri/issues/11741 - // return () => { this.workingResourcePool.length }; - // let count = 0; - // let total = 0; - // if (this.ancestorCounts[content.id]) { - // count = this.ancestorCounts[content.id].count; - // total = this.ancestorCounts[content.id].total; - // } - // if (count) { - // return this.$tr('selectionInformation', { - // '32', - // '45', - // }); - // } - // return ''; - // return function() { - // console.log('Dynamic function called'); - // }; - // }, getBookmarksLink() { // Inject the showBookmarks parameter so that From 72effa51094336224441604123cbae0fc9b3844a Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Mon, 5 Feb 2024 18:18:54 +0300 Subject: [PATCH 07/10] Remove side-effects code from the isSelectAllChecked computed prop --- .../plan/CreateExamPage/ResourceSelection.vue | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index d607757cbe0..ee226627835 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -313,11 +313,7 @@ const workingResourceIds = this.workingResourcePool.map(wr => wr.id); if (this.contentList.every(content => workingResourceIds.includes(content.id))) { - this.contentList.forEach(resource => { - if (resource.kind === ContentNodeKinds.TOPIC) { - this.addToWorkingResourcePool(resource.children.results); - } - }); + this.addToWorkingResourcePoolForTopics(this.contentList); return true; } else { return false; @@ -386,9 +382,9 @@ this.removeFromWorkingResourcePool(content); } }, - addToSelectedResources(content) { - this.addToWorkingResourcePool([content]); - }, + // addToSelectedResources(content) { + // this.addToWorkingResourcePool([content]); + // }, toggleTopicInWorkingResources(isChecked) { if (isChecked) { this.addToWorkingResourcePool(this.contentList); @@ -396,6 +392,13 @@ this.resetWorkingResourcePool(); } }, + addToWorkingResourcePoolForTopics(topics) { + topics.forEach(topic => { + if (topic.kind === ContentNodeKinds.TOPIC) { + this.addToWorkingResourcePool(topic.children.results); + } + }); + }, topicListingLink({ topicId }) { return this.$router.getRoute( PageNames.QUIZ_SELECT_RESOURCES, From acf19496f1135d117e1b06e4e7b2275caa293c01 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Mon, 5 Feb 2024 20:37:01 +0300 Subject: [PATCH 08/10] code cleanup --- .../plan/CreateExamPage/ResourceSelection.vue | 24 +++++-------------- 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index ee226627835..4e40f7c829a 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -311,13 +311,7 @@ isSelectAllChecked() { // Returns true if all the resources in the topic are in the working resource pool const workingResourceIds = this.workingResourcePool.map(wr => wr.id); - - if (this.contentList.every(content => workingResourceIds.includes(content.id))) { - this.addToWorkingResourcePoolForTopics(this.contentList); - return true; - } else { - return false; - } + return this.contentList.every(content => workingResourceIds.includes(content.id)); }, selectAllIndeterminate() { // Returns true if some, but not all, of the resources in the topic are in the working @@ -382,23 +376,17 @@ this.removeFromWorkingResourcePool(content); } }, - // addToSelectedResources(content) { - // this.addToWorkingResourcePool([content]); - // }, toggleTopicInWorkingResources(isChecked) { if (isChecked) { this.addToWorkingResourcePool(this.contentList); } else { - this.resetWorkingResourcePool(); + this.contentList.forEach(content => { + if (content.kind === ContentNodeKinds.TOPIC) { + this.removeFromWorkingResourcePool(content); + } + }); } }, - addToWorkingResourcePoolForTopics(topics) { - topics.forEach(topic => { - if (topic.kind === ContentNodeKinds.TOPIC) { - this.addToWorkingResourcePool(topic.children.results); - } - }); - }, topicListingLink({ topicId }) { return this.$router.getRoute( PageNames.QUIZ_SELECT_RESOURCES, From 30a9341664f6f1b585ebea7f06c1a1edef85762d Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Mon, 5 Feb 2024 23:01:32 +0300 Subject: [PATCH 09/10] number of selected execrises display correctly per topic --- .../views/plan/CreateExamPage/ResourceSelection.vue | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 4e40f7c829a..1a798848b2e 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -414,9 +414,18 @@ }, selectionMetadata(content) { if (content.kind === ContentNodeKinds.TOPIC) { - const count = this.workingResourcePool.length; const total = content.num_exercises; - return this.selectedResourcesInformation$({ count, total }); + const numberOfresourcesSelected = this.workingResourcePool.reduce((acc, wr) => { + if (wr.ancestors.map(ancestor => ancestor.id).includes(content.id)) { + return acc + 1; + } + return acc; + }, 0); + + return this.selectedResourcesInformation$({ + count: numberOfresourcesSelected, + total: total, + }); } return ''; }, From ffee91851a4ec33f3920fba9ec91635d083b62b9 Mon Sep 17 00:00:00 2001 From: Allan Otodi Opeto <103313919+AllanOXDi@users.noreply.github.com> Date: Fri, 9 Feb 2024 19:06:08 +0300 Subject: [PATCH 10/10] can deselect exercises from the working resource pool --- .../src/views/plan/CreateExamPage/ResourceSelection.vue | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue index 1a798848b2e..46aa59b8c75 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -371,7 +371,7 @@ }, toggleSelected({ content, checked }) { if (checked) { - this.addToSelectedResources(content); + this.addToWorkingResourcePool([content]); } else { this.removeFromWorkingResourcePool(content); } @@ -381,9 +381,7 @@ this.addToWorkingResourcePool(this.contentList); } else { this.contentList.forEach(content => { - if (content.kind === ContentNodeKinds.TOPIC) { - this.removeFromWorkingResourcePool(content); - } + this.removeFromWorkingResourcePool(content); }); } },