From 34a920ec5ca9801b1a3dac38f8bdd03576ed93b7 Mon Sep 17 00:00:00 2001 From: brantje Date: Sun, 29 Oct 2017 15:27:50 +0100 Subject: [PATCH] Fix loading vault if it's already open. Ref #263 Signed-off-by: brantje --- .scrutinizer.yml | 1 - js/app/controllers/credential.js | 16 +++++++++++++++- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 048faab3..3e5166ba 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -21,5 +21,4 @@ tools: build_failure_conditions: - 'issues.label("coding-style").new.count > 5' - 'issues.severity(>= MAJOR).new.exists' - - 'elements.rating(<= D).new.exists' - 'project.metric("scrutinizer.quality", < 7.5)' \ No newline at end of file diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index 1496097b..303635f1 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -58,6 +58,9 @@ vault.credentials = []; $scope.active_vault = vault; $scope.active_vault.vaultKey = vaultKey; + if(!$rootScope.vaultCache){ + $rootScope.vaultCache = []; + } VaultService.setActiveVault($scope.active_vault); for (var i = 0; i < _credentials.length; i++) { var _credential = _credentials[i]; @@ -103,6 +106,7 @@ angular.merge($scope.active_vault.credentials, _credentials); $scope.show_spinner = false; $rootScope.$broadcast('credentials_loaded'); + $rootScope.vaultCache[$scope.active_vault.guid] = angular.copy($scope.active_vault); if(!vault.private_sharing_key){ var key_size = 1024; ShareService.generateRSAKeys(key_size).then(function (kp) { @@ -135,13 +139,20 @@ var refresh_data_interval = null; if ($scope.active_vault) { $scope.$parent.selectedVault = true; - fetchCredentials(); + if($rootScope.vaultCache && $rootScope.vaultCache[$scope.active_vault.guid]){ + $scope.active_vault = $rootScope.vaultCache[$scope.active_vault.guid]; + $rootScope.$broadcast('credentials_loaded'); + $scope.show_spinner = false; + } else { + fetchCredentials(); + } getPendingShareRequests(); refresh_data_interval = $interval(function () { fetchCredentials(); getPendingShareRequests(); }, 60000 * 5); } + $scope.$on('$destroy', function () { $interval.cancel(refresh_data_interval); }); @@ -399,6 +410,9 @@ }; $rootScope.$on('logout', function () { + if($scope.active_vault) { + $rootScope.vaultCache[$scope.active_vault.guid] = null; + } $scope.active_vault = null; $scope.credentials = []; // $scope.$parent.selectedVault = false;