From c918e0fbcedbb3f5f30fb23cc3fa3dc573035447 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 8 Apr 2013 03:35:46 -0400 Subject: [PATCH] added ability to get directory size, when space button is pressed and current file is directory. --- .gitignore | 3 +++ ChangeLog | 3 +++ lib/client/dom.js | 25 ++++++++++++++++++++----- lib/client/keyBinding.js | 14 +++++++++++++- lib/server/dir.js | 23 +++++++++++++++++------ lib/server/rest.js | 1 + 6 files changed, 57 insertions(+), 12 deletions(-) diff --git a/.gitignore b/.gitignore index b278c246..1f8a30f7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,8 @@ #files, the will be ignored by git +#file with changes +json/changes.json + #c9 files .c9revisions *tmp diff --git a/ChangeLog b/ChangeLog index 82b707cf..3f2e2886 100644 --- a/ChangeLog +++ b/ChangeLog @@ -56,6 +56,9 @@ from storage folder. * Added ability to recursivly get current folder size. +* Added ability to get directory size, when space button +is pressed and current file is directory. + 2012.03.01, Version 0.1.9 diff --git a/lib/client/dom.js b/lib/client/dom.js index 0a84cecd..887bb31f 100644 --- a/lib/client/dom.js +++ b/lib/client/dom.js @@ -1001,13 +1001,14 @@ var CloudCommander, Util, DOM = {}, CloudFunc; * get size * @pCurrentFile */ - DOM.loadCurrentSize = function(pCurrentFile){ + DOM.loadCurrentSize = function(pCallBack, pCurrentFile){ var lRet, lLink = DOM.getCurrentPath(pCurrentFile); /* если это папка - возвращаем слово dir вместо размера*/ DOM.RESTfull.read(lLink, function(pSize){ - Util.log(pSize); + DOM.setCurrentSize(pSize); + Util.exec(pCallBack); }, '?size'); return lRet; @@ -1232,14 +1233,28 @@ var CloudCommander, Util, DOM = {}, CloudFunc; return lIsCurrent; }; + /** + * selected file check + * + * @param pCurrentFile + */ + DOM.isSelected = function(pSelected){ + var lClass = pSelected && pSelected.className, + lIsSelected = lClass && lClass.indexOf(SELECTED_FILE) >= 0; + + return lIsSelected; + }; + /** * check is current file is a directory * * @param pCurrentFile */ - DOM.isCurrentIsDir = function(pCurrentFile){ - var lSize = DOM.getCurrentSize(pCurrentFile), - lRet = lSize === 'dir'; + DOM.isCurrentIsDir = function(pCurrent){ + var lCurrent = pCurrent || DOM.getCurrentFile(), + lFileType = DOM.getByClass('mini-icon', lCurrent)[0], + lClass = lFileType && lFileType.className, + lRet = lClass && lClass.indexOf('directory') >= 0; return lRet; }; diff --git a/lib/client/keyBinding.js b/lib/client/keyBinding.js index fc42d880..d16ea54b 100644 --- a/lib/client/keyBinding.js +++ b/lib/client/keyBinding.js @@ -186,7 +186,19 @@ var CloudCommander, Util, DOM; break; case KEY.SPACE: - DOM.selectFile(lCurrentFile); + var lSelected = DOM.isSelected(lCurrentFile), + lDir = DOM.isCurrentIsDir(lCurrentFile); + + + if(lDir) + Util.ifExec(lSelected, function(){ + DOM.selectFile(lCurrentFile); + }, function(pCallBack){ + DOM.loadCurrentSize(pCallBack, lCurrentFile); + }); + else + DOM.selectFile(lCurrentFile); + DOM.preventDefault(pEvent); break; diff --git a/lib/server/dir.js b/lib/server/dir.js index 22d91658..ff8043eb 100644 --- a/lib/server/dir.js +++ b/lib/server/dir.js @@ -41,23 +41,34 @@ fs.readdir(pDir, function(pError, pFiles) { lAsyncRunning--; + var lDirPath, n; + if (!pError){ - lFileCounter += pFiles.length; + n = pFiles.length; + lFileCounter += n; - var lDirPath; - for (var i = 0, n = pFiles.length; i < n; i++) { + for (var i = 0; i < n; i++) { lDirPath = path.join(pDir, pFiles[i]); getDirSize(lDirPath); } } + + if(!n) + execCallBack(); }); } } - if (!lFileCounter && !lAsyncRunning) - pCallBack(null, lTotal); - }); + execCallBack(); + }); + } + + function execCallBack(){ + if (!lFileCounter && !lAsyncRunning){ + console.log(lTotal); + pCallBack(null, lTotal); } + } return getDirSize(pDir); }; diff --git a/lib/server/rest.js b/lib/server/rest.js index 6835549c..183a76d7 100644 --- a/lib/server/rest.js +++ b/lib/server/rest.js @@ -103,6 +103,7 @@ dir.getSize(p.name, function(pErr, pSize){ if(!pErr){ var lSize = CloudFunc.getShortSize(pSize); + console.log(lSize); main.sendResponse(pParams, lSize); } else