From 90ccd472de06f6fad0f01fcf2bdde3783e871492 Mon Sep 17 00:00:00 2001 From: "Lisias (Lee) Loback" Date: Tue, 2 Jun 2020 13:10:54 +0100 Subject: [PATCH] #443 Multiselector Recommended --- src/router.js | 2 +- src/store/stage/recommended.js | 28 +++++--- .../Exercises/Stages/RecommendedEdit.vue | 10 +++ .../Exercises/Stages/RecommendedList.vue | 64 +++++++++++++++---- 4 files changed, 83 insertions(+), 21 deletions(-) diff --git a/src/router.js b/src/router.js index 546ba5ff9..afac0b0e6 100644 --- a/src/router.js +++ b/src/router.js @@ -287,7 +287,7 @@ const router = new Router({ }, }, { - path: 'recommended/:applicationId', + path: 'recommended/edit', component: ExerciseStagesRecommendedEdit, name: 'exercise-stages-recommended-edit', meta: { diff --git a/src/store/stage/recommended.js b/src/store/stage/recommended.js index 9c5e54eaf..6fecca772 100644 --- a/src/store/stage/recommended.js +++ b/src/store/stage/recommended.js @@ -26,14 +26,15 @@ export default { let firestoreRef = collectionRef .where('exercise.id', '==', exerciseId) .where('stage', '==', EXERCISE_STAGE.RECOMMENDED) - .where('active', '==', true); + .where('active', '==', true) + .limit(50); return bindFirestoreRef('records', firestoreRef, { serialize: vuexfireSerialize }); }), unbind: firestoreAction(({ unbindFirestoreRef }) => { return unbindFirestoreRef('records'); }), - updateStatus: async ( context, { applicationId, status } ) => { + updateStatus: async ( context, { status } ) => { let stageValue = EXERCISE_STAGE.RECOMMENDED; // initial value: 'recommended' if (status === APPLICATION_STATUS.APPROVED_FOR_IMMEDIATE_APPOINTMENT) { @@ -44,13 +45,20 @@ export default { status: status, stage: stageValue, }; - const ref = collectionRef.doc(applicationId); - await ref.update(data) - .then(() => { - const valueMessage = lookup(status); - context.commit('message', `Application id #${applicationId} changed to '${valueMessage}'`); + + const selectedItems = context.state.selectedItems; + const batch = firestore.batch(); + selectedItems.map( item => { + const ref = collectionRef.doc(item); + batch.update(ref, data); }); - // @TODO store message(s) for what's been updated so it/they can be retrieved later (on list page) + await batch.commit(); + + const valueMessage = lookup(status); + context.commit('message', `Updated ${selectedItems.length} candidates to '${valueMessage}'`); + }, + storeItems: ( context, { items }) => { + context.commit('changeSelectedItems', items); }, getMessages: (context) => { const localMsg = context.state.message; @@ -61,10 +69,14 @@ export default { state: { records: [], message: null, + selectedItems: [], }, mutations: { message(state, msg) { state.message = msg; }, + changeSelectedItems(state, items) { + state.selectedItems = items; + }, }, }; diff --git a/src/views/Exercises/Stages/RecommendedEdit.vue b/src/views/Exercises/Stages/RecommendedEdit.vue index fcf077d54..750ae5774 100644 --- a/src/views/Exercises/Stages/RecommendedEdit.vue +++ b/src/views/Exercises/Stages/RecommendedEdit.vue @@ -48,6 +48,16 @@ export default { availableStatuses() { return this.$store.getters['stageRecommended/availableStatuses']; }, + itemsToChange() { + const selectedItems = this.$store.state.stageRecommended.selectedItems; + return selectedItems; + }, + }, + created() { + // on refresh if there's no IDs to change => redirect to the list + if (this.itemsToChange.length === 0) { + this.$router.push({ name: 'exercise-stages-recommended-list' }); + } }, methods: { async save() { diff --git a/src/views/Exercises/Stages/RecommendedList.vue b/src/views/Exercises/Stages/RecommendedList.vue index 43a1e1230..a07993238 100644 --- a/src/views/Exercises/Stages/RecommendedList.vue +++ b/src/views/Exercises/Stages/RecommendedList.vue @@ -1,32 +1,62 @@