TT#86201 CF: Further requests optimisation

√ 1 - mapping, destinationset, sourceset and timeset GET endopints should be called in parallel (instead of synchronously) when possible
√ 2 - mapping, destinationset, sourceset and timeset PATCH and PUT endpoints should be called with header "return=representation" instead of "return=minimal" to allow consistency between local and persisted data without having to refetch the data every time a change is made

Change-Id: Idec6281c8fd560383e983107e78b48f5094f4dcc
pull/2/head
Carlo Venusino 5 years ago
parent 0646d1c303
commit 9c624967da

@ -4,7 +4,7 @@ import Vue from 'vue';
import { i18n } from '../i18n'; import { i18n } from '../i18n';
import { getJsonBody } from './utils'; import { getJsonBody } from './utils';
import { normalizeDestination } from '../filters/number-format'; import { normalizeDestination } from '../filters/number-format';
import { LIST_ALL_ROWS } from './common'; import { LIST_ALL_ROWS, patchReplaceFull } from './common';
export function getMappings(id) { export function getMappings(id) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
@ -297,34 +297,19 @@ export function deleteDestinationsetById(id) {
} }
export function updateDestinationsetName(options) { export function updateDestinationsetName(options) {
return new Promise((resolve, reject) => { return patchReplaceFull({
let headers = { 'Content-Type': 'application/json-patch+json' }; path: 'api/cfdestinationsets/' + options.id,
Vue.http.patch('api/cfdestinationsets/' + options.id, [{ fieldPath: 'name',
op: 'replace', value: options.name
path: '/name',
value: options.name
}], { headers: headers }).then((result) => {
resolve(result);
}).catch((err) => {
reject(err);
});
}); });
} }
export function addDestinationToDestinationset(options) { export function addDestinationToDestinationset(options) {
let headers = {
'Content-Type': 'application/json-patch+json' return patchReplaceFull({
}; path: 'api/cfdestinationsets/' + options.id,
return new Promise((resolve, reject) => { fieldPath: 'destinations',
Vue.http.patch('api/cfdestinationsets/' + options.id, [{ value: options.data
op: 'replace',
path: '/destinations',
value: options.data
}], { headers: headers }).then((result) => {
resolve(result);
}).catch((err) => {
reject(err);
});
}); });
} }
@ -402,14 +387,22 @@ export function addDestinationToEmptyGroup(options) {
} }
export function addNewMapping(options) { export function addNewMapping(options) {
return patchReplaceFull({
path: 'api/cfmappings/' + options.subscriberId,
fieldPath: options.group,
value: options.mappings
});
}
export function addMultipleNewMappings(options) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
let headers = { 'Content-Type': 'application/json-patch+json' }; let headers = {
Vue.http.patch('api/cfmappings/' + options.subscriberId, [{ 'Content-Type': 'application/json-patch+json',
op: 'replace', 'Prefer': 'return=representation'
path: '/' + options.group, };
value: options.mappings Vue.http.patch('api/cfmappings/' + options.subscriberId, options.mappings
}], { headers: headers }).then((result) => { , { headers: headers }).then((result) => {
resolve(result); resolve(getJsonBody(result.body));
}).catch((err) => { }).catch((err) => {
reject(err); reject(err);
}); });
@ -678,19 +671,10 @@ export function resetTimesetByName(options) {
} }
export function addTimeToTimeset(options) { export function addTimeToTimeset(options) {
return new Promise((resolve, reject) => { return patchReplaceFull({
let headers = { path: 'api/cftimesets/' + options.id,
'Content-Type': 'application/json-patch+json' fieldPath: 'times',
}; value: options.times
Vue.http.patch('api/cftimesets/' + options.id, [{
op: 'replace',
path: '/times',
value: options.times
}], { headers: headers }).then(() => {
resolve();
}).catch((err) => {
reject(err);
});
}); });
} }
@ -976,18 +960,9 @@ export function getOwnPhoneTimeout(id) {
} }
export function updateOwnPhoneTimeout(options) { export function updateOwnPhoneTimeout(options) {
return new Promise((resolve, reject)=>{ return patchReplaceFull({
let headers = { path: 'api/cfmappings/' + options.subscriberId,
'Content-Type': 'application/json-patch+json' fieldPath: 'cft_ringtimeout',
}; value: options.timeout
Vue.http.patch('api/cfmappings/' + options.subscriberId, [{
op: 'replace',
path: '/cft_ringtimeout',
value: options.timeout
}], { headers: headers }).then(() => {
resolve();
}).catch((err) => {
reject(err);
});
}); });
} }

@ -310,8 +310,8 @@
const isGroupEnabled = await this.$store.dispatch('newCallForward/isGroupEnabled', {groupName: this.group.name, id: this.group.id}); const isGroupEnabled = await this.$store.dispatch('newCallForward/isGroupEnabled', {groupName: this.group.name, id: this.group.id});
this.isEnabled = isGroupEnabled; this.isEnabled = isGroupEnabled;
} }
await this.updateSourcesetNames(); this.updateSourcesetNames();
await this.updateTimeSetNames(); this.updateTimeSetNames();
} }
catch(err){ catch(err){
console.log(err) console.log(err)
@ -391,7 +391,7 @@
}, },
set(value) { set(value) {
if(value !== ""){ if(value !== ""){
this.addTimeset(value); this.addTimeToExistingTimeset(value);
} }
else{ else{
this.showConfirmDeleteTimesetDialog() this.showConfirmDeleteTimesetDialog()
@ -432,10 +432,10 @@
this.$refs.numberForm.open(); this.$refs.numberForm.open();
break; break;
case 'voicemail': case 'voicemail':
await this.$store.dispatch('newCallForward/addGroupLoader', this.group.id); this.$store.dispatch('newCallForward/addGroupLoader', this.group.id);
await this.$store.dispatch('newCallForward/addVoiceMail', this.group.id); await this.$store.dispatch('newCallForward/addVoiceMail', this.group.id);
await this.$store.dispatch('newCallForward/loadForwardGroups'); this.$store.dispatch('newCallForward/loadForwardGroups');
await this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id); this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
break; break;
} }
}, },
@ -482,13 +482,13 @@
return destination; return destination;
}, },
async toggleGroupChange(){ async toggleGroupChange(){
await this.$store.dispatch('newCallForward/addGroupLoader', this.group.id); this.$store.dispatch('newCallForward/addGroupLoader', this.group.id);
await this.$store.dispatch('newCallForward/enableGroup', { await this.$store.dispatch('newCallForward/enableGroup', {
groupName: this.group.name, groupName: this.group.name,
id: this.group.id, id: this.group.id,
enabled: this.isEnabled enabled: this.isEnabled
}); });
await this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id); this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
}, },
showConditions(){ showConditions(){
this.$refs.addCondition.add(); this.$refs.addCondition.add();
@ -547,10 +547,10 @@
}, },
async confirmDeleteGroup(){ async confirmDeleteGroup(){
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.group.id); this.$store.dispatch('newCallForward/addGroupLoader', this.group.id);
await this.$store.dispatch('newCallForward/deleteForwardGroup', this.group); await this.$store.dispatch('newCallForward/deleteForwardGroup', this.group);
await this.$store.dispatch('newCallForward/loadForwardGroups'); this.$store.dispatch('newCallForward/loadForwardGroups');
await this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id); this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
} }
catch(e){ catch(e){
console.log(e) console.log(e)
@ -565,31 +565,31 @@
}, },
async deleteTimeset(){ async deleteTimeset(){
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.group.id); this.$store.dispatch('newCallForward/addGroupLoader', this.group.id);
await this.$store.dispatch('newCallForward/deleteTimesFromTimeset', this.timeSet.id); await this.$store.dispatch('newCallForward/deleteTimesFromTimeset', this.timeSet.id);
await this.$store.dispatch('newCallForward/loadTimesets'); await this.$store.dispatch('newCallForward/loadTimesets');
await this.$store.dispatch('newCallForward/loadMappings'); this.$store.dispatch('newCallForward/loadMappings');
await this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id); this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
} }
catch(e){ catch(e){
console.log(e) console.log(e)
} }
}, },
async addTimeset(time){ async addTimeToExistingTimeset(time){
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.group.id); this.$store.dispatch('newCallForward/addGroupLoader', this.group.id);
this.day = { this.day = {
"year": date.formatDate(time, 'YYYY'), "year": date.formatDate(time, 'YYYY'),
"month": date.formatDate(time, 'M'), "month": date.formatDate(time, 'M'),
"mday": date.formatDate(time, 'D') "mday": date.formatDate(time, 'D')
} }
await this.$store.dispatch('newCallForward/addTimeToTimeset', {
const updatedTimeset = await this.$store.dispatch('newCallForward/addTimeToTimeset', {
id: this.timeSet.id, id: this.timeSet.id,
time: this.day time: this.day
}); });
await this.$store.dispatch('newCallForward/loadTimesets'); this.$store.dispatch('newCallForward/editTimes', updatedTimeset);
await this.$store.dispatch('newCallForward/loadMappings'); this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
await this.$store.dispatch('newCallForward/removeGroupLoader', this.group.id);
} }
catch(e){ catch(e){
console.log(e) console.log(e)

@ -144,18 +144,13 @@
}, },
async mounted(){ async mounted(){
this.groupsLoading = true; this.groupsLoading = true;
try{ this.$store.dispatch('newCallForward/loadMappings');
await this.$store.dispatch('newCallForward/loadMappings'); // here we need to wait for the groups to be available in client
await this.$store.dispatch('newCallForward/loadSourcesets'); await this.$store.dispatch('newCallForward/loadForwardGroups');
await this.$store.dispatch('newCallForward/loadTimesets'); const unconditionalGroups = await this.$store.dispatch('newCallForward/getForwardGroupByName', 'unconditional');
await this.$store.dispatch('newCallForward/loadForwardGroups'); this.toggleDefaultNumber = !unconditionalGroups;
let unconditionalGroups = await this.$store.dispatch('newCallForward/getForwardGroupByName', 'unconditional'); this.$store.dispatch('newCallForward/loadSourcesets');
this.toggleDefaultNumber = !unconditionalGroups; this.$store.dispatch('newCallForward/loadTimesets');
}
catch(err){
console.log(err)
}
this.groupsLoading = false; this.groupsLoading = false;
}, },
@ -186,13 +181,13 @@
if(this.toggleDefaultNumber){ if(this.toggleDefaultNumber){
const tempTimeoutFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-timeout'); const tempTimeoutFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-timeout');
if(!tempTimeoutFwdGroup){ if(!tempTimeoutFwdGroup){
await this.$store.dispatch('newCallForward/addTempGroup','timeout' ); this.$store.dispatch('newCallForward/addTempGroup','timeout' );
} }
} }
else{ else{
const tempUnconditionalFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-unconditional'); const tempUnconditionalFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-unconditional');
if(!tempUnconditionalFwdGroup){ if(!tempUnconditionalFwdGroup){
await this.$store.dispatch('newCallForward/addTempGroup','unconditional' ); this.$store.dispatch('newCallForward/addTempGroup','unconditional' );
} }
} }
} }
@ -201,23 +196,23 @@
if(this.toggleDefaultNumber){ if(this.toggleDefaultNumber){
const tempTimeoutFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-timeout-from'); const tempTimeoutFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-timeout-from');
if(!tempTimeoutFwdGroup){ if(!tempTimeoutFwdGroup){
await this.$store.dispatch('newCallForward/addTempGroup','timeoutFrom' ); this.$store.dispatch('newCallForward/addTempGroup','timeoutFrom' );
} }
} }
else{ else{
const tempUnconditionalFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-unconditional-from'); const tempUnconditionalFwdGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', 'temp-csc-unconditional-from');
if(!tempUnconditionalFwdGroup){ if(!tempUnconditionalFwdGroup){
await this.$store.dispatch('newCallForward/addTempGroup','unconditionalFrom' ); this.$store.dispatch('newCallForward/addTempGroup','unconditionalFrom' );
} }
} }
} }
break; break;
case "offline":{ case "offline":{
await this.$store.dispatch('newCallForward/addTempGroup','offline' ); this.$store.dispatch('newCallForward/addTempGroup','offline' );
} }
break; break;
case "busy":{ case "busy":{
await this.$store.dispatch('newCallForward/addTempGroup','busy' ); this.$store.dispatch('newCallForward/addTempGroup','busy' );
} }
break; break;
} }
@ -228,13 +223,13 @@
this.$refs.destinationType.close(); this.$refs.destinationType.close();
this.$refs.addDestinationForm.add(); this.$refs.addDestinationForm.add();
}, },
async toggleChange(){ toggleChange(){
this.groupInCreation = true; this.groupInCreation = true;
await this.$store.dispatch('newCallForward/forwardAllCalls', !this.toggleDefaultNumber); this.$store.dispatch('newCallForward/forwardAllCalls', !this.toggleDefaultNumber);
this.groupInCreation = false; this.groupInCreation = false;
}, },
async resetSelectFwdGroup(){ resetSelectFwdGroup(){
await this.$store.dispatch('newCallForward/setSelectedDestType', null); this.$store.dispatch('newCallForward/setSelectedDestType', null);
} }
} }
} }

@ -102,7 +102,7 @@
const forwardGroupId = this.groupId; const forwardGroupId = this.groupId;
const forwardGroupName = this.groupName; const forwardGroupName = this.groupName;
const forwardGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', forwardGroupId); const forwardGroup = await this.$store.dispatch('newCallForward/getForwardGroupById', forwardGroupId);
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
if (this.numberError || this.saveDisabled) { if (this.numberError || this.saveDisabled) {
showGlobalError(this.$t('validationErrors.generic')); showGlobalError(this.$t('validationErrors.generic'));
} }
@ -113,7 +113,7 @@
destination: this.number destination: this.number
}); });
} }
else { // new group else {
if(forwardGroup.id.toString().includes('temp-')){ // unexisting group if(forwardGroup.id.toString().includes('temp-')){ // unexisting group
forwardGroup.destinations[0].simple_destination = this.number; // optimistic UI update :) forwardGroup.destinations[0].simple_destination = this.number; // optimistic UI update :)
const newGroupId = await this.$store.dispatch('newCallForward/addForwardGroup', { const newGroupId = await this.$store.dispatch('newCallForward/addForwardGroup', {
@ -126,18 +126,17 @@
if(this.destinationIndex === 0 && this.firstDestinationInCreation){ if(this.destinationIndex === 0 && this.firstDestinationInCreation){
await this.$store.dispatch('newCallForward/setFirstDestinationInCreation', newGroupId); await this.$store.dispatch('newCallForward/setFirstDestinationInCreation', newGroupId);
} }
} }
else{ // existing group else{ // existing group
await this.$store.dispatch('newCallForward/addDestination', { await this.$store.dispatch('newCallForward/addDestination', {
forwardGroupId: forwardGroup.id, forwardGroupId: forwardGroup.id,
destination: this.number destination: this.number
}); });
await this.$store.dispatch('newCallForward/loadForwardGroups');
} }
await this.$store.dispatch('newCallForward/loadForwardGroups');
} }
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
}, },
cancel() { cancel() {
this.number = ''; this.number = '';

@ -114,7 +114,7 @@
return; return;
} }
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', forwardGroupId); this.$store.dispatch('newCallForward/addGroupLoader', forwardGroupId);
sourceSetId = await this.$store.dispatch('newCallForward/createSourceSet', { sourceSetId = await this.$store.dispatch('newCallForward/createSourceSet', {
name: this.name, name: this.name,
source: this.number source: this.number
@ -124,10 +124,8 @@
id: forwardGroupId, id: forwardGroupId,
sourceSetId: sourceSetId sourceSetId: sourceSetId
}); });
await this.$store.dispatch('newCallForward/loadSourcesets'); this.$store.dispatch('newCallForward/loadSourcesets');
await this.$store.dispatch('newCallForward/loadMappings'); this.$store.dispatch('newCallForward/removeGroupLoader', forwardGroupId);
await this.$store.dispatch('newCallForward/loadForwardGroups');
await this.$store.dispatch('newCallForward/removeGroupLoader', forwardGroupId);
} }
catch(err){ catch(err){

@ -76,25 +76,24 @@
}, },
async set(value) { async set(value) {
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
const timeSetId = await this.$store.dispatch('newCallForward/createTimeSet', this.timesetName); const timeSetId = await this.$store.dispatch('newCallForward/createTimeSet', this.timesetName);
await this.$store.dispatch('newCallForward/addTimesetToGroup', {
name: this.groupName,
groupId: this.groupId,
timeSetId: timeSetId
});
this.day = { this.day = {
"year": date.formatDate(value, 'YYYY'), "year": date.formatDate(value, 'YYYY'),
"month": date.formatDate(value, 'M'), "month": date.formatDate(value, 'M'),
"mday": date.formatDate(value, 'D') "mday": date.formatDate(value, 'D')
} }
this.$store.dispatch('newCallForward/addTimesetToGroup', {
name: this.groupName,
groupId: this.groupId,
timeSetId: timeSetId
});
await this.$store.dispatch('newCallForward/addTimeToTimeset', { await this.$store.dispatch('newCallForward/addTimeToTimeset', {
id: timeSetId, id: timeSetId,
time: this.day time: this.day
}); });
await this.$store.dispatch('newCallForward/loadMappings');
await this.$store.dispatch('newCallForward/loadTimesets'); await this.$store.dispatch('newCallForward/loadTimesets');
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
} }
catch(err){ catch(err){

@ -184,7 +184,7 @@
this.$refs.numberForm.open(); this.$refs.numberForm.open();
break; break;
case 'voicemail': case 'voicemail':
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
if(this.groupId.toString().includes('temp-')){ // unexisting group if(this.groupId.toString().includes('temp-')){ // unexisting group
const newGroupId = await this.$store.dispatch('newCallForward/addForwardGroup', { const newGroupId = await this.$store.dispatch('newCallForward/addForwardGroup', {
name: this.groupName, name: this.groupName,
@ -202,7 +202,7 @@
else{ else{
await this.$store.dispatch('newCallForward/addVoiceMail', this.groupId); await this.$store.dispatch('newCallForward/addVoiceMail', this.groupId);
} }
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
this.popoverToTop = false; this.popoverToTop = false;
this.popoverTimeoutToTop = false; this.popoverTimeoutToTop = false;
break; break;
@ -219,13 +219,13 @@
this.$refs.selectDestinationType.add(); this.$refs.selectDestinationType.add();
}, },
async saveTimeout(){ async saveTimeout(){
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
await this.$store.dispatch('newCallForward/editTimeout', { await this.$store.dispatch('newCallForward/editTimeout', {
index: this.destinationIndex, index: this.destinationIndex,
timeout: this.destinationTimeout, timeout: this.destinationTimeout,
forwardGroupId: this.groupId forwardGroupId: this.groupId
}); });
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
}, },
showConfirmDialog(){ showConfirmDialog(){
@ -233,12 +233,12 @@
}, },
async confirmDeleteDest(){ async confirmDeleteDest(){
this.removeInProgress = true; this.removeInProgress = true;
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
await this.$store.dispatch('newCallForward/removeDestination', { await this.$store.dispatch('newCallForward/removeDestination', {
destination: this.destination, destination: this.destination,
forwardGroupId: this.groupId forwardGroupId: this.groupId
}); });
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
}, },
isVoiceMail(){ isVoiceMail(){
return this.destination.destination.includes('voicebox.local') return this.destination.destination.includes('voicebox.local')

@ -179,7 +179,7 @@
source: this.number source: this.number
}); });
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
this.$refs.sourceInputField.reset(); this.$refs.sourceInputField.reset();
await this.$store.dispatch('newCallForward/addSourceToSourceset', { await this.$store.dispatch('newCallForward/addSourceToSourceset', {
id: this.sourceSetId, id: this.sourceSetId,
@ -192,7 +192,7 @@
console.log(err) console.log(err)
} }
finally { finally {
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
} }
}, },
showRemoveDialog(){ showRemoveDialog(){
@ -200,12 +200,11 @@
this.toggleFormVisibility = true; this.toggleFormVisibility = true;
}, },
async confirmDeleteSourceset(){ async confirmDeleteSourceset(){
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
await this.$store.dispatch('newCallForward/deleteSourcesetById', this.sourceSetId); await this.$store.dispatch('newCallForward/deleteSourcesetById', this.sourceSetId);
await this.$store.dispatch('newCallForward/loadMappings'); this.$store.dispatch('newCallForward/loadMappings');
await this.$store.dispatch('newCallForward/loadSourcesets'); this.$store.dispatch('newCallForward/loadSourcesets');
await this.$store.dispatch('newCallForward/loadForwardGroups'); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
this.restorePopver(); this.restorePopver();
}, },
restorePopver(){ restorePopver(){

@ -78,7 +78,7 @@
let sources = this.getSourcesesBySourcesetId(this.sourceSetId); let sources = this.getSourcesesBySourcesetId(this.sourceSetId);
sources = sources.filter($source=> $source.source !== this.source); sources = sources.filter($source=> $source.source !== this.source);
try{ try{
await this.$store.dispatch('newCallForward/addGroupLoader', this.groupId); this.$store.dispatch('newCallForward/addGroupLoader', this.groupId);
await this.$store.dispatch('newCallForward/removeSourceFromSourceset', { await this.$store.dispatch('newCallForward/removeSourceFromSourceset', {
id: this.sourceSetId, id: this.sourceSetId,
sources: sources sources: sources
@ -89,7 +89,7 @@
console.log(err) console.log(err)
} }
finally{ finally{
await this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId); this.$store.dispatch('newCallForward/removeGroupLoader', this.groupId);
} }
this.removeInProgress = false; this.removeInProgress = false;
} }

@ -1,4 +1,5 @@
'use strict'; 'use strict';
import _ from 'lodash';
import Vue from 'vue' import Vue from 'vue'
import { import {
getMappings, getMappings,
@ -7,6 +8,7 @@ import {
deleteDestinationsetById, deleteDestinationsetById,
addDestinationToDestinationset, addDestinationToDestinationset,
addNewMapping, addNewMapping,
addMultipleNewMappings,
updateOwnPhoneTimeout, updateOwnPhoneTimeout,
updateDestinationsetName, updateDestinationsetName,
createSourcesetWithSource, createSourcesetWithSource,
@ -165,9 +167,6 @@ export default {
destination.timeout = data.timeout; destination.timeout = data.timeout;
Vue.set(group.destinations, data.index-1, destination) Vue.set(group.destinations, data.index-1, destination)
}, },
loadMappings(state, mappings){
state.mappings = mappings;
},
loadForwardGroups(state, forwardGroups){ loadForwardGroups(state, forwardGroups){
for (let i = 0; i < forwardGroups.length; i++) { for (let i = 0; i < forwardGroups.length; i++) {
const group = forwardGroups[i]; const group = forwardGroups[i];
@ -178,6 +177,21 @@ export default {
} }
state.forwardGroups = forwardGroups; state.forwardGroups = forwardGroups;
}, },
setDestinationSet(state, data){
let forwardGroup = state.forwardGroups.find((group)=>{
return group.id === data.id;
});
Object.assign(forwardGroup, data);
},
setDestinations(state, data){
let group = state.forwardGroups.find((group)=>{
return group.id === data.groupId;
});
group.destinations = data.destinations;
},
setMappings(state, mappings){
state.mappings = mappings;
},
setSelectedDestType(state, destType){ setSelectedDestType(state, destType){
state.selectedDestType = destType; state.selectedDestType = destType;
}, },
@ -187,6 +201,12 @@ export default {
setTimeSets(state, timeSets){ setTimeSets(state, timeSets){
state.timeSets = timeSets; state.timeSets = timeSets;
}, },
editTimes(state, timeSet){
let timeSetToUpdate = state.timeSets.find(($timeset)=>{
return $timeset.id === timeSet.id;
});
timeSetToUpdate.times = timeSet.times;
},
addGroupLoader(state, groupId){ addGroupLoader(state, groupId){
state.groupsLoaders.push(groupId) state.groupsLoaders.push(groupId)
}, },
@ -195,6 +215,10 @@ export default {
}, },
setFirstDestinationInCreation(state, groupId){ setFirstDestinationInCreation(state, groupId){
state.firstDestinationInCreation = groupId; state.firstDestinationInCreation = groupId;
},
setOwnPhoneTimeout(state, cft_ringtimeout){
const mappings = state.mappings;
mappings.cft_ringtimeout = cft_ringtimeout
} }
}, },
actions: { actions: {
@ -211,7 +235,7 @@ export default {
async loadMappings(context) { async loadMappings(context) {
try{ try{
const mappings = await getMappings(localStorage.getItem('subscriberId')); const mappings = await getMappings(localStorage.getItem('subscriberId'));
context.commit('loadMappings', mappings); context.commit('setMappings', mappings);
} }
catch(err){ catch(err){
console.log(err) console.log(err)
@ -236,7 +260,6 @@ export default {
if(data.replaceMapping){ if(data.replaceMapping){
for(let mapping of groupMappings){ for(let mapping of groupMappings){
if(mapping.destinationset_id === data.groupId){ if(mapping.destinationset_id === data.groupId){
mapping.sourceset_id = data.sourceSetId || null; mapping.sourceset_id = data.sourceSetId || null;
mapping.timeset_id = data.timeSetId || null; mapping.timeset_id = data.timeSetId || null;
break; break;
@ -250,12 +273,12 @@ export default {
"timeset_id": data.timeSetId || null "timeset_id": data.timeSetId || null
}); });
} }
await addNewMapping({ const updatedMappings = await addNewMapping({
mappings: groupMappings, mappings: groupMappings,
group: groupMappingId, group: groupMappingId,
subscriberId: subscriberId subscriberId: subscriberId
}); });
context.dispatch('loadMappings'); context.commit('setMappings', updatedMappings);
} }
catch(err){ catch(err){
console.log(err) console.log(err)
@ -273,12 +296,12 @@ export default {
"priority": 1, "priority": 1,
"timeout": 5 "timeout": 5
}; };
await context.dispatch('editMapping', { context.dispatch('editMapping', {
name: data.name, name: data.name,
groupId: newForwardGroupId groupId: newForwardGroupId
}); });
await addDestinationToDestinationset({ addDestinationToDestinationset({
id: newForwardGroupId, id: newForwardGroupId,
data: [destination] data: [destination]
}); });
@ -286,7 +309,7 @@ export default {
// setting cft_ringtimeout in case it is // setting cft_ringtimeout in case it is
// not set while creating timeout group // not set while creating timeout group
if((data.name === 'timeout' || data.name === 'csc-timeout') && (!context.getters.getOwnPhoneTimeout || isNaN(context.getters.getOwnPhoneTimeout))){ if((data.name === 'timeout' || data.name === 'csc-timeout') && (!context.getters.getOwnPhoneTimeout || isNaN(context.getters.getOwnPhoneTimeout))){
await context.dispatch('editRingTimeout', 5); context.dispatch('editRingTimeout', 5);
} }
return newForwardGroupId; return newForwardGroupId;
@ -297,14 +320,7 @@ export default {
}, },
async deleteForwardGroup(context, group) { async deleteForwardGroup(context, group) {
try{ try{
const subscriberId = localStorage.getItem('subscriberId');
const groupMappingId = await context.dispatch('getMappingIdByGroupName', group.name);
await deleteDestinationsetById(group.id); await deleteDestinationsetById(group.id);
await addNewMapping({
mappings: [],
group: groupMappingId,
subscriberId: subscriberId
});
context.dispatch('loadMappings'); context.dispatch('loadMappings');
} }
catch(err){ catch(err){
@ -405,22 +421,24 @@ export default {
let destinations, group = context.state.forwardGroups.find((group)=>{ let destinations, group = context.state.forwardGroups.find((group)=>{
return group.id === data.forwardGroupId; return group.id === data.forwardGroupId;
}); });
destinations = group.destinations.filter(($destination) => { destinations = group.destinations.filter(($destination) => {
return $destination.destination !== data.destination.destination; return $destination.destination !== data.destination.destination;
}); });
if(destinations.length < 1){ if(destinations.length < 1){
await context.dispatch('deleteForwardGroup', group); await context.dispatch('deleteForwardGroup', group);
context.dispatch('loadForwardGroups');
} }
else{ else{
await addDestinationToDestinationset({ const updatedGroup = await addDestinationToDestinationset({
id: group.id, id: group.id,
data: destinations data: destinations
}); });
await context.dispatch('loadMappings'); context.commit('setDestinations', {
groupId: updatedGroup.id,
destinations: updatedGroup.destinations
});
} }
await context.dispatch('loadForwardGroups');
} }
catch(err){ catch(err){
@ -428,17 +446,22 @@ export default {
} }
}, },
async editDestination(context, data){ async editDestination(context, data){
let group = context.state.forwardGroups.find((group)=>{ const group = context.state.forwardGroups.find((group)=>{
return group.id === data.forwardGroupId; return group.id === data.forwardGroupId;
}); });
let destination = group.destinations.slice(data.index, data.index+1)[0]; const groupClone = _.cloneDeep(group);
let destination = groupClone.destinations.slice(data.index, data.index+1)[0];
destination.simple_destination = data.destination; destination.simple_destination = data.destination;
destination.destination = data.destination; destination.destination = data.destination;
context.commit('editDestination', data);
try{ try{
await addDestinationToDestinationset({ const result = await addDestinationToDestinationset({
id: data.forwardGroupId, id: data.forwardGroupId,
data: group.destinations data: groupClone.destinations
});
context.commit('setDestinations', {
groupId: data.forwardGroupId,
destinations: result.destinations
}); });
} }
catch(err){ catch(err){
@ -447,11 +470,11 @@ export default {
}, },
async editRingTimeout(context, timeout){ async editRingTimeout(context, timeout){
try{ try{
await updateOwnPhoneTimeout({ const data = await updateOwnPhoneTimeout({
subscriberId: localStorage.getItem('subscriberId'), subscriberId: localStorage.getItem('subscriberId'),
timeout: timeout timeout: timeout
}); });
await context.dispatch('loadMappings'); context.commit('setOwnPhoneTimeout', data.cft_ringtimeout)
} }
catch(err){ catch(err){
console.log(err) console.log(err)
@ -459,6 +482,7 @@ export default {
}, },
async editTimeout(context, data){ async editTimeout(context, data){
try{ try{
if(data.index === 0){ // first row -> change cft_ringtimeout if(data.index === 0){ // first row -> change cft_ringtimeout
await context.dispatch('editRingTimeout', data.timeout); await context.dispatch('editRingTimeout', data.timeout);
} }
@ -466,13 +490,17 @@ export default {
const group = context.state.forwardGroups.find((group)=>{ const group = context.state.forwardGroups.find((group)=>{
return group.id === data.forwardGroupId; return group.id === data.forwardGroupId;
}); });
let destination = group.destinations.slice(data.index-1, data.index)[0]; const groupClone = _.cloneDeep(group);
let destination = groupClone.destinations.slice(data.index-1, data.index)[0];
destination.timeout = data.timeout; destination.timeout = data.timeout;
await addDestinationToDestinationset({ const result = await addDestinationToDestinationset({
id: group.id, id: groupClone.id,
data: group.destinations data: groupClone.destinations
});
context.commit('setDestinations', {
groupId: group.id,
destinations: result.destinations
}); });
context.commit('editTimeout', data);
} }
} }
catch(err){ catch(err){
@ -487,63 +515,68 @@ export default {
let timeoutGroups = await context.dispatch('getForwardGroupByName', 'timeout'); let timeoutGroups = await context.dispatch('getForwardGroupByName', 'timeout');
if(noSelfNumber && timeoutGroups){ if(noSelfNumber && timeoutGroups){
for(let timeoutGroup of timeoutGroups){ // TODO multiple logic for(let timeoutGroup of timeoutGroups){
if(timeoutGroup && !timeoutGroup.id.toString().includes('temp')){ if(timeoutGroup && !timeoutGroup.id.toString().includes('temp')){
context.dispatch('addGroupLoader', timeoutGroup.id);
await updateDestinationsetName({ const updatedDestinationset = await updateDestinationsetName({
id: timeoutGroup.id, id: timeoutGroup.id,
name: 'csc-unconditional' name: 'csc-unconditional'
}); });
context.commit('setDestinationSet', updatedDestinationset);
await addNewMapping({ context.dispatch('removeGroupLoader', timeoutGroup.id);
mappings: [],
group: 'cft',
subscriberId: subscriberId
});
await addNewMapping({
mappings: mappings['cft'],
group: 'cfu',
subscriberId: subscriberId
});
} }
else { else {
await context.dispatch('addTempGroup', 'unconditional'); context.dispatch('addTempGroup', 'unconditional');
} }
await context.dispatch('loadMappings');
await context.dispatch('loadForwardGroups');
} }
const updatedMappings = await addMultipleNewMappings({
subscriberId: subscriberId,
mappings: [
{
op: 'replace',
value: [],
path: '/cft'
},
{
op: 'replace',
value: mappings['cft'],
path: '/cfu'
}
]
});
context.commit('setMappings', updatedMappings);
} }
else{ else{
if(unconditionalGroups ){ if(unconditionalGroups ){
for(let unconditionalGroup of unconditionalGroups){ // TODO multiple logic for(let unconditionalGroup of unconditionalGroups){
if(!unconditionalGroup.id.toString().includes('temp')){ if(!unconditionalGroup.id.toString().includes('temp')){
context.dispatch('addGroupLoader', unconditionalGroup.id);
await updateDestinationsetName({ const updatedDestinationset = await updateDestinationsetName({
id: unconditionalGroup.id, id: unconditionalGroup.id,
name: 'csc-timeout' name: 'csc-timeout'
}); });
context.commit('setDestinationSet', updatedDestinationset);
await addNewMapping({ context.dispatch('removeGroupLoader', unconditionalGroup.id);
mappings: [],
group: 'cfu',
subscriberId: subscriberId
});
await addNewMapping({
mappings: mappings['cfu'],
group: 'cft',
subscriberId: subscriberId
});
} }
else{ else{
await context.dispatch('addTempGroup', 'timeout'); context.dispatch('addTempGroup', 'timeout');
} }
await context.dispatch('loadMappings');
await context.dispatch('loadForwardGroups');
} }
const updatedMappings = await addMultipleNewMappings({
subscriberId: subscriberId,
mappings: [{
op: 'replace',
value: [],
path: '/cfu'
},
{
op: 'replace',
value: mappings['cfu'],
path: '/cft'
}]
});
context.commit('setMappings', updatedMappings);
} }
} }
} }
@ -584,12 +617,12 @@ export default {
group.enabled = data.enabled; group.enabled = data.enabled;
} }
} }
await addNewMapping({ const updatedMappings = await addNewMapping({
mappings: groupMappings, mappings: groupMappings,
group: mappingId, group: mappingId,
subscriberId: subscriberId subscriberId: subscriberId
}); });
context.dispatch('loadMappings'); context.commit('setMappings', updatedMappings);
} }
} }
@ -610,6 +643,9 @@ export default {
const timeSets = await getTimesets(subscriberId); const timeSets = await getTimesets(subscriberId);
context.commit('setTimeSets', timeSets); context.commit('setTimeSets', timeSets);
}, },
editTimes(context, timeSet){
context.commit('editTimes', timeSet);
},
async createSourceSet(context, data){ async createSourceSet(context, data){
const sourceSetId = await createSourcesetWithSource({ const sourceSetId = await createSourcesetWithSource({
sourcesetName: data.name, sourcesetName: data.name,
@ -677,10 +713,11 @@ export default {
}, },
async addTimeToTimeset(context, data){ async addTimeToTimeset(context, data){
try{ try{
await addTimeToTimeset({ const timeset = await addTimeToTimeset({
id: data.id, id: data.id,
times: [data.time] times: [data.time]
}); });
return timeset;
} }
catch(err){ catch(err){
console.log(err) console.log(err)

Loading…
Cancel
Save