diff --git a/src/api/call-forward.js b/src/api/call-forward.js index 5f75b5a6..6b5be070 100644 --- a/src/api/call-forward.js +++ b/src/api/call-forward.js @@ -88,7 +88,13 @@ export function getDestinationsets(id) { return Promise.resolve(result); } }).then((result) => { - resolve(getJsonBody(result.body)._embedded['ngcp:cfdestinationsets']); + if(getJsonBody(result.body)._embedded){ + resolve(getJsonBody(result.body)._embedded['ngcp:cfdestinationsets']); + } + else{ + resolve([]); + } + }).catch((err) => { reject(err); }); diff --git a/src/components/pages/NewCallForward/CscCallForwardGroup.vue b/src/components/pages/NewCallForward/CscCallForwardGroup.vue index 3f1b4171..c9f98811 100644 --- a/src/components/pages/NewCallForward/CscCallForwardGroup.vue +++ b/src/components/pages/NewCallForward/CscCallForwardGroup.vue @@ -1,25 +1,33 @@ diff --git a/src/components/pages/NewCallForward/CscNewCallForwardAddDestinationForm.vue b/src/components/pages/NewCallForward/CscNewCallForwardAddDestinationForm.vue index af8f9e94..4d6d5b9d 100644 --- a/src/components/pages/NewCallForward/CscNewCallForwardAddDestinationForm.vue +++ b/src/components/pages/NewCallForward/CscNewCallForwardAddDestinationForm.vue @@ -78,6 +78,7 @@ 'index', 'disable', 'loading', + 'groupName' ], validations: { number: { @@ -96,7 +97,7 @@ }, methods: { async save() { - const forwardGroupName = 'unconditional'; // gonna be dynamic + const forwardGroupName = this.groupName; const forwardGroup = await this.$store.dispatch('newCallForward/getForwardGroupByName', forwardGroupName); if (this.numberError || this.saveDisabled) { diff --git a/src/components/pages/NewCallForward/CscNewCallForwardDestination.vue b/src/components/pages/NewCallForward/CscNewCallForwardDestination.vue index 6d2897fc..085aab49 100644 --- a/src/components/pages/NewCallForward/CscNewCallForwardDestination.vue +++ b/src/components/pages/NewCallForward/CscNewCallForwardDestination.vue @@ -4,8 +4,11 @@ :class="removed" >
- {{ $t('pages.newCallForward.destinationTimeoutLabel') }} - + {{ this.allCallsFwd ? '' : $t('pages.newCallForward.destinationTimeoutLabel') }} + {{this.destinationTimeout}} - {{ $t('pages.newCallForward.destinationNumberLabel') }} + {{ this.allCallsFwd ? $t('pages.newCallForward.allCallsForwardedTo') : $t('pages.newCallForward.destinationNumberLabel') }}
@@ -32,19 +35,33 @@ {{ !this.destinationNumber || this.destinationNumber.length < 2 ? $t('pages.newCallForward.destinationLabel') : this.destinationNumber}} + + +
+
+ + + diff --git a/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue b/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue new file mode 100644 index 00000000..5b981c9c --- /dev/null +++ b/src/components/pages/NewCallForward/CscNewCallForwardDestinationsetTypeSelect.vue @@ -0,0 +1,53 @@ + + + + + diff --git a/src/locales/en.json b/src/locales/en.json index 306ce5d2..48e42543 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -212,7 +212,7 @@ }, "newCallForward": { "primarNumberEnabled": "All calls go to the primary number", - "primarNumberDisabled": "No call goes to", + "primarNumberDisabled": "No call goes to primary number", "forwardBtnLabel": "Add forwarding", "numberLabel": "Number", "voiceMailLabel": "Voicemail", @@ -222,7 +222,8 @@ "addDestinationLabel": "Add destination", "allCallsForwardedTo": "All calls forwarded to", "cancelDialogTitle": "Delete from {groupName} forwarding", - "cancelDialogText": "You are about to delete {destination} from {groupName} call forwarding" + "cancelDialogText": "You are about to delete {destination} from {groupName} call forwarding", + "uncoditionalLabel": "Unconditional" }, "callForward": { "titles": { diff --git a/src/store/new-call-forward.js b/src/store/new-call-forward.js index 1ae572f7..2fc8bb7b 100644 --- a/src/store/new-call-forward.js +++ b/src/store/new-call-forward.js @@ -1,49 +1,36 @@ 'use strict'; import Vue from 'vue' - -// import _ from 'lodash'; -// import { RequestState } from './common' -// import { i18n } from '../i18n'; - import { - // getSourcesets, + getMappings, getDestinationsets, addNewDestinationsetWithName, - // deleteDestinationFromDestinationset, + deleteDestinationsetById, addDestinationToDestinationset, - // addDestinationToEmptyGroup, - // addDestinationToExistingGroup, - // changePositionOfDestination, - // moveDestinationUp, - // moveDestinationDown, - // loadTimesetTimes, - // deleteTimeFromTimeset, - // deleteTimesetById, - // resetTimesetByName, - // createTimesetWithTime, - // appendTimeToTimeset, - // loadDestinations, - // createSourcesetWithSource, - // appendSourceToSourceset, - // deleteSourcesetById, - // deleteSourceFromSourcesetByIndex, - // flipCfuAndCft, - // getOwnPhoneTimeout, - // updateOwnPhoneTimeout + addNewMapping, + updateOwnPhoneTimeout } from '../api/call-forward'; const ForwardGroup = { - unconditional: 'unconditional' + unconditional: { + name : 'csc-unconditional', + mapping: 'cfu' + }, + timeout: { + name: 'csc-timeout', + mapping: 'cft' + } }; export default { namespaced: true, state: { - forwardGroups: [] + mappings: [], + forwardGroups: [], + showSwitcher: true }, getters: { primaryNumber(state, getters, rootState, rootGetters) { - let subscriber = rootGetters['user/getSubscriber']; + const subscriber = rootGetters['user/getSubscriber']; if(subscriber !== null) { return subscriber.primary_number; @@ -55,11 +42,14 @@ export default { subscriberDisplayName(state, getters, rootState, rootGetters) { return rootGetters['user/getUsername']; }, - // destinations(state) { - // return state.destinations; - // }, forwardGroups(state){ return state.forwardGroups; + }, + getOwnPhoneTimeout(state){ + return parseInt(state.mappings.cft_ringtimeout); + }, + showSwitcher(state){ + return state.showSwitcher; } }, mutations: { @@ -82,48 +72,127 @@ export default { let group = state.forwardGroups.find((group)=>{ return group.id === data.forwardGroupId; }); - let destination = group.destinations.slice(data.index, data.index+1)[0]; + let destination = group.destinations.slice(data.index-1, data.index)[0]; destination.timeout = data.timeout; - Vue.set(group.destinations, data.index, destination) + Vue.set(group.destinations, data.index-1, destination) + }, + loadMappings(state, mappings){ + state.mappings = mappings; }, loadForwardGroups(state, forwardGroups){ state.forwardGroups = forwardGroups; }, + setShowSwitcher(state){ + const forwardGroups = state.forwardGroups; + const timeoutGroup = forwardGroups.find(($forwardGroup) => { + return $forwardGroup.name === 'csc-timeout'; + }); + const unconditionalGroup = forwardGroups.find(($forwardGroup) => { + return $forwardGroup.name === 'csc-unconditional'; + }); + state.showSwitcher = (timeoutGroup && timeoutGroup.destinations.length > 0) || (unconditionalGroup && unconditionalGroup.destinations.length > 0); + } }, actions: { + async loadMappings(context) { + try{ + const mappings = await getMappings(localStorage.getItem('subscriberId')); + context.commit('loadMappings', mappings); + } + catch(err){ + console.log(err) + } + }, async loadForwardGroups(context) { try{ const forwardGroups = await getDestinationsets(localStorage.getItem('subscriberId')); context.commit('loadForwardGroups', forwardGroups); + context.commit('setShowSwitcher'); + return forwardGroups; + } + catch(err){ + console.log(err) + } + }, + async editMapping(context, data){ + try{ + const subscriberId = localStorage.getItem('subscriberId'); + const groupMappingId = ForwardGroup[data.name].mapping; + const allMappings = await getMappings(subscriberId); + let groupMappings = allMappings[groupMappingId]; + + groupMappings.push({ + "destinationset_id": data.groupId, + "sourceset_id":null, + "timeset_id":null + }); + + await addNewMapping({ + mappings: groupMappings, + group: groupMappingId, + subscriberId: subscriberId + }); + + context.dispatch('loadMappings'); } catch(err){ console.log(err) } + }, async addForwardGroup(context, name) { try{ + const newForwardGroupId = await addNewDestinationsetWithName(ForwardGroup[name].name); const destination = { "announcement_id": null, "simple_destination": " ", "destination": " ", "priority": 1, - "timeout": 20 + "timeout": 5 }; - const newForwardGroupId = await addNewDestinationsetWithName(ForwardGroup[name]); + + await context.dispatch('editMapping', { + name: name, + groupId: newForwardGroupId + }); + await addDestinationToDestinationset({ id: newForwardGroupId, data: [destination] }); + + // setting cft_ringtimeout in case it is + // not set while creating timeout group + if(name === 'timeout' && !context.getters.getOwnPhoneTimeout){ + await context.dispatch('editRingTimeout', 5); + } + return newForwardGroupId; } catch(err){ console.log(err) } }, + async deleteForwardGroup(context, group) { + try{ + const subscriberId = localStorage.getItem('subscriberId'); + const groupMappingId = group.name === 'csc-unconditional' ? 'cfu' : 'cft'; + await deleteDestinationsetById(group.id); + await addNewMapping({ + mappings: [], + group: groupMappingId, + subscriberId: subscriberId + }); + context.dispatch('loadMappings'); + } + catch(err){ + console.log(err) + } + }, getForwardGroupByName(context, name){ let forwardGroups = context.getters.forwardGroups; forwardGroups = forwardGroups.filter(($forwardGroup) => { - return $forwardGroup.name === name; + return ForwardGroup[name] ? $forwardGroup.name === ForwardGroup[name].name : $forwardGroup.name === name; }); return forwardGroups.length > 0 ? forwardGroups[0] : null; }, @@ -137,7 +206,7 @@ export default { "simple_destination": data.destination, "destination": data.destination, "priority": 1, - "timeout": 20 + "timeout": 5 }; await addDestinationToDestinationset({ id: data.forwardGroupId, @@ -148,20 +217,37 @@ export default { console.log(err); } }, - async removeDestination(context, data){ + async replaceDestinations(context, data){ try{ - let group = context.state.forwardGroups.find((group)=>{ + return group.name === ForwardGroup[data.groupName].name; + }); + await addDestinationToDestinationset({ + id: group.id, + data: data.destinations + }); + } + catch(err){ + console.log(err); + } + }, + async removeDestination(context, data){ + try{ + let destinations, group = context.state.forwardGroups.find((group)=>{ return group.id === data.forwardGroupId; }); - - group.destinations = group.destinations.filter(($destination) => { + destinations = group.destinations.filter(($destination) => { return $destination.destination !== data.destination.destination; }); await addDestinationToDestinationset({ id: group.id, - data: group.destinations + data: destinations }); + if(destinations.length < 1){ + context.dispatch('deleteForwardGroup', group); + context.dispatch('loadForwardGroups', group); + context.dispatch('loadMappings', group); + } } catch(err){ console.log(err); @@ -175,22 +261,91 @@ export default { destination.simple_destination = data.destination; destination.destination = data.destination; context.commit('editDestination', data); - await addDestinationToDestinationset({ - id: data.forwardGroupId, - data: group.destinations - }); + try{ + await addDestinationToDestinationset({ + id: data.forwardGroupId, + data: group.destinations + }); + } + catch(err){ + console.log(err) + } + }, + async editRingTimeout(context, timeout){ + try{ + await updateOwnPhoneTimeout({ + subscriberId: localStorage.getItem('subscriberId'), + timeout: timeout + }); + await context.dispatch('loadMappings'); + } + catch(err){ + console.log(err) + } }, async editTimeout(context, data){ - let group = context.state.forwardGroups.find((group)=>{ - return group.id === data.forwardGroupId; - }); - let destination = group.destinations.slice(data.index, data.index+1)[0]; - destination.timeout = data.timeout; - context.commit('editTimeout', data); - await addDestinationToDestinationset({ - id: group.id, - data: group.destinations - }); + if(data.index === 0){ // first row -> change cft_ringtimeout + context.dispatch('editRingTimeout', data.timeout); + } + else{ + const group = context.state.forwardGroups.find((group)=>{ + return group.id === data.forwardGroupId; + }); + let destination = group.destinations.slice(data.index-1, data.index)[0]; + destination.timeout = data.timeout; + context.commit('editTimeout', data); + try{ + await addDestinationToDestinationset({ + id: group.id, + data: group.destinations + }); + } + catch(err){ + console.log(err) + } + } + + }, + async forwardAllCalls(context, noSelfNumber){ + try{ + let unconditionalGroup = await context.dispatch('getForwardGroupByName', 'unconditional') + let timeoutGroup = await context.dispatch('getForwardGroupByName', 'timeout'); + + if(!unconditionalGroup){ + await context.dispatch('addForwardGroup', 'unconditional'); + await context.dispatch('loadMappings'); + await context.dispatch('loadForwardGroups'); + unconditionalGroup = await context.dispatch('getForwardGroupByName', 'unconditional'); + } + if(!timeoutGroup){ + await context.dispatch('addForwardGroup', 'timeout'); + await context.dispatch('loadMappings'); + await context.dispatch('loadForwardGroups'); + timeoutGroup = await context.dispatch('getForwardGroupByName', 'timeout'); + } + + if(noSelfNumber){ + await context.dispatch('replaceDestinations', { + groupName: 'unconditional', + destinations: timeoutGroup.destinations + }); + await context.dispatch('deleteForwardGroup', timeoutGroup); + } + else{ + await context.dispatch('replaceDestinations', { + groupName: 'timeout', + destinations: unconditionalGroup.destinations + }); + await context.dispatch('deleteForwardGroup', unconditionalGroup); + + + } + await context.dispatch('loadMappings'); + await context.dispatch('loadForwardGroups'); + } + catch(err){ + console.log(err) + } } } };