Skip to content

Commit 0cc905d

Browse files
authored
Merge pull request #1972 from jonboiser/update-export
Update export-to-local-drive workflow
2 parents 33f6902 + ab330e7 commit 0cc905d

File tree

5 files changed

+62
-25
lines changed

5 files changed

+62
-25
lines changed

kolibri/plugins/management/assets/src/state/manageContentActions.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@ export function refreshChannelList() {
2020
* @returns {Promise}
2121
*/
2222
export function deleteChannel(store, channelId) {
23-
return ChannelResource.getModel(channelId).delete().then(refreshChannelList);
23+
return ChannelResource.getModel(channelId)
24+
.delete()
25+
.then(() => {
26+
store.dispatch(mutationTypes.REMOVE_CHANNEL_FILE_SUMMARY, channelId);
27+
})
28+
.then(refreshChannelList);
2429
}
2530

2631
/**
@@ -54,6 +59,7 @@ export function addChannelFileSummary(store, channelId) {
5459
*/
5560
export function addChannelFileSummaries(store, channelIds) {
5661
channelIds.forEach(channelId => {
62+
if (store.state.pageState[channelId]) return;
5763
addChannelFileSummary(store, channelId);
5864
});
5965
}
Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,31 @@
1+
import Vue from 'vue';
12
import { PageNames } from '../constants';
23

34
export const mutationTypes = {
45
ADD_CHANNEL_FILE_SUMMARY: 'MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY',
6+
REMOVE_CHANNEL_FILE_SUMMARY: 'MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY',
57
};
68

79
function isManageContentPage(state) {
810
return state.pageName === PageNames.CONTENT_MGMT_PAGE;
911
}
1012

11-
const mutations = {
12-
MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY: (state, fileSummary) => {
13-
if (isManageContentPage(state)) {
14-
state.pageState.channelFileSummaries[fileSummary.channel_id] = {
15-
totalFileSizeInBytes: fileSummary.total_file_size,
16-
numberOfFiles: fileSummary.total_files,
17-
};
18-
}
19-
},
20-
};
13+
function MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY(state, fileSummary) {
14+
if (isManageContentPage(state)) {
15+
state.pageState.channelFileSummaries[fileSummary.channel_id] = {
16+
totalFileSizeInBytes: fileSummary.total_file_size,
17+
numberOfFiles: fileSummary.total_files,
18+
};
19+
}
20+
}
2121

22-
export { mutations as default };
22+
function MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY(state, channelId) {
23+
if (isManageContentPage(state)) {
24+
Vue.delete(state.pageState.channelFileSummaries, channelId);
25+
}
26+
}
27+
28+
export default {
29+
MANAGE_CONTENT_ADD_CHANNEL_FILE_SUMMARY,
30+
MANAGE_CONTENT_REMOVE_CHANNEL_FILE_SUMMARY,
31+
};

kolibri/plugins/management/assets/src/views/manage-content-page/channels-grid.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@
110110
this.addChannelFileSummaries(map(this.channelList, 'id'));
111111
},
112112
watch: {
113-
channelList(val, newVal) {
114-
this.addChannelFileSummaries(map(newVal, 'id'));
113+
channelList(val) {
114+
this.addChannelFileSummaries(map(val, 'id'));
115115
},
116116
},
117117
methods: {

kolibri/plugins/management/assets/src/views/manage-content-page/wizard-export.vue

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
<div class="main">
1111
<template v-if="!drivesLoading">
1212
<div class="modal-message">
13+
<p>
14+
{{ $tr('exportPrompt', { numChannels: allChannels.length, exportSize }) }}
15+
</p>
1316
<drive-list
1417
:value="selectedDrive"
1518
:drives="wizardState.driveList"
@@ -53,15 +56,20 @@
5356
import kButton from 'kolibri.coreVue.components.kButton';
5457
import loadingSpinner from 'kolibri.coreVue.components.loadingSpinner';
5558
import driveList from './wizards/drive-list';
59+
import sumBy from 'lodash/sumBy';
60+
5661
export default {
5762
name: 'wizardExport',
5863
$trs: {
59-
title: 'Export to a Local Drive',
60-
available: 'Available Storage:',
61-
notWritable: 'Not writable',
64+
available: 'available',
6265
cancel: 'Cancel',
6366
export: 'Export',
67+
exportPrompt:
68+
'You are about to export {numChannels, number} {numChannels, plural, one {channel} other {channels}} ({exportSize})',
69+
notWritable: 'Not writable',
6470
refresh: 'Refresh',
71+
title: 'Export to where?',
72+
waitForTotalSize: 'Calculating size...',
6573
},
6674
components: {
6775
coreModal,
@@ -77,10 +85,20 @@
7785
canSubmit() {
7886
return !this.drivesLoading && !this.wizardState.busy && this.selectedDrive !== '';
7987
},
88+
exportSize() {
89+
const allChannelsHaveStats = this.allChannels.reduce((flag, channel) => {
90+
return flag && Boolean(this.channelsWithStats[channel.id]);
91+
}, true);
92+
if (allChannelsHaveStats) {
93+
const totalSize = sumBy(Object.values(this.channelsWithStats), 'totalFileSizeInBytes');
94+
return bytesForHumans(totalSize);
95+
}
96+
return this.$tr('waitForTotalSize');
97+
},
8098
},
8199
methods: {
82100
formatEnabledMsg(drive) {
83-
return `${this.$tr('available')} ${bytesForHumans(drive.freespace)}`;
101+
return `${bytesForHumans(drive.freespace)} ${this.$tr('available')}`;
84102
},
85103
driveIsEnabled(drive) {
86104
return drive.writable;
@@ -100,7 +118,11 @@
100118
},
101119
},
102120
vuex: {
103-
getters: { wizardState: state => state.pageState.wizardState },
121+
getters: {
122+
allChannels: state => state.core.channels.list,
123+
channelsWithStats: state => state.pageState.channelFileSummaries,
124+
wizardState: state => state.pageState.wizardState,
125+
},
104126
actions: {
105127
transitionWizardPage: manageContentActions.transitionWizardPage,
106128
updateWizardLocalDriveList: actions.updateWizardLocalDriveList,

kolibri/plugins/management/assets/src/views/manage-content-page/wizards/drive-list.vue

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@
1313
<k-radio-button
1414
v-for="drive in enabledDrives"
1515
:key="drive.id"
16-
:label="genEnabledDriveLabel(drive)"
16+
:label="enabledDriveLabel(drive)"
1717
:radiovalue="drive.id"
1818
v-model="selectedDrive"
1919
@change="$emit('change', drive.id)"
2020
/>
2121
<k-radio-button
2222
v-for="drive in disabledDrives"
2323
:key="drive.id"
24-
:label="genDisabledDriveLabel(drive)"
24+
:label="disabledDriveLabel(drive)"
2525
:radiovalue="drive.id"
2626
:disabled="true"
2727
v-model="selectedDrive"
@@ -37,6 +37,7 @@
3737
import kRadioButton from 'kolibri.coreVue.components.kRadioButton';
3838
3939
export default {
40+
name: 'wizardDriveList',
4041
components: { kRadioButton },
4142
props: {
4243
value: {
@@ -69,20 +70,19 @@
6970
},
7071
},
7172
methods: {
72-
genEnabledDriveLabel(drive) {
73+
enabledDriveLabel(drive) {
7374
let driveLabel = drive.name;
7475
if (this.enabledMsg) {
7576
driveLabel += ` (${this.enabledMsg(drive)})`;
7677
}
7778
return driveLabel;
7879
},
79-
genDisabledDriveLabel(drive) {
80+
disabledDriveLabel(drive) {
8081
return `${drive.name} (${this.disabledMsg})`;
8182
},
8283
},
83-
name: 'wizardDriveList',
8484
$trs: {
85-
drivesFound: 'Drives found:',
85+
drivesFound: 'Drives found',
8686
noDrivesDetected: 'No drives were detected',
8787
},
8888
};

0 commit comments

Comments
 (0)