@ -12,6 +12,7 @@ export function getMappings(id) {
let jsonBody = getJsonBody ( result . body ) ;
let jsonBody = getJsonBody ( result . body ) ;
delete jsonBody . _links ;
delete jsonBody . _links ;
delete jsonBody . cfs ;
delete jsonBody . cfs ;
delete jsonBody . cfr ;
resolve ( getJsonBody ( result . body ) ) ;
resolve ( getJsonBody ( result . body ) ) ;
} ) . catch ( ( err ) => {
} ) . catch ( ( err ) => {
reject ( err ) ;
reject ( err ) ;
@ -131,15 +132,25 @@ export function loadDestinations(options) {
export function getDestinationsBySourcesetId ( options ) {
export function getDestinationsBySourcesetId ( options ) {
return new Promise ( ( resolve , reject ) => {
return new Promise ( ( resolve , reject ) => {
let cftTimeset = null ;
let cfuTimeset = null ;
let cfuTimeset = null ;
let cfnaTimeset = null ;
let cfnaTimeset = null ;
let cfbTimeset = null ;
let cfbTimeset = null ;
Promise . resolve ( ) . then ( ( ) => {
Promise . resolve ( ) . then ( ( ) => {
return getMappings ( options . subscriberId ) ;
return getMappings ( options . subscriberId ) ;
} ) . then ( ( mappings ) => {
} ) . then ( ( mappings ) => {
let cftPromises = [ ] ;
let cfuPromises = [ ] ;
let cfuPromises = [ ] ;
let cfnaPromises = [ ] ;
let cfnaPromises = [ ] ;
let cfbPromises = [ ] ;
let cfbPromises = [ ] ;
if ( _ . has ( mappings , 'cft' ) && _ . isArray ( mappings . cft ) && mappings . cft . length > 0 ) {
mappings . cft . forEach ( ( cftMapping ) => {
if ( cftMapping . timeset === options . timeset && cftMapping . sourceset _id === options . sourceset _id ) {
cftTimeset = cftMapping . timeset _id ;
cftPromises . push ( getDestinationsetById ( cftMapping . destinationset _id ) ) ;
}
} ) ;
}
if ( _ . has ( mappings , 'cfu' ) && _ . isArray ( mappings . cfu ) && mappings . cfu . length > 0 ) {
if ( _ . has ( mappings , 'cfu' ) && _ . isArray ( mappings . cfu ) && mappings . cfu . length > 0 ) {
mappings . cfu . forEach ( ( cfuMapping ) => {
mappings . cfu . forEach ( ( cfuMapping ) => {
if ( cfuMapping . timeset === options . timeset && cfuMapping . sourceset _id === options . sourceset _id ) {
if ( cfuMapping . timeset === options . timeset && cfuMapping . sourceset _id === options . sourceset _id ) {
@ -165,22 +176,27 @@ export function getDestinationsBySourcesetId(options) {
} ) ;
} ) ;
}
}
return Promise . all ( [
return Promise . all ( [
Promise . all ( cftPromises ) ,
Promise . all ( cfuPromises ) ,
Promise . all ( cfuPromises ) ,
Promise . all ( cfnaPromises ) ,
Promise . all ( cfnaPromises ) ,
Promise . all ( cfbPromises )
Promise . all ( cfbPromises )
] ) ;
] ) ;
} ) . then ( ( result ) => {
} ) . then ( ( result ) => {
addNameIdAndTerminating ( { group : result [ 0 ] , groupName : 'cfu' , timesetId : cfuTimeset } ) ;
let ownPhone = result [ 0 ] . length > 0 && result [ 1 ] . length === 0 ;
addNameIdAndTerminating ( { group : result [ 1 ] , groupName : 'cfna' , timesetId : cfnaTimeset } ) ;
let cftDestinations = addNameIdOwnPhoneAndTerminating ( { group : _ . cloneDeep ( result [ 0 ] ) , groupName : 'cft' , timesetId : cftTimeset , ownPhone : ownPhone } ) ;
addNameIdAndTerminating ( { group : result [ 2 ] , groupName : 'cfb' , timesetId : cfbTimeset } ) ;
let cfuDestinations = addNameIdOwnPhoneAndTerminating ( { group : _ . cloneDeep ( result [ 1 ] ) , groupName : 'cfu' , timesetId : cfuTimeset , ownPhone : ownPhone } ) ;
let offlineDestinations = addNameIdOwnPhoneAndTerminating ( { group : _ . cloneDeep ( result [ 2 ] ) , groupName : 'cfna' , timesetId : cfnaTimeset , ownPhone : ownPhone } ) ;
let busyDestinations = addNameIdOwnPhoneAndTerminating ( { group : _ . cloneDeep ( result [ 3 ] ) , groupName : 'cfb' , timesetId : cfbTimeset , ownPhone : ownPhone } ) ;
let onlineDestinations = getOnlineDestinations ( { cftDestinations : cftDestinations , cfuDestinations : cfuDestinations } ) ;
resolve ( {
resolve ( {
sourcesetId : options . sourceset _id ,
sourcesetId : options . sourceset _id ,
sourcesetName : options . sourceset _name ,
sourcesetName : options . sourceset _name ,
sourcesetMode : options . sourceset _mode ,
sourcesetMode : options . sourceset _mode ,
ownPhone : ownPhone ,
destinationGroups : {
destinationGroups : {
online : result[ 0 ] ,
online : onlineDestinations ,
offline : result[ 1 ] ,
offline : offlineDestinations ,
busy : result[ 2 ]
busy : busyDestinations
}
}
} )
} )
} ) . catch ( ( err ) => {
} ) . catch ( ( err ) => {
@ -189,13 +205,24 @@ export function getDestinationsBySourcesetId(options) {
} ) ;
} ) ;
}
}
export function addNameIdAndTerminating ( options ) {
export function getOnlineDestinations ( options ) {
if ( options . cftDestinations . length > 0 && options . cfuDestinations . length === 0 ) {
return options . cftDestinations ;
}
else {
return options . cfuDestinations ;
}
}
export function addNameIdOwnPhoneAndTerminating ( options ) {
let terminatingFlag = false ;
let terminatingFlag = false ;
options . group . forEach ( destinationset => {
options . group . forEach ( destinationset => {
destinationset . groupName = options . groupName ;
destinationset . groupName = options . groupName ;
destinationset . timesetId = options . timesetId ;
destinationset . timesetId = options . timesetId ;
destinationset . ownPhone = options . ownPhone ;
destinationset . destinations . forEach ( destination => {
destinationset . destinations . forEach ( destination => {
let normalized = normalizeDestination ( destination . destination ) ;
let normalized = normalizeDestination ( destination . destination ) ;
if ( ! terminatingFlag && _ . includes ( [ 'Voicebox' , 'Fax2Mail' , 'Manager Secretary' ,
if ( ! terminatingFlag && _ . includes ( [ 'Voicebox' , 'Fax2Mail' , 'Manager Secretary' ,
'Custom Announcement' , 'Conference' ] , normalized ) ) {
'Custom Announcement' , 'Conference' ] , normalized ) ) {
terminatingFlag = true ;
terminatingFlag = true ;
@ -841,3 +868,81 @@ export function deleteSourceFromSourcesetByIndex(options) {
} ) ;
} ) ;
} ) ;
} ) ;
}
}
export function flipCfuAndCft ( options ) {
return new Promise ( ( resolve , reject ) => {
Promise . resolve ( ) . then ( ( ) => {
return getMappings ( options . subscriberId ) ;
} ) . then ( ( mappings ) => {
let flipValues = mappings [ options . fromType ] . filter ( ( destinationset ) => {
return destinationset . sourceset _id === options . sourcesetId && destinationset . timeset _id === options . timesetId ;
} ) ;
let fromValues = mappings [ options . fromType ] . filter ( ( destinationset ) => {
return ! ( destinationset . sourceset _id === options . sourcesetId && destinationset . timeset _id === options . timesetId ) ;
} )
let toValues = mappings [ options . toType ] . concat ( flipValues ) ;
let patchOptions = [
{
op : 'replace' ,
path : '/' + options . fromType ,
value : fromValues
} , {
op : 'replace' ,
path : '/' + options . toType ,
value : toValues
}
] ;
let timeoutOption = {
op : 'replace' ,
path : '/cft_ringtimeout' ,
value : 15
} ;
if ( ! mappings . cft _ringtimeout ) {
patchOptions . push ( timeoutOption ) ;
}
return new Promise ( ( resolve , reject ) => {
let headers = {
'Content-Type' : 'application/json-patch+json'
} ;
Vue . http . patch ( 'api/cfmappings/' + options . subscriberId ,
patchOptions , { headers : headers } ) . then ( ( result ) => {
resolve ( result ) ;
} ) . catch ( ( err ) => {
reject ( err ) ;
} ) ;
} ) ;
} ) . then ( ( ) => {
resolve ( ) ;
} ) . catch ( ( err ) => {
reject ( err ) ;
} ) ;
} ) ;
}
export function getOwnPhoneTimeout ( id ) {
return new Promise ( ( resolve , reject ) => {
Vue . http . get ( 'api/cfmappings/' + id ) . then ( ( res ) => {
let timeout = getJsonBody ( res . body ) . cft _ringtimeout ;
resolve ( timeout ) ;
} ) . catch ( ( err ) => {
reject ( err ) ;
} ) ;
} ) ;
}
export function updateOwnPhoneTimeout ( options ) {
return new Promise ( ( resolve , reject ) => {
let headers = {
'Content-Type' : 'application/json-patch+json'
} ;
Vue . http . patch ( 'api/cfmappings/' + options . subscriberId , [ {
op : 'replace' ,
path : '/cft_ringtimeout' ,
value : options . timeout
} ] , { headers : headers } ) . then ( ( ) => {
resolve ( ) ;
} ) . catch ( ( err ) => {
reject ( err ) ;
} ) ;
} ) ;
}