diff --git a/src/api/call-forwarding.js b/src/api/call-forwarding.js index 75aa0306..3b41fa10 100644 --- a/src/api/call-forwarding.js +++ b/src/api/call-forwarding.js @@ -28,14 +28,16 @@ export async function cfLoadDestinationSets (subscriberId) { export async function cfLoadSourceSets (subscriberId) { return getList({ resource: 'cfsourcesets', - params: (subscriberId) ? { subscriber_id: subscriberId } : {} + params: (subscriberId) ? { subscriber_id: subscriberId } : {}, + all: true }) } export async function cfLoadTimeSets (subscriberId) { return getList({ resource: 'cftimesets', - params: (subscriberId) ? { subscriber_id: subscriberId } : {} + params: (subscriberId) ? { subscriber_id: subscriberId } : {}, + all: true }) } diff --git a/src/components/call-forwarding/CscCfConditionPopupCustom.vue b/src/components/call-forwarding/CscCfConditionPopupCustom.vue new file mode 100644 index 00000000..71e4d956 --- /dev/null +++ b/src/components/call-forwarding/CscCfConditionPopupCustom.vue @@ -0,0 +1,33 @@ + + + diff --git a/src/components/call-forwarding/CscCfGroupConditionCustom.vue b/src/components/call-forwarding/CscCfGroupConditionCustom.vue new file mode 100644 index 00000000..eb24731e --- /dev/null +++ b/src/components/call-forwarding/CscCfGroupConditionCustom.vue @@ -0,0 +1,50 @@ + + + diff --git a/src/components/call-forwarding/CscCfGroupConditionDate.vue b/src/components/call-forwarding/CscCfGroupConditionDate.vue index 773c4033..27115108 100644 --- a/src/components/call-forwarding/CscCfGroupConditionDate.vue +++ b/src/components/call-forwarding/CscCfGroupConditionDate.vue @@ -23,7 +23,7 @@ flat color="negative" icon="delete" - @click="deleteSourceSetEvent" + @click="deleteTimeSetEvent" /> { this.$wait.start(this.waitIdentifier) if (this.destinationSet.destinations.length > 1) { - await this.removeDestination(payload) + await this.triggerRemoveDestination(payload) this.setAnnouncement() } else { this.$emit('delete-last', payload) @@ -271,6 +271,13 @@ export default { this.$wait.end(this.waitIdentifier) }) }, + async triggerRemoveDestination (payload) { + try { + await this.removeDestination(payload) + } catch (e) { + showGlobalError(e.message) + } + }, async updateDestinationTimeoutEvent (payload) { this.$wait.start(this.waitIdentifier) await this.updateDestinationTimeout(payload) diff --git a/src/components/call-forwarding/CscCfGroupTitle.vue b/src/components/call-forwarding/CscCfGroupTitle.vue index 34ae2907..2afbf303 100644 --- a/src/components/call-forwarding/CscCfGroupTitle.vue +++ b/src/components/call-forwarding/CscCfGroupTitle.vue @@ -144,7 +144,6 @@ > {{ $t('office hours are') }} - - {{ $filters.timeSetTimes(timeSet.times) }} - + @@ -400,6 +404,13 @@ export default { } }, watch: { + async $route (to) { + if (this.id !== to.params.id) { + this.id = to.params.id + this.selectGroup(this.id) + await this.loadMappingsFull(this.id) + } + }, groupSelected () { this.changes = this.getGroupData() this.soundSet = this.getSoundSetByGroupId(this.groupSelected.id) @@ -412,9 +423,9 @@ export default { } } }, - mounted () { + async mounted () { this.selectGroup(this.id) - this.loadMappingsFull(this.id) + await this.loadMappingsFull(this.id) }, beforeUnmount () { this.resetSelectedGroup() diff --git a/src/pages/CscPagePbxSeatDetails.vue b/src/pages/CscPagePbxSeatDetails.vue index ccb44ae4..8c254fdd 100644 --- a/src/pages/CscPagePbxSeatDetails.vue +++ b/src/pages/CscPagePbxSeatDetails.vue @@ -347,18 +347,22 @@ @@ -469,6 +473,7 @@ export default { 'getIntraPbx', 'getSeatUpdateToastMessage', 'isSeatLoading', + 'isSeatMapByIdEmpty', 'getAnnouncementCfu', 'getAnnouncementCallSetup', 'getAnnouncementToCallee', @@ -578,6 +583,12 @@ export default { } }, watch: { + async $route (to) { + if (this.id !== to.params.id) { + this.id = to.params.id + this.selectSeat(this.id) + } + }, seatSelected () { this.soundSet = this.getSoundSetBySeatId(this.seatSelected.id) this.loadPreferences(this.seatSelected.id).then((preferences) => { @@ -625,7 +636,11 @@ export default { } }, async mounted () { - this.selectSeat(this.id) + if (this.isSeatMapByIdEmpty) { + await this.loadSeatListItems() + } + + this.selectSeat(this.$route.params.id) await this.loadAnnouncements() await this.getNcosSetSubscriber() }, @@ -642,6 +657,7 @@ export default { 'setIntraPbx', 'setMusicOnHold', 'setSeatSoundSet', + 'loadSeatListItems', 'loadPreferences', 'setCli', 'setNcosSet', diff --git a/src/store/call-forwarding/actions.js b/src/store/call-forwarding/actions.js index 2777373a..558b5bc2 100644 --- a/src/store/call-forwarding/actions.js +++ b/src/store/call-forwarding/actions.js @@ -18,12 +18,15 @@ import { cfUpdateTimeSetWeekdays } from 'src/api/call-forwarding' import { - get, getList, + get, + getList, patchReplace, patchReplaceFull, - post, put + post, + put } from 'src/api/common' -import { showGlobalError } from 'src/helpers/ui' +import { i18n } from 'src/boot/i18n' +import { showGlobalError, showGlobalWarning } from 'src/helpers/ui' import { v4 } from 'uuid' const DEFAULT_RING_TIMEOUT = 60 @@ -42,19 +45,16 @@ function createDefaultDestination (destination, defaultAnnouncementId) { return payload } -export async function loadMappingsFull ({ dispatch, commit, rootGetters }, subscriberId) { +export async function loadMappingsFull ({ dispatch, commit, rootGetters }, id) { dispatch('wait/start', WAIT_IDENTIFIER, { root: true }) - let res = null - if (subscriberId) { - res = await cfLoadMappingsFull(subscriberId) - } else { - res = await cfLoadMappingsFull(rootGetters['user/getSubscriberId']) - } + const subscriberId = id || rootGetters['user/getSubscriberId'] + const mappingData = await cfLoadMappingsFull(subscriberId) + commit('dataSucceeded', { - mappings: res[0], - destinationSets: res[1].items, - sourceSets: res[2].items, - timeSets: res[3].items + mappings: mappingData[0], + destinationSets: mappingData[1].items, + sourceSets: mappingData[2].items, + timeSets: mappingData[3].items }) dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) } @@ -66,7 +66,7 @@ export async function createMapping ({ dispatch, commit, state, rootGetters }, p if (payload.type === 'cfu' && state.mappings.cft && state.mappings.cft.length > 0) { type = 'cft' } - const subscriberId = (payload.subscriberId) ? (payload.subscriberId) : rootGetters['user/getSubscriberId'] + const subscriberId = payload.subscriberId ? payload.subscriberId : rootGetters['user/getSubscriberId'] const mappings = _.cloneDeep(state.mappings[type]) const destinationSet = await post({ resource: 'cfdestinationsets', @@ -76,21 +76,22 @@ export async function createMapping ({ dispatch, commit, state, rootGetters }, p destinations: [createDefaultDestination()] } }) + mappings.push({ - destinationset_id: destinationSet?.id + destinationset_id: destinationSet.id }) - const res = await Promise.all([ - patchReplaceFull({ - resource: 'cfmappings', - resourceId: subscriberId, - fieldPath: type, - value: mappings - }), - cfLoadDestinationSets(rootGetters['user/getSubscriberId']) - ]) + + const patchedMappings = await patchReplaceFull({ + resource: 'cfmappings', + resourceId: subscriberId, + fieldPath: type, + value: mappings + }) + const latestDestinationSets = await cfLoadDestinationSets() + commit('dataSucceeded', { - mappings: res[0], - destinationSets: res[1].items + mappings: patchedMappings, + destinationSets: latestDestinationSets.items }) } catch (error) { showGlobalError(error.message) @@ -114,7 +115,19 @@ export async function deleteMapping ({ dispatch, commit, state, rootGetters }, p fieldPath: payload.type, value: updatedMappings }) - await cfDeleteDestinationSet(payload.destinationset_id) + + try { + await cfDeleteDestinationSet(payload.destinationset_id) + } catch (e) { + if (e.code === 404 && e.message === 'Entity \'cfdestinationset\' not found.') { + // This happens when CF was set by Admin therefore current + // csc user doesn't have rights to delete the entity + showGlobalWarning(i18n.global.tc('Entity belongs to admin')) + } else { + showGlobalError(e.message) + } + } + const destinationSets = await cfLoadDestinationSets() commit('dataSucceeded', { mappings: patchRes, @@ -139,8 +152,8 @@ export async function toggleMapping ({ dispatch, commit, state, rootGetters }, p dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) } -export async function updateDestination ({ dispatch, commit, state, rootGetters }, payload) { - dispatch('wait/start', WAIT_IDENTIFIER, { root: true }) +export async function updateDestination ({ dispatch, commit, state }, payload) { + dispatch('wait/start', 'csc-cf-destination-set-update', { root: true }) const destinations = _.cloneDeep(state.destinationSetMap[payload.destinationSetId].destinations) destinations[payload.destinationIndex].destination = payload.destination await patchReplace({ @@ -153,7 +166,7 @@ export async function updateDestination ({ dispatch, commit, state, rootGetters commit('dataSucceeded', { destinationSets: destinationSets.items }) - dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) + dispatch('wait/end', 'csc-cf-destination-set-update', { root: true }) } export async function addDestination ({ dispatch, commit, state, rootGetters }, payload) { @@ -189,8 +202,8 @@ export async function rewriteDestination ({ dispatch, commit, state, rootGetters } } -export async function removeDestination ({ dispatch, commit, state, rootGetters }, payload) { - dispatch('wait/start', WAIT_IDENTIFIER, { root: true }) +export async function removeDestination ({ dispatch, commit, state }, payload) { + dispatch('wait/start', 'csc-cf-destination-set-remove', { root: true }) const destinations = _.cloneDeep(state.destinationSetMap[payload.destinationSetId].destinations) const updatedDestinations = destinations.reduce(($updatedDestinations, value, index) => { if (index !== payload.destinationIndex) { @@ -208,19 +221,23 @@ export async function removeDestination ({ dispatch, commit, state, rootGetters commit('dataSucceeded', { destinationSets: destinationSets.items }) - dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) + dispatch('wait/end', 'csc-cf-destination-set-remove', { root: true }) } -export async function updateDestinationTimeout ({ dispatch, commit, state, rootGetters }, payload) { +export async function updateDestinationTimeout ({ dispatch, commit, state }, payload) { dispatch('wait/start', WAIT_IDENTIFIER, { root: true }) const destinations = _.cloneDeep(state.destinationSetMap[payload.destinationSetId].destinations) destinations[payload.destinationIndex].timeout = payload.destinationTimeout - await patchReplace({ - resource: 'cfdestinationsets', - resourceId: payload.destinationSetId, - fieldPath: 'destinations', - value: destinations - }) + try { + await patchReplace({ + resource: 'cfdestinationsets', + resourceId: payload.destinationSetId, + fieldPath: 'destinations', + value: destinations + }) + } catch (e) { + showGlobalError(e.message) + } const destinationSets = await cfLoadDestinationSets() commit('dataSucceeded', { destinationSets: destinationSets.items @@ -228,7 +245,7 @@ export async function updateDestinationTimeout ({ dispatch, commit, state, rootG dispatch('wait/end', WAIT_IDENTIFIER, { root: true }) } -export async function loadSourceSets ({ dispatch, commit, rootGetters }) { +export async function loadSourceSets ({ dispatch, commit }) { dispatch('wait/start', 'csc-cf-sourcesets', { root: true }) const sourceSets = await cfLoadSourceSets() commit('dataSucceeded', { @@ -259,7 +276,7 @@ export async function createSourceSet ({ dispatch, commit, rootGetters, state }, } } -export async function updateSourceSet ({ dispatch, commit, rootGetters, state }, payload) { +export async function updateSourceSet ({ dispatch, commit, rootGetters }, payload) { try { dispatch('wait/start', 'csc-cf-source-set-create', { root: true }) await cfUpdateSourceSet(rootGetters['user/getSubscriberId'], payload) @@ -267,6 +284,14 @@ export async function updateSourceSet ({ dispatch, commit, rootGetters, state }, commit('dataSucceeded', { sourceSets: sourceSets.items }) + } catch (e) { + if (e.code === 404 && e.message === 'Entity \'sourceset\' not found.') { + // This happens when CF was set by Admin therefore current + // csc user doesn't have rights to delete the entity + showGlobalWarning(i18n.global.tc('Entity belongs to admin')) + } else { + showGlobalError(e.message) + } } finally { dispatch('wait/end', 'csc-cf-source-set-create', { root: true }) } @@ -290,6 +315,8 @@ export async function deleteSourceSet ({ dispatch, commit, rootGetters, state }, mappings: updatedMappings, sourceSets: sourceSets.items }) + } catch (e) { + showGlobalError(e.message) } finally { dispatch('wait/end', 'csc-cf-source-set-create', { root: true }) } @@ -353,14 +380,19 @@ export async function createTimeSetDate ({ dispatch, commit, rootGetters, state dispatch('wait/end', 'csc-cf-time-set-create', { root: true }) } -export async function updateTimeSetDate ({ dispatch, commit, rootGetters, state }, payload) { +export async function updateTimeSetDate ({ dispatch, commit }, payload) { dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) - await cfUpdateTimeSetDate(payload.id, payload.date) - const timeSets = await cfLoadTimeSets() - commit('dataSucceeded', { - timeSets: timeSets.items - }) - dispatch('wait/end', 'csc-cf-time-set-create', { root: true }) + try { + await cfUpdateTimeSetDate(payload.id, payload.date) + const timeSets = await cfLoadTimeSets() + commit('dataSucceeded', { + timeSets: timeSets.items + }) + } catch (e) { + showGlobalError(e.message) + } finally { + dispatch('wait/end', 'csc-cf-time-set-create', { root: true }) + } } export async function deleteTimeSet ({ dispatch, commit, rootGetters, state }, payload) { @@ -374,7 +406,17 @@ export async function deleteTimeSet ({ dispatch, commit, rootGetters, state }, p fieldPath: payload.mapping.type, value: updatedMapping }) - await cfDeleteTimeSet(payload.id) + try { + await cfDeleteTimeSet(payload.id) + } catch (e) { + if (e.code === 404 && e.message === 'Entity \'cftimeset\' not found.') { + // This happens when CF was set by Admin therefore current + // csc user doesn't have rights to delete the entity + showGlobalWarning(i18n.global.tc('Entity belongs to admin')) + } else { + showGlobalError(e.message) + } + } const timeSets = await cfLoadTimeSets() commit('dataSucceeded', { mappings: updatedMappings, @@ -414,6 +456,8 @@ export async function doNotRingPrimaryNumber ({ commit, rootGetters, state }, pa } export async function updateRingTimeout ({ commit, rootGetters, state }, payload) { + // eslint-disable-next-line no-console + console.debug('aaa') const updatedMappings = await patchReplaceFull({ resource: 'cfmappings', resourceId: (payload.subscriberId) ? payload.subscriberId : rootGetters['user/getSubscriberId'], @@ -444,9 +488,20 @@ export async function createTimeSetDateRange ({ dispatch, commit, rootGetters, s dispatch('wait/end', 'csc-cf-time-set-create', { root: true }) } -export async function updateTimeSetDateRange ({ dispatch, commit, rootGetters, state }, payload) { +export async function updateTimeSetDateRange ({ dispatch, commit }, payload) { dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) - await cfUpdateTimeSetDateRange(payload.id, payload.date) + try { + await cfUpdateTimeSetDateRange(payload.id, payload.date) + } catch (e) { + if (e.code === 404 && e.message === 'Entity \'timeset\' not found.') { + // This happens when CF was set by Admin therefore current + // csc user doesn't have rights to delete the entity + showGlobalWarning(i18n.global.tc('Entity belongs to admin')) + } else { + showGlobalError(e.message) + } + } + const timeSets = await cfLoadTimeSets() commit('dataSucceeded', { timeSets: timeSets.items @@ -473,9 +528,20 @@ export async function createTimeSetWeekdays ({ dispatch, commit, rootGetters, st dispatch('wait/end', 'csc-cf-time-set-create', { root: true }) } -export async function updateTimeSetWeekdays ({ dispatch, commit, rootGetters, state }, payload) { +export async function updateTimeSetWeekdays ({ dispatch, commit }, payload) { dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) - await cfUpdateTimeSetWeekdays(payload.id, payload.weekdays) + try { + await cfUpdateTimeSetWeekdays(payload.id, payload.weekdays) + } catch (e) { + if (e.code === 404 && e.message === 'Entity \'timeset\' not found.') { + // This happens when CF was set by Admin therefore current + // csc user doesn't have rights to delete the entity + showGlobalWarning(i18n.global.tc('Entity belongs to admin')) + } else { + showGlobalError(e.message) + } + } + const timeSets = await cfLoadTimeSets() commit('dataSucceeded', { timeSets: timeSets.items @@ -497,7 +563,7 @@ export async function createOfficeHours ({ dispatch, commit, rootGetters, state if (payload.id) { await cfDeleteTimeSet(payload.id) } - const timeSets = await cfLoadTimeSets(rootGetters['user/getSubscriberId']) + const timeSets = await cfLoadTimeSets() commit('dataSucceeded', { mappings: updatedMappings, timeSets: timeSets.items @@ -507,8 +573,13 @@ export async function createOfficeHours ({ dispatch, commit, rootGetters, state export async function updateOfficeHours ({ dispatch, commit, rootGetters, state }, payload) { dispatch('wait/start', 'csc-cf-time-set-create', { root: true }) - await cfUpdateOfficeHours(payload.id, payload.times) - const timeSets = await cfLoadTimeSets(rootGetters['user/getSubscriberId']) + try { + await cfUpdateOfficeHours(payload.id, payload.times) + } catch (e) { + showGlobalError(e.message) + } + + const timeSets = await cfLoadTimeSets() commit('dataSucceeded', { timeSets: timeSets.items }) @@ -543,15 +614,20 @@ export async function getAnnouncementById ({ dispatch, commit, rootGetters, stat } } -export async function updateAnnouncement ({ dispatch, commit, rootGetters, state }, payload) { - const destinations = _.cloneDeep(state.destinationSetMap[payload.destinationSetId].destinations) - destinations[payload.destinationIndex].announcement_id = payload.announcementId - await patchReplace({ - resource: 'cfdestinationsets', - resourceId: payload.destinationSetId, - fieldPath: 'destinations', - value: destinations - }) +export async function updateAnnouncement ({ dispatch, commit, state }, payload) { + try { + const destinations = _.cloneDeep(state.destinationSetMap[payload.destinationSetId].destinations) + destinations[payload.destinationIndex].announcement_id = payload.announcementId + await patchReplace({ + resource: 'cfdestinationsets', + resourceId: payload.destinationSetId, + fieldPath: 'destinations', + value: destinations + }) + } catch (e) { + showGlobalError(e.message) + } + const destinationSets = await cfLoadDestinationSets() commit('dataSucceeded', { destinationSets: destinationSets.items diff --git a/src/store/call-forwarding/mutations.js b/src/store/call-forwarding/mutations.js index 374261e2..3e33d22a 100644 --- a/src/store/call-forwarding/mutations.js +++ b/src/store/call-forwarding/mutations.js @@ -5,6 +5,7 @@ export function dataSucceeded (state, res) { destinationSetMap[destinationSet.id] = destinationSet }) state.destinationSetMap = destinationSetMap + state.destinationSets = res.destinationSets } if (res.sourceSets) { const sourceSetMap = {} diff --git a/src/store/pbx-seats.js b/src/store/pbx-seats.js index ee435283..9b0276cf 100644 --- a/src/store/pbx-seats.js +++ b/src/store/pbx-seats.js @@ -58,6 +58,9 @@ export default { isSeatListEmpty (state) { return state.seatListItems.length && state.seatListItems.length === 0 }, + isSeatMapByIdEmpty (state) { + return Object.keys(state.seatMapById).length === 0 + }, isSeatListRequesting (state) { return state.seatListState === RequestState.requesting },