From 77b84d6329aaf88eabed02cc47a71596b5ac2a88 Mon Sep 17 00:00:00 2001 From: raxelsen Date: Mon, 12 Mar 2018 15:54:01 +0100 Subject: [PATCH] TT#28063 Destinations grouped by SourceSets What has been done: - TT#35420, CallForwarding: Implement the UI for sourceset tabs - TT#35421, CallForwarding: Implement the UI for listing of sources - TT#35422, CallForwarding: Implement API methods - TT#35423, CallForwarding: For sources list, implement component methods/computations and store mutations/actions - TT#35433, CallForwarding: For sourceset tabs, implement component methods/computations and store mutations/actions Change-Id: I0747c45778a9db068f77422f316eb7522e3cb14c --- src/api/call-forward.js | 81 +++++++++---- .../pages/CallForward/AfterHours.vue | 6 - src/components/pages/CallForward/Always.vue | 48 ++++++-- .../pages/CallForward/CompanyHours.vue | 6 - .../CallForward/CscAddDestinationForm.vue | 6 +- .../CscCallForwardDestinations.vue | 6 +- .../CallForward/CscCallForwardTimeset.vue | 55 ++++++--- .../pages/CallForward/CscDestinations.vue | 5 +- .../pages/CallForward/CscSourcesets.vue | 111 ++++++++++++++++++ src/locales/en.json | 4 +- src/store/call-forward.js | 71 ++++++++--- 11 files changed, 316 insertions(+), 83 deletions(-) create mode 100644 src/components/pages/CallForward/CscSourcesets.vue diff --git a/src/api/call-forward.js b/src/api/call-forward.js index d8114129..503029ef 100644 --- a/src/api/call-forward.js +++ b/src/api/call-forward.js @@ -35,7 +35,11 @@ export function getSourcesets(id) { return Promise.resolve(result); } }).then(result => { - resolve(getJsonBody(result.body)._embedded['ngcp:cfsourcesets']); + let sourcesets = []; + if (getJsonBody(result.body)._embedded) { + sourcesets = getJsonBody(result.body)._embedded['ngcp:cfsourcesets']; + } + resolve(sourcesets); }).catch(err => { reject(err); }); @@ -90,36 +94,69 @@ export function getDestinationsets(id) { }); } -export function loadEverybodyDestinations(options) { - return new Promise((resolve, reject)=>{ +export function loadDestinations(options) { + return new Promise((resolve, reject) => { + Promise.resolve().then(() => { + return getSourcesets(options.subscriberId); + }).then((sourcesets) => { + let sourcesetsCollection = [{ + id: null, + name: null + }]; + let destinationPromises = []; + sourcesets.map((sourceset) => { + sourcesetsCollection.push({ + id: sourceset.id, + name: sourceset.name + }) + }); + sourcesetsCollection.forEach((sourceset) => { + destinationPromises.push( + getDestinationsBySourcesetId({ + timeset: options.timeset, + sourceset_id: sourceset.id, + sourceset_name: sourceset.name, + subscriberId: options.subscriberId + }) + ) + }); + resolve(Promise.all(destinationPromises)); + }).catch((err) => { + reject(err); + }); + }); +} + +export function getDestinationsBySourcesetId(options) { + return new Promise((resolve, reject) => { let cfuTimeset = null; let cfnaTimeset = null; let cfbTimeset = null; - Promise.resolve().then(()=>{ + Promise.resolve().then(() => { return getMappings(options.subscriberId); - }).then((mappings)=>{ + }).then((mappings) => { let cfuPromises = []; let cfnaPromises = []; let cfbPromises = []; if(_.has(mappings, 'cfu') && _.isArray(mappings.cfu) && mappings.cfu.length > 0) { - mappings.cfu.forEach((cfuMapping)=>{ - if (cfuMapping.timeset === options.timeset && cfuMapping.sourceset_id === null) { + mappings.cfu.forEach((cfuMapping) => { + if (cfuMapping.timeset === options.timeset && cfuMapping.sourceset_id === options.sourceset_id) { cfuTimeset = cfuMapping.timeset_id; cfuPromises.push(getDestinationsetById(cfuMapping.destinationset_id)); } }); } if(_.has(mappings, 'cfna') && _.isArray(mappings.cfna) && mappings.cfna.length > 0) { - mappings.cfna.forEach((cfnaMapping)=>{ - if (cfnaMapping.timeset === options.timeset && cfnaMapping.sourceset_id === null) { + mappings.cfna.forEach((cfnaMapping) => { + if (cfnaMapping.timeset === options.timeset && cfnaMapping.sourceset_id === options.sourceset_id) { cfnaTimeset = cfnaMapping.timeset_id; cfnaPromises.push(getDestinationsetById(cfnaMapping.destinationset_id)); } }); } if(_.has(mappings, 'cfb') && _.isArray(mappings.cfb) && mappings.cfb.length > 0) { - mappings.cfb.forEach((cfbMapping)=>{ - if (cfbMapping.timeset === options.timeset && cfbMapping.sourceset_id === null) { + mappings.cfb.forEach((cfbMapping) => { + if (cfbMapping.timeset === options.timeset && cfbMapping.sourceset_id === options.sourceset_id) { cfbTimeset = cfbMapping.timeset_id; cfbPromises.push(getDestinationsetById(cfbMapping.destinationset_id)); } @@ -130,15 +167,19 @@ export function loadEverybodyDestinations(options) { Promise.all(cfnaPromises), Promise.all(cfbPromises) ]); - }).then((res)=>{ - addNameIdAndTerminating({ group: res[0], groupName: 'cfu', timesetId: cfuTimeset }); - addNameIdAndTerminating({ group: res[1], groupName: 'cfna', timesetId: cfnaTimeset }); - addNameIdAndTerminating({ group: res[2], groupName: 'cfb', timesetId: cfbTimeset }); + }).then((result) => { + addNameIdAndTerminating({ group: result[0], groupName: 'cfu', timesetId: cfuTimeset }); + addNameIdAndTerminating({ group: result[1], groupName: 'cfna', timesetId: cfnaTimeset }); + addNameIdAndTerminating({ group: result[2], groupName: 'cfb', timesetId: cfbTimeset }); resolve({ - online: res[0], - offline: res[1], - busy: res[2] - }); + sourcesetId: options.sourceset_id, + sourcesetName: options.sourceset_name, + destinationGroups: { + online: result[0], + offline: result[1], + busy: result[2] + } + }) }).catch((err)=>{ reject(err); }); @@ -282,7 +323,7 @@ export function addDestinationToEmptyGroup(options) { let updatedMappings = mappings[options.groupName]; updatedMappings.push({ destinationset_id: destinationsetId, - sourceset_id: null, + sourceset_id: options.sourcesetId, timeset_id: options.timesetId }); return addNewMapping({ diff --git a/src/components/pages/CallForward/AfterHours.vue b/src/components/pages/CallForward/AfterHours.vue index bb245f99..e54e3fde 100644 --- a/src/components/pages/CallForward/AfterHours.vue +++ b/src/components/pages/CallForward/AfterHours.vue @@ -8,10 +8,6 @@ import CscPage from '../../CscPage' import CscCallForwardTimeset from './CscCallForwardTimeset' export default { - data () { - return { - } - }, components: { CscPage, CscCallForwardTimeset @@ -20,6 +16,4 @@ diff --git a/src/components/pages/CallForward/Always.vue b/src/components/pages/CallForward/Always.vue index df4c7b3e..42456f6b 100644 --- a/src/components/pages/CallForward/Always.vue +++ b/src/components/pages/CallForward/Always.vue @@ -1,33 +1,61 @@ diff --git a/src/components/pages/CallForward/CscAddDestinationForm.vue b/src/components/pages/CallForward/CscAddDestinationForm.vue index 3bc74406..7be9c115 100644 --- a/src/components/pages/CallForward/CscAddDestinationForm.vue +++ b/src/components/pages/CallForward/CscAddDestinationForm.vue @@ -49,7 +49,8 @@ 'groupName', 'priority', 'timeset', - 'timesetId' + 'timesetId', + 'sourcesetId' ], data () { return { @@ -140,7 +141,8 @@ form: this.destinationForm, destinations: this.destinations, timeset: this.timeset, - timesetId: this.timesetId + timesetId: this.timesetId, + sourcesetId: this.sourcesetId }); } } diff --git a/src/components/pages/CallForward/CscCallForwardDestinations.vue b/src/components/pages/CallForward/CscCallForwardDestinations.vue index 936f4512..787e8eca 100644 --- a/src/components/pages/CallForward/CscCallForwardDestinations.vue +++ b/src/components/pages/CallForward/CscCallForwardDestinations.vue @@ -5,18 +5,21 @@ :group="destinations.online" group-name="cfu" :timeset="timeset" + :sourceset="sourceset" icon="smartphone" /> @@ -30,6 +33,7 @@ name: 'csc-call-forward-destinations', props: [ 'timeset', + 'sourceset', 'destinations' ], data () { @@ -63,7 +67,7 @@ }, methods: { reloadDestinations(timeset) { - this.$store.dispatch('callForward/loadEverybodyDestinations', { + this.$store.dispatch('callForward/loadDestinations', { timeset: timeset }); }, diff --git a/src/components/pages/CallForward/CscCallForwardTimeset.vue b/src/components/pages/CallForward/CscCallForwardTimeset.vue index b664dc9d..a146db65 100644 --- a/src/components/pages/CallForward/CscCallForwardTimeset.vue +++ b/src/components/pages/CallForward/CscCallForwardTimeset.vue @@ -1,8 +1,10 @@ + + diff --git a/src/locales/en.json b/src/locales/en.json index 8cf4d99c..4b38c842 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -131,7 +131,8 @@ "titles": { "always": "Always", "companyHours": "Company Hours", - "afterHours": "After Hours" + "afterHours": "After Hours", + "sources": "Sources" }, "buttons": { "addNumber": "Add Number", @@ -170,6 +171,7 @@ "resetSuccessMessage": "Reset of timesets completed", "addTimeSuccessMessage": "Created new timeset", "addTimeErrorMessage": "An error occured while trying to create the timeset. Please try again.", + "loadDestinationErrorMessage": "An error occured while trying to load the destinations. Please try again.", "noTimeSet": "no time set", "addTimeButton": "Add Time", "timesetIncompatible": "The {timeset} timeset contains incompatible values. You can resolve this by resetting the {timeset} timeset.", diff --git a/src/store/call-forward.js b/src/store/call-forward.js index 285accf3..397c1c43 100644 --- a/src/store/call-forward.js +++ b/src/store/call-forward.js @@ -3,11 +3,11 @@ import _ from 'lodash'; import { i18n } from '../i18n'; -import { getSourcesets, +import { + getSourcesets, getDestinationsets, getTimesets, getMappings, - loadEverybodyDestinations, deleteDestinationFromDestinationset, addDestinationToDestinationset, addDestinationToEmptyGroup, @@ -20,7 +20,9 @@ import { getSourcesets, deleteTimesetById, resetTimesetByName, createTimesetWithTime, - appendTimeToTimeset } from '../api/call-forward'; + appendTimeToTimeset, + loadDestinations +} from '../api/call-forward'; const RequestState = { button: 'button', @@ -33,14 +35,13 @@ export default { namespaced: true, state: { mappings: null, - sourcesets: null, + sourcesets: [], + sourceset: [], timesets: null, destinationsets: null, - destinations: { - online: [], - busy: [], - offline: [] - }, + destinations: [], + loadDestinationState: RequestState.button, + loadDestinationError: null, removeDestinationState: RequestState.button, removeDestinationError: null, lastRemovedDestination: null, @@ -112,7 +113,21 @@ export default { }, showDefinedAlert(state) { return !state.timesetExists && !state.activeTimeForm && state.addTimeState !== 'succeeded'; + }, + destinationsLoaded(state) { + return state.destinations.length > 0; + }, + showTimesAndDestinations(state) { + return state.timesetIsCompatible && + !state.timesetHasReverse && + !state.timesetHasDuplicate && + state.timesetExists; + }, + loadDestinationError(state) { + return state.loadDestinationError || + i18n.t('pages.callForward.times.loadDestinationErrorMessage'); } + }, mutations: { loadMappings(state, result) { @@ -261,6 +276,21 @@ export default { state.timesetHasDuplicate = false; state.activeTimeForm = false; state.addTimeState = RequestState.button; + }, + setSourceset(state, result) { + state.sourceset = result; + }, + loadDestinationRequesting(state) { + state.loadDestinationState = RequestState.requesting; + state.loadDestinationError = null; + }, + loadDestinationSucceeded(state) { + state.loadDestinationState = RequestState.succeeded; + state.loadDestinationError = null; + }, + loadDestinationFailed(state, error) { + state.loadDestinationState = RequestState.failed; + state.loadDestinationError = error; } }, actions: { @@ -304,14 +334,6 @@ export default { }); }); }, - loadEverybodyDestinations(context, options) { - loadEverybodyDestinations({ - subscriberId: localStorage.getItem('subscriberId'), - timeset: options.timeset - }).then((result)=>{ - context.commit('loadDestinations', result); - }); - }, deleteDestinationFromDestinationset(context, options) { let removedDestination = options.removeDestination; context.commit('removeDestinationRequesting'); @@ -358,7 +380,8 @@ export default { data: form, groupName: context.getters.getGroupName, id: context.getters.getDestinationsetId, - timesetId: timeset + timesetId: timeset, + sourcesetId: options.sourcesetId }; if (options.destinations) { return new Promise(() => { @@ -514,6 +537,18 @@ export default { }).catch((err) => { context.commit('addTimeFailed', err.message); }); + }, + loadDestinations(context, options) { + context.commit('loadDestinationRequesting'); + loadDestinations({ + timeset: options.timeset, + subscriberId: context.getters.getSubscriberId + }).then((result) => { + context.commit('loadDestinations', result); + context.commit('loadDestinationSucceeded'); + }).catch((err) => { + context.commit('loadDestinationFailed', err.message); + }); } } };