diff --git a/kolibri/plugins/coach/assets/src/composables/useResources.js b/kolibri/plugins/coach/assets/src/composables/useResources.js index 1c549cfae61..aed6a874d0d 100644 --- a/kolibri/plugins/coach/assets/src/composables/useResources.js +++ b/kolibri/plugins/coach/assets/src/composables/useResources.js @@ -1,17 +1,34 @@ import { ref, onMounted } from 'kolibri.lib.vueCompositionApi'; import { ChannelResource, ContentNodeResource } from 'kolibri.resources'; -// import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants'; -// import { getContentNodeThumbnail } from 'kolibri.utils.contentNode'; +import { ContentNodeKinds } from 'kolibri.coreVue.vuex.constants'; +import { getContentNodeThumbnail } from 'kolibri.utils.contentNode'; +import { set } from '@vueuse/core'; +import store from 'kolibri.coreVue.vuex.store'; + +// import { store } from 'vuex'; export function useResources() { const resources = ref(null); const channels = ref([]); const bookmarks = ref([]); + const contentList = ref([]); function fetchChannelResource() { ChannelResource.fetchCollection({ params: { has_exercises: true, available: true } }).then( response => { - channels.value = response; + // channels.value = response; + set( + channels, + response.map(chnl => { + return { + ...chnl, + id: chnl.root, + title: chnl.name, + kind: ContentNodeKinds.CHANNEL, + is_leaf: false, + }; + }) + ); } ); } @@ -22,85 +39,101 @@ export function useResources() { }); } - // function _getTopicsWithExerciseDescendants(topicIds = []) { - // return new Promise(resolve => { - // if (!topicIds.length) { - // resolve([]); - // return; - // } - // const topicsNumAssessmentDescendantsPromise - // = ContentNodeResource.fetchDescendantsAssessments( - // topicIds - // ); + 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: [], + }); + } + }); - // 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); + }); + }); + }); + } - // 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 => { + if (childNodes) { + 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); + }); + } + }); + } - 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); - // }); - // } ); + function filterLessonResource(lessonId) { + store + .dispatch('lessonSummary/saveLessonResources', { + lessonId: lessonId, + resources: store.state.lessonSummary.workingResources, + }) + .then(content => { + console.log(content); + }); } onMounted(() => { fetchChannelResource(); fetchBookMarkedResource(); filterAndAnnotateContentList(); + filterLessonResource(); }); return { resources, channels, bookmarks, + contentList, + filterLessonResource, }; } diff --git a/kolibri/plugins/coach/assets/src/routes/planExamRoutes.js b/kolibri/plugins/coach/assets/src/routes/planExamRoutes.js index 54ae6b9cdd0..bca08102637 100644 --- a/kolibri/plugins/coach/assets/src/routes/planExamRoutes.js +++ b/kolibri/plugins/coach/assets/src/routes/planExamRoutes.js @@ -47,27 +47,25 @@ 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 - // once you are in the bookmark resources page the only thing that we are interested in is the topic Id that always get updated name: PageNames.QUIZ_SELECT_RESOURCES, path: ':section_id/select-resources', - children:[ + children: [ { - name:PageNames.SELECT_FROM_RESOURCE, - path:':topic_id', - } - ] + name: PageNames.SELECT_FROM_RESOURCE, + path: ':topic_id', + }, + ], }, { name: PageNames.BOOK_MARKED_RESOURCES, path: ':section_id/book-marked-resources', - children:[ + children: [ { - name:PageNames.SELECT_FROM_RESOURCE, - path:':topic_id', - } - ] + name: PageNames.SELECT_FROM_RESOURCE, + path: ':topic_id', + }, + ], }, ], }, diff --git a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/BookMarkedResource.vue b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/BookMarkedResource.vue index 3ec1358e47c..569dc6c76ca 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/BookMarkedResource.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/BookMarkedResource.vue @@ -59,10 +59,10 @@ type: Number, required: true, }, - to:{ - type:Object, - required:true, - } + to: { + type: Object, + required: true, + }, }, computed: { bookMarkBackgroundColor() { @@ -71,9 +71,6 @@ }; }, }, - mounted(){ - console.log(this.$route.params); - } }; 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 c6229d20cf6..dd9a4b6887e 100644 --- a/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue +++ b/kolibri/plugins/coach/assets/src/views/plan/CreateExamPage/ResourceSelection.vue @@ -1,41 +1,69 @@