Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion kolibri_explore_plugin/assets/src/kolibriApi.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@ class KolibriApi {
}
const kind = onlyContent ? 'content' : onlyTopics ? ContentNodeKinds.TOPIC : undefined;

const includeUnavailable =
'includeUnavailable' in options ? options.includeUnavailable : !DEFAULT_HIDE_UNAVAILABLE;

return ContentNodeResource.fetchCollection({
getParams: {
ids: options.ids,
Expand All @@ -76,7 +79,7 @@ class KolibriApi {
kind: kind,
kind_in: kinds,
descendant_of: options.descendantOf,
no_available_filtering: true,
...(includeUnavailable && { no_available_filtering: true }),
},
}).then(contentNodes => {
const { more, results } = contentNodes;
Expand Down
42 changes: 37 additions & 5 deletions packages/template-ui/src/views/Home.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@
<EkCardGridPlaceholder />
</template>
<template v-else>
<FilterContent v-if="hasFilters" />

<b-container>
<b-row alignH="between">
<b-col>
<b-form-checkbox v-model="hideUnavailableItems" name="check-only-downloaded" switch>
Only downloaded items
</b-form-checkbox>
</b-col>

<b-col v-if="hasFilters">
<FilterContent />
</b-col>
</b-row>
</b-container>

<template v-if="isFilterEmpty">
<template v-if="contentNodes.nodes.length">
Expand All @@ -38,6 +51,7 @@
:key="section.id"
>
<EkCardGrid
v-if="sectionNodes[section.id].nodes.length"
:id="section.id"
:nodes="sectionNodes[section.id].nodes"
:hasMoreNodes="sectionNodes[section.id].hasMoreNodes"
Expand Down Expand Up @@ -73,6 +87,7 @@ export default {
loadingCarouselNodes: true,
loadingContentNodes: true,
loadingSectionNodes: true,
hideUnavailableItems: window.kolibri.defaultHideUnavailable,
};
},
computed: {
Expand Down Expand Up @@ -100,6 +115,13 @@ export default {
mainSections() {
return this.fetchSectionNodes();
},
hideUnavailableItems() {
return Promise.all([
this.fetchCarouselNodes(),
this.fetchContentNodes(),
this.fetchSectionNodes(),
]);
},
},
mounted() {
return Promise.all([
Expand All @@ -115,8 +137,10 @@ export default {
}
this.loadingCarouselNodes = true;
if (this.carouselNodeIds.length) {
return window.kolibri.getContentByFilter({ ids: this.carouselNodeIds })
.then((page) => {
return window.kolibri.getContentByFilter({
ids: this.carouselNodeIds,
includeUnavailable: !this.hideUnavailableItems,
}).then((page) => {
this.carouselNodes = page.results;
this.loadingCarouselNodes = false;
});
Expand All @@ -138,6 +162,7 @@ export default {
return window.kolibri.getContentByFilter({
...options,
maxResults: constants.ItemsPerPage,
includeUnavailable: !this.hideUnavailableItems,
})
.then((pageResult) => {
this.contentNodes = {
Expand All @@ -160,6 +185,7 @@ export default {
return window.kolibri.getContentByFilter({
parent: section.id,
maxResults: sectionPageSize,
includeUnavailable: !this.hideUnavailableItems,
})
.then((pageResult) => {
this.$set(this.sectionNodes, section.id, {
Expand All @@ -177,7 +203,10 @@ export default {
if (!hasMoreNodes) {
return null;
}
return window.kolibri.getContentPage(pagination).then((pageResult) => {
return window.kolibri.getContentPage({
...pagination,
...(!this.hideUnavailableItems && { no_available_filtering: true }),
}).then((pageResult) => {
this.$set(this.sectionNodes, sectionId, {
nodes: nodes.concat(pageResult.results),
hasMoreNodes: pageResult.more !== null,
Expand All @@ -190,7 +219,10 @@ export default {
if (!hasMoreNodes) {
return null;
}
return window.kolibri.getContentPage(pagination).then((pageResult) => {
return window.kolibri.getContentPage({
...pagination,
...(!this.hideUnavailableItems && { no_available_filtering: true }),
}).then((pageResult) => {
this.contentNodes = {
nodes: nodes.concat(pageResult.results),
hasMoreNodes: pageResult.more !== null,
Expand Down
23 changes: 22 additions & 1 deletion packages/template-ui/src/views/ListSection.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,18 @@
>
<ChannelHeader :section="section" />

<b-container v-if="false">
<div class="my-4">
<b-form-checkbox
v-model="hideUnavailableItems"
name="check-only-downloaded"
switch
>
Only downloaded items
</b-form-checkbox>
</div>
</b-container>

<div v-if="isInlineLevel">
<template v-if="loadingSubsectionNodes">
<EkCardGridPlaceholder
Expand Down Expand Up @@ -71,6 +83,7 @@ export default {
return {
subsectionNodes: { nodes: [], hasMoreNodes: false, pagination: null },
loadingSubsectionNodes: true,
hideUnavailableItems: window.kolibri.defaultHideUnavailable,
};
},
computed: {
Expand All @@ -92,6 +105,10 @@ export default {
this.loadInlineLevel();
}
},
hideUnavailableItems() {
console.log("Switched again!");
return this.fetchSubsectionNodes();
},
},
mounted() {
if (this.isInlineLevel) {
Expand All @@ -115,6 +132,7 @@ export default {
return window.kolibri.getContentByFilter({
parent: subsection.id,
maxResults: sectionPageSize,
includeUnavailable: !this.hideUnavailableItems,
})
.then((pageResult) => {
this.$set(this.subsectionNodes, subsection.id, {
Expand All @@ -132,7 +150,10 @@ export default {
if (!hasMoreNodes) {
return null;
}
return window.kolibri.getContentPage(pagination).then((pageResult) => {
return window.kolibri.getContentPage({
...pagination,
...(!this.hideUnavailableItems && { no_available_filtering: true }),
}).then((pageResult) => {
this.$set(this.subsectionNodes, sectionId, {
nodes: nodes.concat(pageResult.results),
hasMoreNodes: pageResult.more !== null,
Expand Down