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 @@ - + - {{ $t('pages.callForward.firstRing') }} - {{ $t('pages.callForward.thenRing') }} - {{ destination.destination | numberFormat }} + + {{ $t('pages.callForward.firstRing') }} + + + {{ $t('pages.callForward.thenRing') }} + + + {{ destination.destination | destinationFormat }} + - {{ $t('pages.callForward.for') }} - {{ destination.timeout }} - {{ $t('pages.callForward.secs') }} + + {{ $t('pages.callForward.for') }} + + + {{ destination.timeout }} + + + {{ $t('pages.callForward.secs') }} + - {{ $t('buttons.remove') }} + + {{ $t('buttons.remove') }} + @@ -24,12 +39,13 @@ import numberFormat from '../../../filters/number-format' import _ from 'lodash' import { showToast } from '../../../helpers/ui' - import { QItem, QItemSide, Dialog, Toast, QBtn, QItemMain } from 'quasar-framework' + import { QItem, QItemMain, QItemSide, Toast, + Dialog, QBtn } from 'quasar-framework' export default { name: 'csc-destination', props: [ 'destinations', - 'destinationsetId' + 'id' ], components: { QItem, @@ -44,7 +60,11 @@ methods: { isNumber(destination) { let dest = destination.split(/:|@/); - return !isNaN(dest[1]); + if (dest[2] === 'fax2mail.local') { + return false; + } else { + return !isNaN(dest[1]); + }; }, deleteDestination(index) { let clonedDestinations = _.cloneDeep(this.destinations); @@ -66,7 +86,7 @@ color: 'negative', handler () { store.dispatch('callForward/deleteDestinationFromDestinationset', { - id: self.destinationsetId, + id: self.id, data: clonedDestinations, deleteDestinationset: isLastDestination }).then((result) => { store.dispatch('callForward/loadAlwaysEverybodyDestinations'); @@ -88,8 +108,6 @@ diff --git a/src/components/pages/CallForward/CscDestinations.vue b/src/components/pages/CallForward/CscDestinations.vue index c4fdd107..eb3e56d3 100644 --- a/src/components/pages/CallForward/CscDestinations.vue +++ b/src/components/pages/CallForward/CscDestinations.vue @@ -1,5 +1,5 @@ - + {{ title }} @@ -14,38 +14,62 @@ - + - + + +