Skip to content

Commit

Permalink
implement content filtering for select resource side panel
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Nov 22, 2023
1 parent 8ebe621 commit b14457f
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 3 deletions.
76 changes: 74 additions & 2 deletions kolibri/plugins/coach/assets/src/composables/useResources.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { ref, onMounted } from 'kolibri.lib.vueCompositionApi';
import { ChannelResource, ContentNodeResource as bookMarkedResource } from 'kolibri.resources';
import { ChannelResource,ContentNodeResource} from 'kolibri.resources';
import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants';
import { getContentNodeThumbnail } from 'kolibri.utils.contentNode';

export function useResources() {
const resources = ref(null);
Expand All @@ -15,14 +17,84 @@ export function useResources() {
}

function fetchBookMarkedResource() {
bookMarkedResource.fetchBookmarks({ params: { limit: 25, available: true } }).then(data => {
ContentNodeResource.fetchBookmarks({ params: { limit: 25, available: true } }).then(data => {
bookmarks.value = data.results ? data.results : [];
});
}

function _getTopicsWithExerciseDescendants(topicIds = []) {
return new Promise(resolve => {
if (!topicIds.length) {
resolve([]);
return;
}
const topicsNumAssessmentDescendantsPromise = ContentNodeResource.fetchDescendantsAssessments(
topicIds
);

topicsNumAssessmentDescendantsPromise.then(response => {
const topicsWithExerciseDescendants = [];
response.data.forEach(descendantAssessments => {
if (descendantAssessments.num_assessments > 0) {
topicsWithExerciseDescendants.push({
id: descendantAssessments.id,
numAssessments: descendantAssessments.num_assessments,
exercises: [],
});
}
});

ContentNodeResource.fetchDescendants(
topicsWithExerciseDescendants.map(topic => topic.id),
{
descendant_kind: ContentNodeKinds.EXERCISE,
}
).then(response => {
response.data.forEach(exercise => {
const topic = topicsWithExerciseDescendants.find(t => t.id === exercise.ancestor_id);
topic.exercises.push(exercise);
});
resolve(topicsWithExerciseDescendants);
});
});
});
}

function filterAndAnnotateContentList(childNodes) {
return new Promise(resolve => {
const childTopics = childNodes.filter(({ kind }) => kind === ContentNodeKinds.TOPIC);
const topicIds = childTopics.map(({ id }) => id);
const topicsThatHaveExerciseDescendants = _getTopicsWithExerciseDescendants(topicIds);

topicsThatHaveExerciseDescendants.then(topics => {
const childNodesWithExerciseDescendants = childNodes
.map(childNode => {
const index = topics.findIndex(topic => topic.id === childNode.id);
if (index !== -1) {
return { ...childNode, ...topics[index] };
}
return childNode;
})
.filter(childNode => {
if (childNode.kind === ContentNodeKinds.TOPIC && (childNode.numAssessments || 0) < 1) {
return false;
}
return true;
});

const contentList = childNodesWithExerciseDescendants.map(node => ({
...node,
thumbnail: getContentNodeThumbnail(node),
}));
resolve(contentList);
});
});
}

onMounted(() => {
fetchChannelResource();
fetchBookMarkedResource();
filterAndAnnotateContentList()
});

return {
Expand Down
8 changes: 8 additions & 0 deletions kolibri/plugins/coach/assets/src/routes/planExamRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export default [
path: ':section_id/replace-questions',
},
{
// this is basically show how the routing works once you in the select resources page and bookmarked resources page

Check failure on line 50 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a length of 123. Maximum allowed is 100

Check failure on line 50 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a comment length of 123. Maximum allowed is 100

Check failure on line 50 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a length of 123. Maximum allowed is 100

Check failure on line 50 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a comment length of 123. Maximum allowed is 100
// once you are in the bookmark resources page the only thing that we are interested in is the topic Id that always get updated

Check failure on line 51 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a length of 137. Maximum allowed is 100

Check failure on line 51 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a comment length of 137. Maximum allowed is 100

Check failure on line 51 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a length of 137. Maximum allowed is 100

Check failure on line 51 in kolibri/plugins/coach/assets/src/routes/planExamRoutes.js

View workflow job for this annotation

GitHub Actions / All file linting

This line has a comment length of 137. Maximum allowed is 100
name: PageNames.QUIZ_SELECT_RESOURCES,
path: ':section_id/select-resources',

Expand All @@ -60,6 +62,12 @@ export default [
{
name: PageNames.BOOK_MARKED_RESOURCES,
path: ':section_id/book-marked-resources',
children:[
{
name:PageNames.SELECT_FROM_RESOURCE,
path:':topic_id',
}
]
},
],
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<template>
<template>
<div class="">

<ContentCardList
Expand Down

0 comments on commit b14457f

Please sign in to comment.