diff --git a/openstack_dashboard/static/js/horizon.networktopologycommon.js b/openstack_dashboard/static/js/horizon.networktopologycommon.js index a2722e8fec..9a435f88ac 100644 --- a/openstack_dashboard/static/js/horizon.networktopologycommon.js +++ b/openstack_dashboard/static/js/horizon.networktopologycommon.js @@ -20,6 +20,59 @@ horizon.networktopologycommon = { } }; +function isEqual(data1, data2) { + var list1=[],list2=[]; + function compare2Objects (data1, data2) { + var item; + + if (isNaN(data1) && isNaN(data2) && typeof data1 === 'number' && typeof data2 === 'number') { + return true; + } + + // Compare primitives and functions. + // Check if both arguments link to the same object. + // Especially useful on the step where we compare prototypes + if (data1 === data2) { + return true; + } + for (item in data1) { + if (data2.hasOwnProperty(item) !== data1.hasOwnProperty(item)) { + return false; + } + else if (typeof data2[item] !== typeof data1[item]) { + return false; + } + + switch (typeof (data1[item])) { + case 'object': + if (!compare2Objects (data1[item], data2[item])) { + return false; + } + break; + + default: + if (data1[item] !== data2[item]) { + list1.push(data1[item]); + list2.push(data2[item]); + } + break; + } + } + return true; + } + if(!compare2Objects(data1, data2)){ + return false; + }else{ + list1 = list1.sort(); + list2 = list2.sort(); + for(var i in list1){ + if(list2[i]!=list1[i]) + return false; + } + } + return true; +} + /** * Common data loader for network topology views */ @@ -30,7 +83,7 @@ horizon.networktopologyloader = { reload_duration: 10000, // timer controlling update intervals update_timer: null, - + previous_data : {}, init:function() { var self = this; if($('#networktopology').length === 0) { @@ -48,9 +101,12 @@ horizon.networktopologyloader = { angular.element('#networktopology').data('networktopology') + '?' + angular.element.now(), function(data) { self.model = data; - $('#networktopology').trigger('change'); + if(!isEqual(data,self.previous_data)) { + angular.copy(data, self.previous_data); + $('#networktopology').trigger('change'); + } self.update_timer = setTimeout(function(){ - self.update(); + self.update(); }, self.reload_duration); } );