Skip to content

Commit

Permalink
added dragging feature
Browse files Browse the repository at this point in the history
  • Loading branch information
AllanOXDi committed Nov 27, 2023
1 parent 75ec4ec commit 300b355
Show file tree
Hide file tree
Showing 6 changed files with 596 additions and 263 deletions.
169 changes: 101 additions & 68 deletions kolibri/plugins/coach/assets/src/composables/useResources.js
Original file line number Diff line number Diff line change
@@ -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,
};
})
);
}
);
}
Expand All @@ -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,
};
}
22 changes: 10 additions & 12 deletions kolibri/plugins/coach/assets/src/routes/planExamRoutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
],
},
],
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@
type: Number,
required: true,
},
to:{
type:Object,
required:true,
}
to: {
type: Object,
required: true,
},
},
computed: {
bookMarkBackgroundColor() {
Expand All @@ -71,9 +71,6 @@
};
},
},
mounted(){
console.log(this.$route.params);
}
};
</script>
Expand Down
Loading

0 comments on commit 300b355

Please sign in to comment.