Skip to content

Commit

Permalink
Merge pull request #907 from endlessm/T35159-persist-pack-selection
Browse files Browse the repository at this point in the history
Persist content pack choice
  • Loading branch information
manuq authored Jan 29, 2024
2 parents b8b78c8 + f170fec commit d969788
Show file tree
Hide file tree
Showing 13 changed files with 622 additions and 204 deletions.
6 changes: 6 additions & 0 deletions kolibri_explore_plugin/api_urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from rest_framework import routers

from .collectionviews import cancel_download
from .collectionviews import current_collection_exists
from .collectionviews import get_all_collections_info
from .collectionviews import get_collection_info
from .collectionviews import get_download_status
Expand Down Expand Up @@ -39,6 +40,11 @@

urlpatterns = [
url(r"^", include(router.urls)),
url(
r"ek-collections/current-collection-exists",
current_collection_exists,
name="current_collection_exists",
),
url(
r"ek-collections/get-collection-info",
get_collection_info,
Expand Down
16 changes: 12 additions & 4 deletions kolibri_explore_plugin/assets/src/modules/coreExplore/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,18 @@ export function updateContentNodeProgress(channelId, contentId, progressFraction
ContentNodeProgressResource.getModel(contentId).set({ progress_fraction: progressFraction });
}

export function getCollectionInfo(grade, name) {
export function currentCollectionExists() {
return client({
url: urls['kolibri:kolibri_explore_plugin:current_collection_exists'](),
}).then(({ data }) => {
return data;
});
}

export function getCollectionInfo(name, sequence) {
return client({
url: urls['kolibri:kolibri_explore_plugin:get_collection_info'](),
params: { grade, name },
params: { name, sequence },
}).then(({ data }) => {
return data.collectionInfo;
});
Expand Down Expand Up @@ -89,11 +97,11 @@ export function resumeDownload() {
});
}

export function startDownload(grade, name) {
export function startDownload(name, sequence) {
return client({
url: urls['kolibri:kolibri_explore_plugin:start_download'](),
method: 'POST',
data: { grade, name },
data: { name, sequence },
}).then(({ data }) => {
return data.status;
});
Expand Down
15 changes: 8 additions & 7 deletions kolibri_explore_plugin/assets/src/modules/topicsRoot/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { ChannelResource, ContentNodeResource } from '../../apiResources';
import { CarouselItemsLength, SEARCH_MAX_RESULTS, PageNames } from '../../constants';
import { CustomChannelApps, getBigThumbnail, getChannelIcon } from '../../customApps';
import {
currentCollectionExists,
getDownloadStatus,
getShouldResume,
resumeDownload,
Expand Down Expand Up @@ -147,17 +148,17 @@ export function decideWelcome(store) {
return Promise.resolve();
}

return Promise.all([getDownloadStatus(), getShouldResume()]).then(
([status, { shouldResume, grade, name }]) => {
if (_isDownloadComplete(status)) {
return Promise.all([currentCollectionExists(), getDownloadStatus(), getShouldResume()]).then(
([currentExists, status, { shouldResume, name, sequence }]) => {
if (currentExists || _isDownloadComplete(status)) {
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
console.debug('Welcome: Download complete, redirecting to Explore page...');
router.replace({ name: PageNames.TOPICS_ROOT });
} else if (_isDownloadOngoing(status) || shouldResume) {
console.debug('Welcome: Redirecting to Download page...');
// The catch here is needed for ignoring redundant navigation errors.
router.replace({ name: PageNames.DOWNLOAD, params: { grade, name } }).catch(() => {});
router.replace({ name: PageNames.DOWNLOAD, params: { name, sequence } }).catch(() => {});
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
Expand All @@ -178,7 +179,7 @@ export function decidePackSelection(store) {

if (languageIdToCode(currentLanguage) === 'es') {
console.debug('Welcome: Downloading Spanish pack directly...');
router.replace({ name: PageNames.DOWNLOAD, params: { grade: 'spanish', name: '0001' } });
router.replace({ name: PageNames.DOWNLOAD, params: { name: 'spanish', sequence: '0001' } });
} else {
store.commit('SET_PAGE_NAME', PageNames.WELCOME_PACK_SELECTION);
}
Expand All @@ -187,7 +188,7 @@ export function decidePackSelection(store) {
store.commit('CORE_SET_ERROR', null);
}

export function decideDownload(store, grade, name) {
export function decideDownload(store, name, sequence) {
store.commit('CORE_SET_PAGE_LOADING', true);

return Promise.all([getDownloadStatus(), getShouldResume()]).then(
Expand All @@ -211,7 +212,7 @@ export function decideDownload(store, grade, name) {
});
} else {
console.debug('Downloading starter pack...');
return startDownload(grade, name).then(() => {
return startDownload(name, sequence).then(() => {
store.commit('SET_PAGE_NAME', PageNames.DOWNLOAD);
store.commit('CORE_SET_PAGE_LOADING', false);
store.commit('CORE_SET_ERROR', null);
Expand Down
6 changes: 3 additions & 3 deletions kolibri_explore_plugin/assets/src/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@ export default [
},
{
name: PageNames.WELCOME_PACK_READY,
path: '/welcome/pack-ready/:grade/:name',
path: '/welcome/pack-ready/:name/:sequence',
handler: () => {
store.commit('SET_PAGE_NAME', PageNames.WELCOME_PACK_READY);
},
},
{
name: PageNames.DOWNLOAD,
path: '/download/:grade/:name',
path: '/download/:name/:sequence',
handler: toRoute => {
decideDownload(store, toRoute.params.grade, toRoute.params.name);
decideDownload(store, toRoute.params.name, toRoute.params.sequence);
},
},
{
Expand Down
4 changes: 2 additions & 2 deletions kolibri_explore_plugin/assets/src/views/DownloadPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@
},
},
mounted() {
return getCollectionInfo(this.$route.params.grade, this.$route.params.name).then(
return getCollectionInfo(this.$route.params.name, this.$route.params.sequence).then(
collectionsInfo => {
this.packTitle = collectionsInfo.metadata.title;
this.packTitle = collectionsInfo.title;
return this.setUpdateInterval();
}
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@
};
},
mounted() {
return getCollectionInfo(this.$route.params.grade, this.$route.params.name).then(
return getCollectionInfo(this.$route.params.name, this.$route.params.sequence).then(
collectionsInfo => {
this.isDownloadRequired = collectionsInfo.isDownloadRequired;
}
);
},
methods: {
downloadContent() {
const grade = this.$route.params.grade;
const name = this.$route.params.name;
this.$router.push({ name: PageNames.DOWNLOAD, params: { grade, name } });
const sequence = this.$route.params.sequence;
this.$router.push({ name: PageNames.DOWNLOAD, params: { name, sequence } });
},
},
$trs: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,10 @@
methods: {
packMetadataTitle,
packMetadataSubtitle,
choosePack(grade) {
choosePack(name) {
// FIXME: This is hardcoded to the (currently) only option.
const name = '0001';
this.$router.push({ name: PageNames.WELCOME_PACK_READY, params: { grade, name } });
const sequence = '0001';
this.$router.push({ name: PageNames.WELCOME_PACK_READY, params: { name, sequence } });
},
},
$trs: {
Expand Down
Loading

0 comments on commit d969788

Please sign in to comment.