TT#40256 User wants to remove speed dial config

Change-Id: I18090be6cc718e219a3a9cc145198dd4883d5dba
changes/20/22620/2
raxelsen 7 years ago
parent 6117c5f6fe
commit 6c303ccc55

@ -1,5 +1,6 @@
import _ from 'lodash' import _ from 'lodash'
import Vue from 'vue';
import { getFieldList } from './common' import { getFieldList } from './common'
export function getSpeedDials(id) { 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);
});
});
}

@ -36,7 +36,7 @@
icon="delete" icon="delete"
color="negative" color="negative"
slot="right" slot="right"
@click="deleteAssignment(index)" @click="unassignSlot(assigned)"
/> />
</q-item-tile> </q-item-tile>
</q-item-side> </q-item-side>
@ -56,6 +56,7 @@
import { import {
startLoading, startLoading,
stopLoading, stopLoading,
showToast,
showGlobalError showGlobalError
} from '../../helpers/ui' } from '../../helpers/ui'
import CscPage from '../CscPage' import CscPage from '../CscPage'
@ -66,7 +67,8 @@
QItemTile, QItemTile,
QItemSide, QItemSide,
QChip, QChip,
QBtn QBtn,
Dialog
} from 'quasar-framework' } from 'quasar-framework'
export default { export default {
@ -87,12 +89,32 @@
...mapGetters('speedDial', [ ...mapGetters('speedDial', [
'assignedSlots', 'assignedSlots',
'speedDialLoadingState', 'speedDialLoadingState',
'speedDialLoadingError' 'speedDialLoadingError',
'unassignSlotState',
'unassignSlotError',
'lastUnassignedSlot'
]) ])
}, },
methods: { methods: {
deleteAssignment(index) { unassignSlot(slot) {
console.log('deleteAssignment(), index', index); 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: { watch: {
@ -107,6 +129,21 @@
else if (state === 'succeeded') { else if (state === 'succeeded') {
stopLoading(); 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
}));
}
} }
} }
} }

@ -368,6 +368,10 @@
"whenIDial": "When I dial {slot} ...", "whenIDial": "When I dial {slot} ...",
"ring": "ring", "ring": "ring",
"loadSpeedDialErrorMessage": "An error occured while trying to load the speed dials. Please try again.", "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}"
} }
} }

@ -3,7 +3,8 @@
import { i18n } from '../i18n'; import { i18n } from '../i18n';
import { RequestState } from './common' import { RequestState } from './common'
import { import {
getSpeedDials getSpeedDials,
unassignSpeedDialSlot
} from '../api/speed-dial'; } from '../api/speed-dial';
export default { export default {
@ -12,7 +13,10 @@ export default {
assignedSlots: [], assignedSlots: [],
slotOptions: [], slotOptions: [],
speedDialLoadingState: RequestState.initiated, speedDialLoadingState: RequestState.initiated,
speedDialError: null speedDialError: null,
unassignSlotState: RequestState.initiated,
unassignSlotError: null,
lastUnassignedSlot: null
}, },
getters: { getters: {
reminderLoadingState(state) { reminderLoadingState(state) {
@ -32,6 +36,15 @@ export default {
}, },
speedDialLoadingError(state) { speedDialLoadingError(state) {
return state.speedDialLoadingError || i18n.t('speedDial.loadSpeedDialErrorMessage'); 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: { mutations: {
@ -47,6 +60,19 @@ export default {
speedDialFailed(state, error) { speedDialFailed(state, error) {
state.speedDialLoadingState = RequestState.failed; state.speedDialLoadingState = RequestState.failed;
state.speedDialLoadingError = error; 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: { actions: {
@ -57,6 +83,19 @@ export default {
}).catch((error) => { }).catch((error) => {
context.commit('speedDialFailed', 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);
});
} }
} }
}; };

Loading…
Cancel
Save