From 11cef7871576db711cecbe2d8f425a107b265a56 Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 10 Dec 2015 06:18:55 +0300 Subject: [PATCH] added file count to fs browser... Signed-off-by: Alex A. Naanou --- ui (gen4)/css/widget/browse.css | 10 ++++++++++ ui (gen4)/lib/widget/browse-walk.js | 17 +++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/ui (gen4)/css/widget/browse.css b/ui (gen4)/css/widget/browse.css index db20e5e1..517aa051 100755 --- a/ui (gen4)/css/widget/browse.css +++ b/ui (gen4)/css/widget/browse.css @@ -187,6 +187,16 @@ overflow: hidden; } +.browse-widget .list>div:after { + display: inline-block; + + content: attr(count); + + float: right; + margin-right: 10px; + + opacity: 0.4; +} .browse-widget .list>div.strike-out .text { text-decoration: line-through; opacity: 0.3; diff --git a/ui (gen4)/lib/widget/browse-walk.js b/ui (gen4)/lib/widget/browse-walk.js index f8424676..730a375f 100755 --- a/ui (gen4)/lib/widget/browse-walk.js +++ b/ui (gen4)/lib/widget/browse-walk.js @@ -100,6 +100,7 @@ function(path, make){ // list dirs... } else { return new promise(function(resolve, reject){ + // XXX should this be a promise??? fs.readdir(path, function(err, files){ // XXX if(err){ @@ -116,9 +117,21 @@ function(path, make){ : file, null, true) }) .then(function(res){ - res && make(fullpath + var dir = res.isDirectory() + var elem = res && make(fullpath ? path +'/'+ file - : file + (res.isDirectory() ? '/' : '')) + : file + (dir ? '/' : '')) + + // count the number of files... + // NOTE: we do not care how long it will take + // so we'll not wait... + if(res && dir){ + fs.readdir(path +'/'+ file, function(err, files){ + if(!err){ + elem.attr('count', '('+ files.length +')') + } + }) + } }) // NOTE: we are not using promise.all(..) here because it // triggers BEFORE the first make(..) is called...