From 9567594bd1d03b5a23c68ad2fd1839bd4556070a Mon Sep 17 00:00:00 2001 From: raxelsen Date: Thu, 4 Jan 2018 12:24:27 +0100 Subject: [PATCH] TT#28058 Add New Call Forward Destination What has been done: - TT#29602, CallForwarding: Create UI input form - TT#29603, CallForwarding: Implement API method for add new destination - TT#29604, CallForwarding: Implement store and bindings for add new destination feature Change-Id: I723488e684990c21ee74700cf6e849a5d16cda9c --- src/api/call-forward.js | 116 +++++++++++- src/components/layouts/Default.vue | 5 + .../pages/CallForward/AfterHours.vue | 2 +- src/components/pages/CallForward/Always.vue | 5 +- .../pages/CallForward/CompanyHours.vue | 2 +- .../CallForward/CscAddDestinationForm.vue | 170 ++++++++++++++++++ .../pages/CallForward/CscDestination.vue | 46 +++-- .../pages/CallForward/CscDestinations.vue | 40 ++++- src/filters/index.js | 2 + src/filters/number-format.js | 77 +++++--- src/locales/en.json | 16 +- src/store/call-forward.js | 166 ++++++++++++++++- src/store/user.js | 3 + t/api/call-forward.js | 29 ++- t/store/call-forward.js | 15 ++ t/unit/number-format.js | 68 +++++++ 16 files changed, 701 insertions(+), 61 deletions(-) create mode 100644 src/components/pages/CallForward/CscAddDestinationForm.vue create mode 100644 t/unit/number-format.js diff --git a/src/api/call-forward.js b/src/api/call-forward.js index 6eae6eb6..0bf91d00 100644 --- a/src/api/call-forward.js +++ b/src/api/call-forward.js @@ -1,6 +1,7 @@ +import _ from 'lodash'; import Vue from 'vue'; -import { getJsonBody } from './utils' +import { getJsonBody } from './utils'; let rowCountAssumption = 1000; @@ -87,7 +88,7 @@ export function loadAlwaysEverybodyDestinations(subscriberId) { return new Promise((resolve, reject)=>{ Promise.resolve().then(()=>{ return getMappings(subscriberId); - }).then((mappings)=>{ + }).then((mappings) => { let cfuPromises = []; let cfnaPromises = []; let cfbPromises = []; @@ -118,6 +119,9 @@ export function loadAlwaysEverybodyDestinations(subscriberId) { Promise.all(cfbPromises) ]); }).then((res)=>{ + computeLowestPriorityAndAddGroupName(res[0], 'cfu'); + computeLowestPriorityAndAddGroupName(res[1], 'cfna'); + computeLowestPriorityAndAddGroupName(res[2], 'cfb'); resolve({ online: res[0], offline: res[1], @@ -129,6 +133,15 @@ export function loadAlwaysEverybodyDestinations(subscriberId) { }); } +export function computeLowestPriorityAndAddGroupName(group, groupName) { + group.forEach(destinationset => { + let lowest = _.maxBy(destinationset.destinations, 'priority') || { priority: 1 }; + destinationset.lowestPriority = lowest.priority; + destinationset.groupName = groupName; + }); + return group; +} + export function getDestinationsetById(id) { return new Promise((resolve, reject)=>{ Vue.http.get('/api/cfdestinationsets/' + id).then((res)=>{ @@ -175,3 +188,102 @@ export function deleteDestinationsetById(id) { }); }); } + +export function addDestinationToDestinationset(options) { + let headers = { + 'Content-Type': 'application/json-patch+json' + }; + return new Promise((resolve, reject) => { + Vue.http.patch('/api/cfdestinationsets/' + options.id, [{ + op: 'replace', + path: '/destinations', + value: options.data + }], { headers: headers }).then(result => { + resolve(result); + }).catch(err => { + reject(err); + }); + }); +} + +export function addNewDestinationset() { + let destinationsetName = `csc-${Date.now()}`; + return new Promise((resolve, reject) => { + Vue.http.post('/api/cfdestinationsets/', { name: destinationsetName }) + .then(response => { + resolve(_.last(_.split(response.headers.get('Location'), '/'))); + }).catch(err => { + reject(err); + }); + }); +} + +export function addDestinationToExistingGroup(options) { + return new Promise((resolve, reject)=> { + Promise.resolve().then(() => { + return getDestinationsetById(options.id); + }).then((destinationset) => { + let data = destinationset.destinations; + data.push(options.data); + return addDestinationToDestinationset({ + id: options.id, data: data + }); + }).then(() => { + resolve(); + }).catch((err) => { + reject(err); + }); + }); +} + +export function addDestinationToEmptyGroup(options) { + return new Promise((resolve, reject)=> { + let destinationsetId; + Promise.resolve().then(() => { + return addNewDestinationset(); + }).then((id) => { + destinationsetId = id; + return addDestinationToDestinationset({ + id: id, data: [options.data] + }); + //}).then(() => { + // return getMappings(subscriberId); + //}).then((mappings) => { + // return addNewMapping({ + // destinationsetId: destinationsetId, + // group: options.groupName, + // subscriberId: options.subscriberId, + // mappings: mappings + // }); + }).then(() => { + return addNewMapping({ + destinationsetId: destinationsetId, + group: options.groupName, + subscriberId: options.subscriberId + }); + }).then(() => { + resolve(); + }).catch((err) => { + reject(err); + }); + }); +} + +export function addNewMapping(options) { + let headers = { + 'Content-Type': 'application/json-patch+json' + }; + return new Promise((resolve, reject) => { + let mappingsToSend = [{ destinationset_id: options.destinationsetId, + sourceset_id: null, timeset_id: null }]; + Vue.http.patch('/api/cfmappings/' + options.subscriberId, [{ + op: 'replace', + path: '/' + options.group, + value: mappingsToSend + }], { headers: headers }).then(result => { + resolve(result); + }).catch(err => { + reject(err); + }); + }); +} diff --git a/src/components/layouts/Default.vue b/src/components/layouts/Default.vue index 294e8169..00776146 100644 --- a/src/components/layouts/Default.vue +++ b/src/components/layouts/Default.vue @@ -283,4 +283,9 @@ z-index: 1001; } + .q-if-control.q-if-control-before.q-icon, + .q-if-control.q-if-control-before.q-icon:before { + font-size:24px; + } + diff --git a/src/components/pages/CallForward/AfterHours.vue b/src/components/pages/CallForward/AfterHours.vue index 6d46e694..5b335c2c 100644 --- a/src/components/pages/CallForward/AfterHours.vue +++ b/src/components/pages/CallForward/AfterHours.vue @@ -4,7 +4,7 @@ + + diff --git a/src/components/pages/CallForward/CscDestination.vue b/src/components/pages/CallForward/CscDestination.vue index b304617f..a3620acb 100644 --- a/src/components/pages/CallForward/CscDestination.vue +++ b/src/components/pages/CallForward/CscDestination.vue @@ -1,20 +1,35 @@