Skip to content

Commit

Permalink
fix(server): clear node/alarm caches when switching servers (COMPASS-57)
Browse files Browse the repository at this point in the history
  • Loading branch information
Benjamin Reed committed Apr 8, 2016
1 parent 28b0263 commit 5f908f6
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 32 deletions.
31 changes: 14 additions & 17 deletions src/app/alarms/AlarmsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
var angular = require('angular'),
AlarmFilter = require('./AlarmFilter');

require('angular-debounce');

require('./AlarmService');

require('../servers/Servers');
Expand All @@ -19,6 +21,7 @@
angular.module('opennms.controllers.Alarms', [
'ionic',
'angularLocalStorage',
'rt.debounce',
'opennms.services.Alarms',
'opennms.services.Errors',
'opennms.services.Modals',
Expand Down Expand Up @@ -96,7 +99,7 @@
//severity.$stateful = true;
return severity;
})
.controller('AlarmsCtrl', function($q, $scope, $log, $timeout, $ionicListDelegate, $ionicLoading, $ionicModal, $ionicPopup, $ionicScrollDelegate, $ionicViewSwitcher, storage, util, AlarmService, Errors, Modals, Servers, severityStateTracker, severities) {
.controller('AlarmsCtrl', function($q, $scope, $log, $timeout, $ionicListDelegate, $ionicLoading, $ionicModal, $ionicPopup, $ionicScrollDelegate, $ionicViewSwitcher, AlarmService, debounce, Errors, Modals, Servers, severityStateTracker, severities, storage, util) {
$log.info('AlarmsCtrl initializing.');

var filterParams = storage.get('opennms.alarms.filterParams');
Expand Down Expand Up @@ -169,22 +172,14 @@
});
};

$scope.refreshAlarms = function() {
$timeout(function() {
var delegate = $ionicScrollDelegate.$getByHandle('alarms-scroll');
if (delegate) {
delegate.scrollTop();
}
$scope.filter = $scope.filter.reset();
$scope.getAlarms();
});
};

var doThenRefresh = function(promise) {
promise['finally'](function() {
util.dirty('alarms');
});
};
$scope.refreshAlarms = debounce(500, function() {
var delegate = $ionicScrollDelegate.$getByHandle('alarms-scroll');
if (delegate) {
delegate.scrollTop();
}
$scope.filter = $scope.filter.reset();
$scope.getAlarms();
});

$scope.openAlarm = function(alarm) {
$scope.modals.alarm(alarm);
Expand Down Expand Up @@ -288,6 +283,8 @@
} else {
$scope.username = undefined;
}
$scope.alarms = [];
$scope.refreshAlarms();
});
$scope.info = {
numericVersion: 0.0
Expand Down
38 changes: 23 additions & 15 deletions src/app/nodes/NodeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,29 +209,30 @@
$scope.refresh = function() {
if ($scope.node.id) {
showLoading();
NodeService.get($scope.node.id).then(function(n) {
return NodeService.get($scope.node.id).then(function(n) {
showNode(n);
}, function(err) {
err.caller = 'NodeCtrl.refresh';
$log.error(err.toString());
}).finally(function() {
hideLoading();
});
var showGraphButton = Capabilities.graphs();
if (showGraphButton) {
ResourceService.resources($scope.node.id).then(function(res) {
//$log.debug('graphs: got res ' + angular.toJson(res));
if (res && res.children && res.children.length > 0) {
$scope.showGraphButton = true;
} else {
}).then(function() {
var showGraphButton = Capabilities.graphs();
if (showGraphButton) {
return ResourceService.resources($scope.node.id).then(function(res) {
//$log.debug('graphs: got res ' + angular.toJson(res));
if (res && res.children && res.children.length > 0) {
$scope.showGraphButton = true;
} else {
$scope.showGraphButton = false;
}
}).catch(function(err) {
$scope.showGraphButton = false;
}
}).catch(function(err) {
});
} else {
$scope.showGraphButton = false;
});
} else {
$scope.showGraphButton = false;
}
}
});
}
};

Expand All @@ -249,6 +250,13 @@
$scope.updateData();
}
});
var lastServer = {};
util.onDefaultServerUpdated(function(defaultServer) {
if (lastServer.name !== defaultServer.name) {
resetModel();
}
lastServer = defaultServer || {};
});

$scope.$on('$ionicView.beforeEnter', function(ev, info) {
$log.info('NodeCtrl: entering node view.');
Expand Down

0 comments on commit 5f908f6

Please sign in to comment.