Skip to content

Commit

Permalink
fix(): if there was a connection error, do not replace with cached da…
Browse files Browse the repository at this point in the history
…ta (COMPASS-73)
  • Loading branch information
Benjamin Reed committed May 11, 2016
1 parent 682853e commit 4709d39
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 7 deletions.
10 changes: 7 additions & 3 deletions src/app/alarms/AlarmsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@
} else if (Errors.hasError('alarmSeverities')) {
$scope.error = Errors.get('alarmSeverities');
} else {
delete $scope.error;
$scope.error = false;
}
};

Expand Down Expand Up @@ -307,7 +307,9 @@
if (!$scope.refreshing.alarmSeverities) {
setRefreshing('alarmSeverities', true);
getCached('alarmSeverities').then(function(severities) {
$scope.legend = severities;
if ($scope.error === false) {
$scope.legend = severities;
}
}).catch(function(err) {
/*
$ionicLoading.show({
Expand All @@ -333,7 +335,9 @@
if (!$scope.refreshing.alarms) {
setRefreshing('alarms', true);
getCached('alarms', Alarm).then(function(alarms) {
updateView('alarms', alarms);
if ($scope.error === false) {
updateView('alarms', alarms);
}
}).catch(function(err) {
/*
$ionicLoading.show({
Expand Down
29 changes: 28 additions & 1 deletion src/app/dashboard/DashboardController.js
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,13 @@
$scope.refreshWaiting--;
}

if ($scope.lastResultGood.outages === false && update.cached) {
// we're in an error state, and this is a cached result, don't do anything
resetOutages();
return;
}
$scope.lastResultGood.outages = update.success;

if (update.success) {
$scope.donuts.outages = update.contents;
$scope.donuts.outages.options = angular.copy(flotOptions);
Expand Down Expand Up @@ -269,6 +276,12 @@
$scope.refreshWaiting--;
}

if ($scope.lastResultGood.alarms === false && update.cached) {
// we're in an error state, and this is a cached result, don't do anything
resetAlarms();
}
$scope.lastResultGood.alarms = update.success;

if (update.success) {
$scope.donuts.alarms = update.contents;
$scope.donuts.alarms.options = angular.copy(flotOptions);
Expand All @@ -292,6 +305,13 @@
$scope.refreshWaiting--;
}

if ($scope.lastResultGood.availability === false && update.cached) {
// we're in an error state, and this is a cached result, don't do anything
resetAvailability();
return;
}
$scope.lastResultGood.availability = update.success;

if (update.success) {
$scope.availability = update.contents;
for (var i=0, len=$scope.availability.length, section; i < len; i++) {
Expand Down Expand Up @@ -324,6 +344,13 @@
$scope.refreshWaiting--;
}

if ($scope.lastResultGood.favorites === false && update.cached) {
// we're in an error state, and this is a cached result, don't do anything
resetFavorites();
return;
}
$scope.lastResultGood.favorites = update.success;

if (update.success) {
if ($scope.currentGraphSlide >= update.contents.favorites.length) {
// "current" graph is now higher than the number of graphs we have
Expand All @@ -344,7 +371,7 @@
}
});


$scope.lastResultGood = {};
$scope.refreshing = false;
$scope.refreshWaiting = 0;
var refreshTimeout;
Expand Down
4 changes: 3 additions & 1 deletion src/app/nodes/NodesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@

$scope.updateSearch = function(searchFor, pullToRefresh) {
Cache.get('nodes-list-'+searchFor).then(function(nodes, Node) {
$scope.nodes = nodes;
if ($scope.error === false) {
$scope.nodes = nodes;
}
});

if (!pullToRefresh) {
Expand Down
8 changes: 6 additions & 2 deletions src/app/nodes/ResourcesController.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,10 @@
$log.info('NodeResources.refresh: refreshing: ' + $scope.nodeId);
if ($scope.nodeId) {
Cache.get('node-resources-' + $scope.nodeId).then(function(ret) {
$scope.resourceLabel = ret.resourceLabel;
$scope.resources = ret.resources;
if ($scope.error === false) {
$scope.resourceLabel = ret.resourceLabel;
$scope.resources = ret.resources;
}
}).catch(function() {
$scope.loading = true;
});
Expand All @@ -65,11 +67,13 @@
var children = ret.children;
children.sort(sortResources);
$scope.resources = ResourceService.withDividers(children);
$scope.error = false;
return Cache.set('node-resources-' + $scope.nodeId, {
resourceLabel: $scope.resourceLabel,
resources: $scope.resources
});
}, function(err) {
$scope.error = true;
$log.error('NodeResources.refresh: failed: ' + angular.toJson(err));
return $q.reject(err);
}).finally(function() {
Expand Down

0 comments on commit 4709d39

Please sign in to comment.