Skip to content

Commit

Permalink
Merge pull request #10748 from rtibbles/scheduled_syncing_updates
Browse files Browse the repository at this point in the history
Scheduled syncing updates
  • Loading branch information
rtibbles authored Jun 7, 2023
2 parents 03af494 + 8224234 commit 3e5861d
Show file tree
Hide file tree
Showing 13 changed files with 557 additions and 280 deletions.
18 changes: 17 additions & 1 deletion kolibri/core/assets/src/views/sync/ConfirmationRegisterModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
:submitText="registerText"
:cancelText="cancelText"
@submit="registerFacility"
@cancel="$emit('cancel')"
@cancel="cancel"
>
<template v-if="!alreadyRegistered">
<p>{{ $tr('registerWith', { name: projectName }) }}</p>
Expand Down Expand Up @@ -44,6 +44,15 @@
type: String,
required: true,
},
/**
* Whether or not the modal should emit a success event
* after the facility has been discovered to be already registered.
*/
successOnAlreadyRegistered: {
type: Boolean,
required: false,
default: false,
},
},
data() {
return {
Expand Down Expand Up @@ -90,6 +99,13 @@
}
});
},
cancel() {
if (this.alreadyRegistered && this.successOnAlreadyRegistered) {
this.$emit('success', this.targetFacility);
} else {
this.$emit('cancel');
}
},
},
$trs: {
registerFacility: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
</template>
<KButton
:text="$tr('createSync')"
:disabled="isSyncing || isDeleting"
appearance="basic-link"
@click="manageSync"
/>
Expand Down
46 changes: 41 additions & 5 deletions kolibri/core/assets/src/views/sync/SyncFacilityModalGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,23 @@
@submit="handleAddressSubmit"
@cancel="closeModal()"
/>

<RegisterFacilityModal
v-else-if="atRegister"
:displaySkipOption="true"
@success="handleValidateSuccess"
@cancel="closeModal"
@skip="emitKdpSync"
/>
<ConfirmationRegisterModal
v-else-if="atConfirmation"
:targetFacility="facilityForSync"
:projectName="kdpProject.name"
:token="kdpProject.token"
:successOnAlreadyRegistered="true"
@success="emitKdpSync"
@cancel="closeModal"
/>
</div>

</template>
Expand All @@ -26,15 +43,21 @@
import commonSyncElements from 'kolibri.coreVue.mixins.commonSyncElements';
import SelectDeviceModalGroup from './SelectDeviceModalGroup';
import SelectSyncSourceModal from './SelectSyncSourceModal';
import RegisterFacilityModal from './RegisterFacilityModal';
import ConfirmationRegisterModal from './ConfirmationRegisterModal';
const Steps = Object.freeze({
SELECT_SOURCE: 'SELECT_SOURCE',
SELECT_ADDRESS: 'SELECT_ADDRESS',
REGISTER_FACILITY: 'REGISTER_FACILITY',
CONFIRMATION_REGISTER: 'CONFIRMATION_REGISTER',
});
export default {
name: 'SyncFacilityModalGroup',
components: {
ConfirmationRegisterModal,
RegisterFacilityModal,
SelectSyncSourceModal,
SelectDeviceModalGroup,
},
Expand All @@ -49,28 +72,34 @@
},
data() {
return {
step: null,
step: Steps.SELECT_SOURCE,
syncSubmitDisabled: false,
displaySkipOption: true,
kdpProject: null, // { name, token }
};
},
computed: {
atSelectSource() {
return !this.step;
return this.step === Steps.SELECT_SOURCE;
},
atSelectAddress() {
return this.step === Steps.SELECT_ADDRESS;
},
atRegister() {
return this.step === Steps.REGISTER_FACILITY;
},
atConfirmation() {
return this.step === Steps.CONFIRMATION_REGISTER;
},
},
methods: {
handleSourceSubmit(data) {
if (data.source === 'PEER') {
this.step = Steps.SELECT_ADDRESS;
} else {
if (this.facilityForSync.dataset.registered) {
this.$emit('syncKDP', this.facilityForSync);
this.emitKdpSync();
} else {
this.$emit('register', this.displaySkipOption, this.facilityForSync);
this.step = Steps.REGISTER_FACILITY;
}
}
},
Expand All @@ -80,9 +109,16 @@
}
this.$emit('syncPeer', data, this.facilityForSync);
},
handleValidateSuccess({ name, token }) {
this.kdpProject = { name, token };
this.step = Steps.CONFIRMATION_REGISTER;
},
closeModal() {
this.$emit('close');
},
emitKdpSync() {
this.$emit('syncKDP', this.facilityForSync);
},
},
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</p>
<div>
<FacilityTaskPanel
v-for="(task, idx) in facilityTasks"
v-for="(task, idx) in activeFacilityTasks"
:key="idx"
class="task-panel"
:style="{ borderBottomColor: $themePalette.grey.v_200 }"
Expand Down Expand Up @@ -80,7 +80,7 @@
return { name: PageNames.FACILITIES_PAGE };
},
someClearableTasks() {
return Boolean(this.facilityTasks.find(task => task.clearable));
return Boolean(this.activeFacilityTasks.find(task => task.clearable));
},
},
methods: {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Mixin that can be used for a component to view and manage
// the task queue
import { TaskResource } from 'kolibri.resources';
import { TaskTypes } from 'kolibri.utils.syncTaskUtils';
import { TaskStatuses, TaskTypes } from 'kolibri.utils.syncTaskUtils';

function isSyncTask(task) {
return task.type === TaskTypes.SYNCDATAPORTAL || task.type === TaskTypes.SYNCPEERFULL;
Expand All @@ -11,6 +11,13 @@ function taskFacilityMatch(task, facility) {
return task.facility_id === facility.id;
}

function isActiveTask(task) {
// Helper function filter tasks by whether they are 'active'
// i.e. has a user just queued a non-repeating task, or is a repeating task
// that is currently running.
return task.repeat !== null || task.status === TaskStatuses.RUNNING;
}

export default {
data() {
return {
Expand Down Expand Up @@ -41,10 +48,15 @@ export default {
this.isPolling = false;
},
computed: {
activeFacilityTasks() {
return this.facilityTasks.filter(isActiveTask);
},
facilityIsSyncing() {
return function isSyncing(facility) {
const syncTasks = this.facilityTasks.filter(t => isSyncTask(t) && !t.clearable);
return Boolean(syncTasks.find(task => taskFacilityMatch(task, facility)));
const inProcessSyncTasks = this.activeFacilityTasks.filter(
t => isSyncTask(t) && !t.clearable
);
return Boolean(inProcessSyncTasks.find(task => taskFacilityMatch(task, facility)));
};
},
facilityIsDeleting() {
Expand Down
15 changes: 3 additions & 12 deletions kolibri/plugins/device/assets/src/views/FacilitiesPage/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
</HeaderWithOptions>

<TasksBar
v-if="facilityTasks.length > 0"
:tasks="facilityTasks"
v-if="activeFacilityTasks.length > 0"
:tasks="activeFacilityTasks"
:taskManagerLink="{ name: 'FACILITIES_TASKS_PAGE' }"
@clearall="handleClickClearAll"
/>
Expand Down Expand Up @@ -153,7 +153,7 @@
<RegisterFacilityModal
v-if="!kdpProject"
:facility="facilityForRegister"
:displaySkipOption="displaySkipOption"
:displaySkipOption="false"
@success="handleValidateSuccess"
@cancel="clearRegistrationState"
@skip="handleKDPSync"
Expand All @@ -173,7 +173,6 @@
v-if="Boolean(facilityForSync)"
:facilityForSync="facilityForSync"
@close="facilityForSync = null"
@register="handleRegister"
@syncKDP="handleKDPSync"
@syncPeer="handlePeerSync"
/>
Expand Down Expand Up @@ -246,8 +245,6 @@
facilityForRegister: null,
kdpProject: null, // { name, token }
taskIdsToWatch: [],
displaySkipOption: false,
// (facilityTaskQueue) facilityTasks
};
},
computed: {
Expand Down Expand Up @@ -306,7 +303,6 @@
if (option === Options.REMOVE) {
this.facilityForRemoval = facility;
} else if (option === Options.REGISTER) {
this.displaySkipOption = false;
this.facilityForRegister = facility;
} else if (option === Options.MANAGESYNC) {
const route = this.manageSync(facility.id);
Expand Down Expand Up @@ -367,11 +363,6 @@
this.taskIdsToWatch.push(taskId);
this.facilityForRemoval = null;
},
handleRegister(displaySkipOption, facility) {
this.displaySkipOption = displaySkipOption;
this.facilityForRegister = facility;
this.facilityForSync = null;
},
handleKDPSync(facility) {
this.facilityForSync = null;
this.facilityForRegister = null;
Expand Down
10 changes: 8 additions & 2 deletions kolibri/plugins/facility/assets/src/routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,10 @@ export default [
const facilityId = route.params.facility_id || store.getters.currentFacilityId;
return {
facilityId,
goBackRoute: { name: PageNames.DATA_EXPORT_PAGE },
goBackRoute: {
name: PageNames.DATA_EXPORT_PAGE,
params: { facility_id: route.params.facility_id },
},
editSyncRoute: function(deviceId) {
return {
name: SyncPageNames.EDIT_SYNC_SCHEDULE,
Expand All @@ -180,7 +183,10 @@ export default [
return {
facilityId: route.params.facility_id || store.getters.currentFacilityId,
deviceId: route.params.deviceId,
goBackRoute: { name: SyncPageNames.MANAGE_SYNC_SCHEDULE },
goBackRoute: {
name: SyncPageNames.MANAGE_SYNC_SCHEDULE,
params: { facility_id: route.params.facility_id },
},
};
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@

<RegisterFacilityModal
v-if="modalShown === Modals.REGISTER_FACILITY"
:displaySkipOption="displaySkipOption"
:displaySkipOption="false"
@success="handleValidateSuccess"
@cancel="closeModal"
@skip="handleKDPSync"
Expand All @@ -102,7 +102,6 @@
v-if="modalShown === Modals.SYNC_FACILITY"
:facilityForSync="facility"
@close="closeModal"
@register="handleRegister"
@syncKDP="handleKDPSync"
@syncPeer="handlePeerSync"
/>
Expand Down Expand Up @@ -169,7 +168,6 @@
syncHasFailed: false,
Modals,
isMenuOpen: false,
displaySkipOption: false,
};
},
computed: {
Expand Down Expand Up @@ -265,9 +263,8 @@
handleSyncFacilityFailure() {
this.syncHasFailed = true;
},
handleRegister(displaySkipOption) {
handleRegister() {
this.closeMenu();
this.displaySkipOption = Boolean(displaySkipOption);
this.displayModal(Modals.REGISTER_FACILITY);
},
handleKDPSync() {
Expand Down
Loading

0 comments on commit 3e5861d

Please sign in to comment.