From 02040f6b0ed8d703179a086dbc5306dcea7756f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20N=C3=BCsse?= Date: Mon, 31 Dec 2018 17:58:48 +0100 Subject: [PATCH] Fixed disappearing credentials on foldermove to new folder MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Felix NĂ¼sse --- js/app/controllers/credential.js | 31 ++++++++++++------------------- js/app/directives/folderpicker.js | 4 ++-- 2 files changed, 14 insertions(+), 21 deletions(-) diff --git a/js/app/controllers/credential.js b/js/app/controllers/credential.js index ba4ac38e..0e528bcb 100644 --- a/js/app/controllers/credential.js +++ b/js/app/controllers/credential.js @@ -540,24 +540,26 @@ $scope.TempFolderList=Temp; }; - $rootScope.$on('updateFolderInMainList', function (updated_credential) { - $scope.buildFolderList(updated_credential); + $rootScope.$on('updateFolderInMainList', function (evt, updated_credential) { + + for (var i = 0; i < $scope.active_vault.credentials.length; i++) { + if($scope.active_vault.credentials[i].guid === updated_credential.guid){ + $scope.active_vault.credentials[i]=updated_credential; + } + } + + $scope.buildFolderList(true); $scope.getCurrentFolderList(); $scope.createBreadCrumbList(); }); $rootScope.$on('credentials_loaded', function () { //create all folders after fetching credentials - $scope.buildFolderList(); + $scope.buildFolderList(false); $scope.getCurrentFolderList(); }); - $scope.buildFolderList = function (updated_credential) { - - var update=false; - if(typeof updated_credential !== 'undefined'){ - update=true; - } + $scope.buildFolderList = function (update) { $scope.FolderList=["/"]; $scope.TempFolderList=[]; @@ -567,7 +569,7 @@ var _credential = $scope.active_vault.credentials[i]; if(_credential.folderpath !== null){ - if(_credential.folderpath.startsWith($scope.currentFolder) || update){ + if(String(_credential.folderpath).startsWith(String($scope.currentFolder)) || update){ if($scope.FolderList.indexOf(_credential.folderpath) <= -1){ $scope.FolderList.push(_credential.folderpath); } @@ -580,19 +582,10 @@ $scope.active_vault.credentials[i]=_credential; } - if(update){ - if(!$scope.FolderList.includes(updated_credential.folderpath)){ - $scope.FolderList.push(updated_credential.folderpath); - } - } - - if(!$scope.FolderList.includes($scope.currentFolder)){ $scope.currentFolder="/"; } - console.log($scope.FolderList); - console.log($scope.TempFolderList); }; $scope.selectedtags = []; diff --git a/js/app/directives/folderpicker.js b/js/app/directives/folderpicker.js index 6401f887..5b757d38 100644 --- a/js/app/directives/folderpicker.js +++ b/js/app/directives/folderpicker.js @@ -39,9 +39,9 @@ link: function(scope, element) { scope.save = function() { - CredentialService.updateCredential(scope.credential).then(function (updated_cred) { + CredentialService.updateCredential(scope.credential).then(function () { NotificationService.showNotification($translate.instant('folderpath.moved'), 5000); - $rootScope.$broadcast('updateFolderInMainList', updated_cred); + $rootScope.$broadcast('updateFolderInMainList', scope.credential); $('#folderPicker').dialog('close'); }); };