Skip to content

Commit

Permalink
template: Use descendant_of filter
Browse files Browse the repository at this point in the history
This change adapts the API to the changes upstream in this PR:
learningequality/kolibri#8796

https://phabricator.endlessm.com/T32761
  • Loading branch information
danigm committed Dec 3, 2021
1 parent 64ee3d5 commit 439ef3b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
31 changes: 12 additions & 19 deletions kolibri_explore_plugin/assets/src/kolibriApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,33 +34,26 @@ class KolibriApi {
}

getContentByFilter(options) {
const { kinds, onlyContent, onlyTopics, withinDescendant } = options;
const { kinds, onlyContent, onlyTopics } = options;

if (onlyContent && onlyTopics) {
const err = new Error('onlyContent and onlyTopics can not be used at the same time');
throw err;
}
const kind = onlyContent ? 'content' : onlyTopics ? ContentNodeKinds.TOPIC : undefined;

const getParams = {
ids: options.ids,
authors: options.authors,
tags: options.tags,
channel_id: this.channelId,
parent: options.parent === 'self' ? this.channelId : options.parent,
max_results: options.maxResults ? options.maxResults : 50,
kind: kind,
kind_in: kinds,
};

if (withinDescendant) {
getParams.tree_id = withinDescendant.tree_id;
getParams.lft__gt = withinDescendant.lft;
getParams.rght__lt = withinDescendant.rght;
}

return ContentNodeResource.fetchCollection({
getParams,
getParams: {
ids: options.ids,
authors: options.authors,
tags: options.tags,
channel_id: this.channelId,
parent: options.parent === 'self' ? this.channelId : options.parent,
max_results: options.maxResults ? options.maxResults : 50,
kind: kind,
kind_in: kinds,
descendant_of: options.descendantOf,
},
}).then(contentNodes => {
return {
maxResults: options.maxResults ? options.maxResults : 50,
Expand Down
2 changes: 1 addition & 1 deletion packages/template-ui/src/components/FilterResult.vue
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
const params = {
cursor: this.pageCursor,
maxResults: constants.ItemsPerPage,
withinDescendant: this.node,
descendantOf: this.node ? this.node.id : null,
};
const kinds = this.query[constants.MediaFilterName];
Expand Down

0 comments on commit 439ef3b

Please sign in to comment.