From b93f2ddcb577a262d170163f4bc7117b70ffa3f7 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Thu, 18 Dec 2014 23:11:42 +0100 Subject: hide header when no files in list match --- apps/files/js/filesummary.js | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) (limited to 'apps/files/js/filesummary.js') diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index f83eb54678b..d73fd59cb81 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -39,7 +39,8 @@ summary: { totalFiles: 0, totalDirs: 0, - totalSize: 0 + totalSize: 0, + filter:'' }, /** @@ -48,6 +49,9 @@ * @param update whether to update the display */ add: function(file, update) { + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + return; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { this.summary.totalDirs++; } @@ -65,6 +69,9 @@ * @param update whether to update the display */ remove: function(file, update) { + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + return; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { this.summary.totalDirs--; } @@ -76,6 +83,10 @@ this.update(); } }, + setFilter: function(filter, files){ + this.summary.filter = filter.toLowerCase(); + this.calculate(files); + }, /** * Returns the total of files and directories */ @@ -91,11 +102,15 @@ var summary = { totalDirs: 0, totalFiles: 0, - totalSize: 0 + totalSize: 0, + filter: this.summary.filter }; for (var i = 0; i < files.length; i++) { file = files[i]; + if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + continue; + } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { summary.totalDirs++; } @@ -137,10 +152,12 @@ var $dirInfo = this.$el.find('.dirinfo'); var $fileInfo = this.$el.find('.fileinfo'); var $connector = this.$el.find('.connector'); + var $filterInfo = this.$el.find('.filter'); // Substitute old content with new translations $dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs)); $fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles)); + $filterInfo.html(n('files', 'matches \'{filter}\'', 'match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); this.$el.find('.filesize').html(OC.Util.humanFileSize(this.summary.totalSize)); // Show only what's necessary (may be hidden) @@ -159,6 +176,11 @@ if (this.summary.totalDirs > 0 && this.summary.totalFiles > 0) { $connector.removeClass('hidden'); } + if (this.summary.filter === '') { + $filterInfo.addClass('hidden'); + } else { + $filterInfo.removeClass('hidden'); + } }, render: function() { if (!this.$el) { @@ -168,6 +190,7 @@ var summary = this.summary; var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs); var fileInfo = n('files', '%n file', '%n files', summary.totalFiles); + var filterInfo = n('files', 'matches \'{filter}\'', 'match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}) var infoVars = { dirs: ''+directoryInfo+'', @@ -182,11 +205,14 @@ var info = t('files', '{dirs} and {files}', infoVars); - var $summary = $(''+info+''+fileSize+''); + var $summary = $(''+info+' '+filterInfo+''+fileSize+''); if (!this.summary.totalFiles && !this.summary.totalDirs) { this.$el.addClass('hidden'); } + if (!summary.filter) { + $summary.find('.filter').addClass('hidden'); + } this.$el.append($summary); } -- cgit v1.2.3 From b45d0f03fc57c861ddaec0e293d537eefab4c7d1 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 14:36:48 +0100 Subject: fix js tests --- apps/files/js/filesummary.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'apps/files/js/filesummary.js') diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index d73fd59cb81..46880272cdc 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -49,7 +49,7 @@ * @param update whether to update the display */ add: function(file, update) { - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { return; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { @@ -69,7 +69,7 @@ * @param update whether to update the display */ remove: function(file, update) { - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { return; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { @@ -133,6 +133,9 @@ */ setSummary: function(summary) { this.summary = summary; + if (typeof this.summary.filter === 'undefined') { + this.summary.filter = ''; + } this.update(); }, @@ -157,7 +160,6 @@ // Substitute old content with new translations $dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs)); $fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles)); - $filterInfo.html(n('files', 'matches \'{filter}\'', 'match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); this.$el.find('.filesize').html(OC.Util.humanFileSize(this.summary.totalSize)); // Show only what's necessary (may be hidden) @@ -177,8 +179,10 @@ $connector.removeClass('hidden'); } if (this.summary.filter === '') { + $filterInfo.html(''); $filterInfo.addClass('hidden'); } else { + $filterInfo.html(n('files', ' matches \'{filter}\'', ' match \'{filter}\'', this.summary.totalDirs + this.summary.totalFiles, {filter: this.summary.filter})); $filterInfo.removeClass('hidden'); } }, @@ -190,7 +194,11 @@ var summary = this.summary; var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs); var fileInfo = n('files', '%n file', '%n files', summary.totalFiles); - var filterInfo = n('files', 'matches \'{filter}\'', 'match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}) + if (this.summary.filter === '') { + var filterInfo = ''; + } else { + var filterInfo = n('files', ' matches \'{filter}\'', ' match \'{filter}\'', summary.totalFiles + summary.totalDirs, {filter: summary.filter}); + } var infoVars = { dirs: ''+directoryInfo+'', @@ -205,14 +213,11 @@ var info = t('files', '{dirs} and {files}', infoVars); - var $summary = $(''+info+' '+filterInfo+''+fileSize+''); + var $summary = $(''+info+''+filterInfo+''+fileSize+''); if (!this.summary.totalFiles && !this.summary.totalDirs) { this.$el.addClass('hidden'); } - if (!summary.filter) { - $summary.find('.filter').addClass('hidden'); - } this.$el.append($summary); } -- cgit v1.2.3 From 457f5abf6cc611064b30bdc0d70a8d42a73c9706 Mon Sep 17 00:00:00 2001 From: Jörn Friedrich Dreyer Date: Wed, 31 Dec 2014 16:15:57 +0100 Subject: fix count --- apps/files/js/filesummary.js | 2 +- search/js/search.js | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) (limited to 'apps/files/js/filesummary.js') diff --git a/apps/files/js/filesummary.js b/apps/files/js/filesummary.js index 46880272cdc..d69c5f1b53a 100644 --- a/apps/files/js/filesummary.js +++ b/apps/files/js/filesummary.js @@ -108,7 +108,7 @@ for (var i = 0; i < files.length; i++) { file = files[i]; - if (file.name.toLowerCase().indexOf(this.summary.filter) === -1) { + if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { continue; } if (file.type === 'dir' || file.mime === 'httpd/unix-directory') { diff --git a/search/js/search.js b/search/js/search.js index b19a420cee8..b090a4ec4a8 100644 --- a/search/js/search.js +++ b/search/js/search.js @@ -234,6 +234,9 @@ } else { // not showing result, decrease counter var count = $status.data('count') - 1; + if (count < 0) { + count = 0; + } $status.data('count', count) .text(t('search', '{count} search results in other places', {count:count}, count)); } -- cgit v1.2.3