Skip to content

Commit ce8dec1

Browse files
authored
Merge pull request #2909 from marcellamaki/update-progress-modal
Update progress modal
2 parents bb1d8e6 + bc8c766 commit ce8dec1

File tree

6 files changed

+100
-27
lines changed

6 files changed

+100
-27
lines changed

contentcuration/contentcuration/frontend/channelEdit/views/TreeView/TreeViewBase.vue

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,11 +165,17 @@
165165
<slot></slot>
166166

167167
<PublishModal v-if="showPublishModal" v-model="showPublishModal" />
168-
<ProgressModal />
168+
<ProgressModal v-model="showProgressModal" :syncing="syncing" :noSyncNeeded="noSyncNeeded" />
169169
<template v-if="isPublished">
170170
<ChannelTokenModal v-model="showTokenModal" :channel="currentChannel" />
171171
</template>
172-
<SyncResourcesModal v-if="currentChannel" v-model="showSyncModal" :channel="currentChannel" />
172+
<SyncResourcesModal
173+
v-if="currentChannel"
174+
v-model="showSyncModal"
175+
:channel="currentChannel"
176+
@syncing="syncInProgress"
177+
@nosync="noResourcesToSync"
178+
/>
173179
<MessageDialog v-model="showDeleteModal" :header="$tr('deleteTitle')">
174180
{{ $tr('deletePrompt') }}
175181
<template #buttons="{ close }">
@@ -281,8 +287,11 @@
281287
showPublishModal: false,
282288
showTokenModal: false,
283289
showSyncModal: false,
290+
showProgressModal: false,
284291
showClipboard: false,
285292
showDeleteModal: false,
293+
syncing: false,
294+
noSyncNeeded: false,
286295
};
287296
},
288297
computed: {
@@ -397,6 +406,14 @@
397406
this.showSyncModal = true;
398407
this.trackClickEvent('Sync');
399408
},
409+
syncInProgress() {
410+
this.syncing = true;
411+
this.showProgressModal = true;
412+
},
413+
noResourcesToSync() {
414+
this.noSyncNeeded = true;
415+
this.showProgressModal = true;
416+
},
400417
deleteChannel() {
401418
this.showDeleteModal = true;
402419
this.trackClickEvent('Delete channel');

contentcuration/contentcuration/frontend/channelEdit/views/progress/ProgressModal.vue

Lines changed: 45 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
<div>
44
<VDialog
5-
v-if="(currentChannel && currentChannel.publishing) || currentTask"
5+
v-if="isSyncing || nothingToSync || isPublishing"
66
:value="true"
77
persistent
88
:width="575"
@@ -20,6 +20,7 @@
2020
{{ descriptionText }}
2121
</p>
2222
<ProgressBar
23+
v-if="!nothingToSync"
2324
:progressPercent="progressPercent"
2425
:currentTaskError="currentTaskError"
2526
/>
@@ -108,19 +109,52 @@
108109
type: String,
109110
default: '',
110111
},
112+
syncing: {
113+
type: Boolean,
114+
default: false,
115+
},
116+
noSyncNeeded: {
117+
type: Boolean,
118+
default: false,
119+
},
111120
},
112121
data() {
113122
return {
114123
step: 1,
115124
};
116125
},
117126
computed: {
118-
...mapGetters('task', ['publishTaskForChannel']),
127+
...mapGetters('task', ['currentTasksForChannel']),
119128
...mapGetters('currentChannel', ['currentChannel']),
129+
currentTasks() {
130+
return this.currentTasksForChannel(this.currentChannel.id) || null;
131+
},
132+
isSyncing() {
133+
return this.syncing && this.currentChannel && !this.currentChannel.publishing;
134+
},
135+
// this handles validation errors from the Sync Resources Modal
136+
// where .sync itself errors because of the validation error
137+
// for not syncing channels with no imported resources
138+
// this property is added her as a way to manager feedback to the user
139+
nothingToSync() {
140+
return this.noSyncNeeded;
141+
},
142+
isPublishing() {
143+
return this.currentChannel && this.currentChannel.publishing;
144+
},
120145
currentTask() {
121-
return this.publishTaskForChannel(this.currentChannel.id) || null;
146+
if (this.isSyncing) {
147+
return this.currentTasks.find(task => task.task_type === 'sync-channel');
148+
} else if (this.isPublishing) {
149+
return this.currentTasks.find(task => task.task_type === 'export-channel');
150+
} else {
151+
return null;
152+
}
122153
},
123154
progressPercent() {
155+
if (this.nothingToSync) {
156+
return 100;
157+
}
124158
return get(this.currentTask, ['metadata', 'progress'], 0);
125159
},
126160
currentTaskError() {
@@ -133,16 +167,15 @@
133167
if (this.currentTask) {
134168
if (this.currentTask.task_type === 'duplicate-nodes') {
135169
return this.$tr('copyHeader');
136-
} else if (this.currentTask.task_type === 'export-channel') {
170+
} else if (this.isPublishing) {
137171
return this.$tr('publishHeader');
138172
} else if (this.currentTask.task_type === 'move-nodes') {
139173
return this.$tr('moveHeader');
140-
} else if (
141-
this.currentTask.task_type === 'sync-channel' ||
142-
this.currentTask.task_type === 'sync-nodes'
143-
) {
174+
} else if (this.isSyncing || this.nothingToSync) {
144175
return this.$tr('syncHeader');
145176
}
177+
} else if (this.nothingToSync) {
178+
return this.$tr('syncHeader');
146179
}
147180
return this.$tr('publishHeader');
148181
},
@@ -152,16 +185,15 @@
152185
return this.$tr('finishedMessage');
153186
} else if (this.currentTask.task_type === 'duplicate-nodes') {
154187
return this.$tr('copyDescription');
155-
} else if (this.currentTask.task_type === 'export-channel') {
188+
} else if (this.isPublishing) {
156189
return this.$tr('publishDescription');
157190
} else if (this.currentTask.task_type === 'move-nodes') {
158191
return this.$tr('moveDescription');
159-
} else if (
160-
this.currentTask.task_type === 'sync-channel' ||
161-
this.currentTask.task_type === 'sync-nodes'
162-
) {
192+
} else if (this.isSyncing) {
163193
return this.$tr('syncDescription');
164194
}
195+
} else if (this.nothingToSync) {
196+
return this.$tr('finishedMessage');
165197
}
166198
return this.$tr('publishDescription');
167199
},

contentcuration/contentcuration/frontend/channelEdit/views/progress/__tests__/progressModal.spec.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,40 @@ import { factory } from '../../../store';
55
const store = factory();
66

77
const task = { task: { id: 123, task_type: 'test-task' } };
8+
const tasks = [
9+
{ task: { id: 123, task_type: 'test-task' } },
10+
{ task: { id: 456, task_type: 'test-task-2' } },
11+
];
812

913
function makeWrapper(computed = {}) {
1014
return mount(ProgressModal, {
1115
store,
1216
computed: {
17+
currentTasks() {
18+
return tasks;
19+
},
1320
currentTask() {
1421
return task;
1522
},
23+
isPublishing() {
24+
return true;
25+
},
1626
...computed,
1727
},
1828
});
1929
}
2030

2131
describe('progressModal', () => {
22-
it('should be hidden if there is no task', () => {
32+
it('should be hidden if the user is not syncing or publishing', () => {
2333
let wrapper = makeWrapper({
24-
currentTask() {
25-
return null;
34+
isSyncing() {
35+
return false;
36+
},
37+
nothingToSync() {
38+
return false;
39+
},
40+
isPublishing() {
41+
return false;
2642
},
2743
});
2844
expect(wrapper.find('[data-test="progressmodal"]').exists()).toBe(false);

contentcuration/contentcuration/frontend/channelEdit/views/sync/SyncResourcesModal.vue

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -170,9 +170,19 @@
170170
tags: this.syncTags,
171171
files: this.syncFiles,
172172
assessment_items: this.syncExercises,
173-
}).then(() => {
174-
this.confirmSyncModal = false;
175-
});
173+
})
174+
.then(() => {
175+
this.confirmSyncModal = false;
176+
this.$emit('syncing');
177+
})
178+
.catch(() => {
179+
// add a way for the progress modal to provide feedback
180+
// since the available error message doesn't make sense here,
181+
// for now we will just have the operation be reported complete
182+
// see ProgressModal nothingToSync for more info
183+
this.confirmSyncModal = false;
184+
this.$emit('nosync');
185+
});
176186
},
177187
},
178188
$trs: {

contentcuration/contentcuration/frontend/channelEdit/vuex/currentChannel/actions.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ export function publishChannel(context, version_notes) {
6363

6464
export function stopPublishing(context) {
6565
return Channel.clearPublish(context.state.currentChannelId).then(() => {
66-
const publishTask = context.rootGetters['task/publishTaskForChannel'](
66+
const publishTask = context.rootGetters['task/currentTasksForChannel'](
6767
context.state.currentChannelId
68-
);
68+
).find(task => task.task_type === 'export-channel');
6969
return publishTask
7070
? context.dispatch('task/deleteTask', publishTask, { root: true })
7171
: Promise.resolve();

contentcuration/contentcuration/frontend/channelEdit/vuex/task/index.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,9 @@ export default {
2424
return state.asyncTasksMap[taskId];
2525
};
2626
},
27-
publishTaskForChannel(state, getters) {
27+
currentTasksForChannel(state, getters) {
2828
return function(id) {
29-
return getters.asyncTasks.find(
30-
task => task.task_type === 'export-channel' && task.channel === id
31-
);
29+
return getters.asyncTasks.filter(task => task.channel === id);
3230
};
3331
},
3432
},

0 commit comments

Comments
 (0)