TT#20533 Change the order of Destinations

What subtasks have been done:
 - 20689: CallForward: Merge latest changes
 - 20628: CallForward: Update destinationsets in all affected
   grids/states
 - 20631: CallForward: Remove superfluous destinations from duplicate
   destinationset names
 - 20688: CallForward: Discussion about the overall approach and
   common understanding

Change-Id: Id1b1c69c8c943ffee777ed44abd2282c66f3e1ad
changes/85/14985/7
Robert Axelsen 8 years ago
parent 02e7b70eb6
commit 65286e9be4

@ -182,6 +182,9 @@ Ext.define('NgcpCsc.view.main.MainController', {
this.setSectionTitle(id); this.setSectionTitle(id);
if (id == 'inbox' || id == 'conversation-with' || id == 'pbxconfig/seats' || id == 'pbxconfig/groups' || id == 'pbxconfig/devices') { if (id == 'inbox' || id == 'conversation-with' || id == 'pbxconfig/seats' || id == 'pbxconfig/groups' || id == 'pbxconfig/devices') {
vm.set('headerBarFieldHideState', false); vm.set('headerBarFieldHideState', false);
} else if (id == 'callforward/always' || id == 'callforward/afterhours' || id == 'callforward/companyhours') {
this.fireEvent('cfReloadStore');
vm.set('headerBarFieldHideState', true);
} else { } else {
vm.set('headerBarFieldHideState', true); vm.set('headerBarFieldHideState', true);
}; };

@ -6,7 +6,8 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
listen: { listen: {
controller: { controller: {
'*': { '*': {
confirmCFRemoval: 'confirmCFRemoval' confirmCFRemoval: 'confirmCFRemoval',
cfReloadStore: 'cfReLoadStore'
} }
}, },
store: { store: {
@ -129,7 +130,21 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
}; };
}, },
sortDestinationsetByPriority: function(destinations) { getStoreNameFromRoute: function (route) {
switch (route) {
case ('#callforward/always'):
return 'CallForwardAlways';
break;
case ('#callforward/afterhours'):
return 'CallForwardAfterHours';
break;
case ('#callforward/companyhours'):
return 'CallForwardCompanyHours';
break;
};
},
sortDestinationsetByPriority: function (destinations) {
var sorted = destinations.sort(function(a, b) { var sorted = destinations.sort(function(a, b) {
return parseFloat(a.priority) - parseFloat(b.priority); return parseFloat(a.priority) - parseFloat(b.priority);
}); });
@ -155,7 +170,6 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var arrayOfModels = []; var arrayOfModels = [];
var currentRoute = window.location.hash; var currentRoute = window.location.hash;
var routeTimeset = this.getTimesetFromRoute(currentRoute); var routeTimeset = this.getTimesetFromRoute(currentRoute);
if (me.getView()._preventReLoad) return;
store.removeAll(); store.removeAll();
// TODO optimize, too many nested loops affects performance. // TODO optimize, too many nested loops affects performance.
// Ex. Where possible use break Ext.each by return false; // Ex. Where possible use break Ext.each by return false;
@ -164,30 +178,29 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
success: function(response, opts) { success: function(response, opts) {
var decodedResponse = Ext.decode(response.responseText); var decodedResponse = Ext.decode(response.responseText);
if (decodedResponse._embedded) { if (decodedResponse._embedded) {
var destinationsets = decodedResponse._embedded['ngcp:cfdestinationsets']; var cfdestinationsets = decodedResponse._embedded['ngcp:cfdestinationsets'];
destinationsets[0].destinations = me.sortDestinationsetByPriority(destinationsets[0].destinations); cfdestinationsets[0].destinations = me.sortDestinationsetByPriority(cfdestinationsets[0].destinations);
me.getView()._preventReLoad = true; // assumes there is no need to reload the store Ext.each(cfTypeArrayOfObjects, function (cfTypeObjects, index) {
Ext.each(cfTypeArrayOfObjects, function(cfTypeObjects, index) {
var cfType = cfTypes[index]; var cfType = cfTypes[index];
cfType !== 'cft' && me.addCftOwnPhone(destinationsets[0].destinations); // if 'cft' we invoke addCftOwnPhone() cfType !== 'cft' && me.addCftOwnPhone(cfdestinationsets[0].destinations); // cfType is 'cft' we invoke addCftOwnPhone()
Ext.each(cfTypeObjects, function(cfTypeObject) { Ext.each(cfTypeObjects, function(cfTypeObject) {
var cfmappings = {};
var destinationsetName = cfTypeObject.destinationset; cfmappings.destinationsetName = cfTypeObject.destinationset;
var sourcesetName = cfTypeObject.sourceset; cfmappings.sourcesetName = cfTypeObject.sourceset;
var timesetName = cfTypeObject.timeset; cfmappings.timesetName = cfTypeObject.timeset;
if (timesetName == routeTimeset) { if (cfmappings.timesetName == routeTimeset) {
Ext.each(destinationsets, function(destinationset) { Ext.each(cfdestinationsets, function(cfdestinationset) {
if (destinationset.name == destinationsetName) { if (cfdestinationset.name == cfmappings.destinationsetName && !cfmappings._modelCreated) {
for (item in destinationset.destinations) { for (item in cfdestinationset.destinations) {
var destinationToDisplayInGrid = me.getDestinationFromSipId(destinationset.destinations[item].destination); var destinationToDisplayInGrid = me.getDestinationFromSipId(cfdestinationset.destinations[item].destination);
var destinationAnnouncementId = destinationset.announcement_id; var destinationAnnouncementId = cfdestinationset.announcement_id;
var destination = destinationset.destinations[item].destination; var destination = cfdestinationset.destinations[item].destination;
var priority = destinationset.destinations[item].priority; var priority = cfdestinationset.destinations[item].priority;
var timeout = destinationset.destinations[item].timeout; var timeout = cfdestinationset.destinations[item].timeout;
var destinationId = destinationset.id; var destinationId = cfdestinationset.id;
var destinationName = destinationset.name; var destinationName = cfdestinationset.name;
// Removes timeout if destination is not a number // Removes timeout if destination is not a number
var ringFor = !Ext.isNumber(parseInt(destinationToDisplayInGrid)) ? '' : destinationset.destinations[item].timeout; var ringFor = !Ext.isNumber(parseInt(destinationToDisplayInGrid)) ? '' : cfdestinationset.destinations[item].timeout;
var cbModel = Ext.create('NgcpCsc.model.CallForwardDestination', { var cbModel = Ext.create('NgcpCsc.model.CallForwardDestination', {
type: cfType, type: cfType,
destination_displayed: destinationToDisplayInGrid, destination_displayed: destinationToDisplayInGrid,
@ -196,12 +209,13 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
priority: priority, priority: priority,
timeout_displayed: ringFor, timeout_displayed: ringFor,
timeout: timeout, timeout: timeout,
sourceset: sourcesetName, sourceset: cfmappings.sourcesetName,
timeset: timesetName, timeset: cfmappings.timesetName,
destinationset_id: destinationId, destinationset_id: destinationId,
destinationset_name: destinationName destinationset_name: destinationName
}); });
arrayOfModels.push(cbModel); arrayOfModels.push(cbModel);
cfmappings._modelCreated = true;
} }
} }
}); });
@ -229,6 +243,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
cfStoreBeforeSync: function(store, options) { cfStoreBeforeSync: function(store, options) {
var me = this; var me = this;
var vm = this.getViewModel();
var recordsToSend = []; var recordsToSend = [];
delete options['destroy']; delete options['destroy'];
delete options['create']; delete options['create'];
@ -276,7 +291,10 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
"value": obj.records "value": obj.records
}], }],
success: function(response, opts) { success: function(response, opts) {
store.commitChanges(); var currentRoute = window.location.hash;
var currentStoreName = me.getStoreNameFromRoute(currentRoute);
Ext.getStore(currentStoreName).load();
vm.set('last_store_synced', currentStoreName);
}, },
failure: function(response, opts) { failure: function(response, opts) {
console.log('server-side failure with status code ' + response.status); console.log('server-side failure with status code ' + response.status);
@ -286,7 +304,17 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
return false; return false;
}, },
cfSourcesetBeforeSync: function(store, options) { cfReLoadStore: function () {
var me = this;
var vm = this.getViewModel();
var currentRoute = window.location.hash;
var currentStoreName = me.getStoreNameFromRoute(currentRoute);
if (vm.get('last_store_synced').length > 0 && currentStoreName !== vm.get('last_store_synced')) {
Ext.getStore(currentStoreName).load();
};
},
cfSourcesetBeforeSync: function (store, options) {
// Using Ajax request here as we are using different url // Using Ajax request here as we are using different url
// params for PATCH compared to GET // params for PATCH compared to GET
delete options['destroy']; delete options['destroy'];
@ -535,7 +563,10 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
var type = me.getGridCategoryFromType(model.get('type')); var type = me.getGridCategoryFromType(model.get('type'));
var storeName = sourcename + timename + type; var storeName = sourcename + timename + type;
store = Ext.getStore(storeName); store = Ext.getStore(storeName);
if(!store._emptied){
store.removeAll();
store._emptied = true;
}
if (store) { if (store) {
store.add(model); store.add(model);
stores.push(store); stores.push(store);
@ -545,6 +576,7 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardController', {
Ext.each(stores, function(store) { Ext.each(stores, function(store) {
store.commitChanges(); store.commitChanges();
me.setLabelTerminationType(store); me.setLabelTerminationType(store);
store._emptied = false;
}); });
} }
}, },

@ -33,7 +33,8 @@ Ext.define('NgcpCsc.view.pages.callforward.CallForwardModel', {
offline_then_number: '', offline_then_number: '',
offline_then_timeout: '10', offline_then_timeout: '10',
after_hours_exists_in_api: false, after_hours_exists_in_api: false,
company_hours_exists_in_api: false company_hours_exists_in_api: false,
last_store_synced: ''
}, },
formulas: { formulas: {

Loading…
Cancel
Save