From 9e663c5a181811c52759a33f80283de40da5ff1c Mon Sep 17 00:00:00 2001 From: lars Date: Sun, 15 Jun 2014 13:38:00 +0200 Subject: [PATCH] open and close filelists when they are displayed, fixes #5 --- app/js/controllers/browse.js | 31 +++++++++++++++++++------------ app/js/controllers/hubs.js | 13 +------------ 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/app/js/controllers/browse.js b/app/js/controllers/browse.js index b6af945..0c4ce2d 100644 --- a/app/js/controllers/browse.js +++ b/app/js/controllers/browse.js @@ -3,23 +3,30 @@ EiskaltApp.controller('BrowseCtrl', function ($scope, EiskaltRPC) { EiskaltRPC.ShowLocalLists().success(function (filelists) { $scope.filelists = filelists; - EiskaltRPC.ShowOpenedLists().success(function (openedFilelists) { - angular.forEach($scope.filelists, function (filelist) { - if (openedFilelists.indexOf(filelist) < 0) { - EiskaltRPC.OpenFileList(filelist); - } - }); - }); }); }); -EiskaltApp.controller('FileListCtrl', function ($scope, EiskaltRPC) { +EiskaltApp.controller('FileListCtrl', function ($scope, $timeout, EiskaltRPC) { $scope.filelist = $scope.$parent.filelist; - $scope.tree = {} $scope.treeData = []; - EiskaltRPC.LsDirInList('', $scope.filelist).success(function (data) { - $scope.treeData = data; + + var waitForOpening = function() { + EiskaltRPC.LsDirInList('', $scope.filelist).success(function (data) { + if (data.length > 0) { + $scope.treeData = data; + } else { + // not ready, give it some time + $timeout(waitForOpening, 250); + } + }); + } + + // open on start + EiskaltRPC.OpenFileList($scope.filelist).success(waitForOpening); + // close on leave + $scope.$on("$destroy", function(event) { + EiskaltRPC.CloseFileList($scope.filelist); }); $scope.handle = function(node) { @@ -48,4 +55,4 @@ EiskaltApp.controller('BrowseDownloadCtrl', function ($scope, EiskaltRPC) { } }); }; -}); \ No newline at end of file +}); diff --git a/app/js/controllers/hubs.js b/app/js/controllers/hubs.js index e054d59..a25b71d 100644 --- a/app/js/controllers/hubs.js +++ b/app/js/controllers/hubs.js @@ -62,15 +62,7 @@ EiskaltApp.controller('HubCtrl', function ($scope, $interval, $localStorage, set $scope.newChatMessage = ''; $scope.refreshChat(); }); - } - - $scope.getFilelist = function (nick) { - console.log('getFilelist', nick); - // close possible old opened filelist - - // trigger filelist download - //EiskaltRPC.GetFileList($scope.hub.huburl, nick); - } + }; }); EiskaltApp.controller('UserCtrl', function ($scope, EiskaltRPC) { @@ -78,9 +70,6 @@ EiskaltApp.controller('UserCtrl', function ($scope, EiskaltRPC) { $scope.downloadFilelist = function (nick) { EiskaltRPC.GetFileList($scope.hub.huburl, nick).success(function(status) { - EiskaltApp.ShowOpenedLists().success(function(data) { - console.log(data); - }); if (status == 0) { $scope.downloading = true; } else {