From 6c303ccc551e0ec5d11b32b1a326e8a7cc6c94c4 Mon Sep 17 00:00:00 2001 From: raxelsen Date: Fri, 20 Jul 2018 16:57:09 +0200 Subject: [PATCH] TT#40256 User wants to remove speed dial config Change-Id: I18090be6cc718e219a3a9cc145198dd4883d5dba --- src/api/speed-dial.js | 19 ++++++++++++ src/components/pages/SpeedDial.vue | 47 ++++++++++++++++++++++++++---- src/locales/en.json | 6 +++- src/store/speed-dial.js | 43 +++++++++++++++++++++++++-- 4 files changed, 107 insertions(+), 8 deletions(-) diff --git a/src/api/speed-dial.js b/src/api/speed-dial.js index 50796e97..837a9c2d 100644 --- a/src/api/speed-dial.js +++ b/src/api/speed-dial.js @@ -1,5 +1,6 @@ import _ from 'lodash' +import Vue from 'vue'; import { getFieldList } from './common' export function getSpeedDials(id) { @@ -34,3 +35,21 @@ export function getUnassignedSlots(id) { }); }); } + +export function unassignSpeedDialSlot(options) { + return new Promise((resolve, reject) => { + let updatedAssignedSlots = _.without(options.slots, options.slot); + let headers = { + 'Content-Type': 'application/json-patch+json' + }; + Vue.http.patch('api/speeddials/' + options.id, [{ + op: 'replace', + path: '/speeddials', + value: updatedAssignedSlots + }], { headers: headers }).then(() => { + resolve(); + }).catch((err) => { + reject(err.body.message); + }); + }); +} diff --git a/src/components/pages/SpeedDial.vue b/src/components/pages/SpeedDial.vue index 8a06201c..4385acd7 100644 --- a/src/components/pages/SpeedDial.vue +++ b/src/components/pages/SpeedDial.vue @@ -36,7 +36,7 @@ icon="delete" color="negative" slot="right" - @click="deleteAssignment(index)" + @click="unassignSlot(assigned)" /> @@ -56,6 +56,7 @@ import { startLoading, stopLoading, + showToast, showGlobalError } from '../../helpers/ui' import CscPage from '../CscPage' @@ -66,7 +67,8 @@ QItemTile, QItemSide, QChip, - QBtn + QBtn, + Dialog } from 'quasar-framework' export default { @@ -87,12 +89,32 @@ ...mapGetters('speedDial', [ 'assignedSlots', 'speedDialLoadingState', - 'speedDialLoadingError' + 'speedDialLoadingError', + 'unassignSlotState', + 'unassignSlotError', + 'lastUnassignedSlot' ]) }, methods: { - deleteAssignment(index) { - console.log('deleteAssignment(), index', index); + unassignSlot(slot) { + let self = this; + let store = this.$store; + Dialog.create({ + title: self.$t('speedDial.removeDialogTitle'), + message: self.$t('speedDial.removeDialogText', { + slot: slot.slot + }), + buttons: [ + self.$t('buttons.cancel'), + { + label: self.$t('buttons.remove'), + color: 'negative', + handler () { + store.dispatch('speedDial/unassignSpeedDialSlot', slot) + } + } + ] + }); } }, watch: { @@ -107,6 +129,21 @@ else if (state === 'succeeded') { stopLoading(); } + }, + unassignSlotState(state) { + if (state === 'requesting') { + startLoading(); + } + else if (state === 'failed') { + stopLoading(); + showGlobalError(this.unassignSlotError); + } + else if (state === 'succeeded') { + stopLoading(); + showToast(this.$t('speedDial.unassignSlotSuccessMessage', { + slot: this.lastUnassignedSlot + })); + } } } } diff --git a/src/locales/en.json b/src/locales/en.json index b5bcb47b..04a0796f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -368,6 +368,10 @@ "whenIDial": "When I dial {slot} ...", "ring": "ring", "loadSpeedDialErrorMessage": "An error occured while trying to load the speed dials. Please try again.", - "noResultsMessage": "No speed dials found" + "noResultsMessage": "No speed dials found", + "removeDialogTitle": "Remove speed dial", + "removeDialogText": "You are about to remove the speed dial {slot}", + "unassignSlotErrorMessage": "An error occured while trying to unassign the speed dial slot. Please try again.", + "unassignSlotSuccessMessage": "Unassigned slot {slot}" } } diff --git a/src/store/speed-dial.js b/src/store/speed-dial.js index a061c59a..9db97cba 100644 --- a/src/store/speed-dial.js +++ b/src/store/speed-dial.js @@ -3,7 +3,8 @@ import { i18n } from '../i18n'; import { RequestState } from './common' import { - getSpeedDials + getSpeedDials, + unassignSpeedDialSlot } from '../api/speed-dial'; export default { @@ -12,7 +13,10 @@ export default { assignedSlots: [], slotOptions: [], speedDialLoadingState: RequestState.initiated, - speedDialError: null + speedDialError: null, + unassignSlotState: RequestState.initiated, + unassignSlotError: null, + lastUnassignedSlot: null }, getters: { reminderLoadingState(state) { @@ -32,6 +36,15 @@ export default { }, speedDialLoadingError(state) { return state.speedDialLoadingError || i18n.t('speedDial.loadSpeedDialErrorMessage'); + }, + unassignSlotState(state) { + return state.unassignSlotState; + }, + unassignSlotError(state) { + return state.unassignSlotError || i18n.t('speedDial.unassignSlotErrorMessage'); + }, + lastUnassignedSlot(state) { + return state.lastUnassignedSlot; } }, mutations: { @@ -47,6 +60,19 @@ export default { speedDialFailed(state, error) { state.speedDialLoadingState = RequestState.failed; state.speedDialLoadingError = error; + }, + unassignSlotRequesting(state) { + state.unassignSlotState = RequestState.requesting; + state.unassignSlotError = null; + }, + unassignSlotSucceeded(state, last) { + state.lastUnassignedSlot = last; + state.unassignSlotState = RequestState.succeeded; + state.unassignSlotError = null; + }, + unassignSlotFailed(state, error) { + state.unassignSlotState = RequestState.failed; + state.unassignSlotError = error; } }, actions: { @@ -57,6 +83,19 @@ export default { }).catch((error) => { context.commit('speedDialFailed', error); }); + }, + unassignSpeedDialSlot(context, slot) { + context.commit('unassignSlotRequesting'); + unassignSpeedDialSlot({ + slots: context.state.assignedSlots, + slot: slot, + id: context.getters.subscriberId + }).then(() => { + context.commit('unassignSlotSucceeded', slot.slot); + context.dispatch('loadSpeedDials'); + }).catch((error) => { + context.commit('unassignSlotFailed', error); + }); } } };