hide header when no files in list match
This commit is contained in:
parent
7e6c660b00
commit
b93f2ddcb5
4 changed files with 41 additions and 9 deletions
|
@ -1668,6 +1668,8 @@
|
|||
*/
|
||||
setFilter:function(filter) {
|
||||
this._filter = filter;
|
||||
this.fileSummary.setFilter(filter, this.files);
|
||||
this.hideHeaderWhenNoFilesMatch();
|
||||
var that = this;
|
||||
this.$fileList.find('tr').each(function(i,e) {
|
||||
var $e = $(e);
|
||||
|
@ -1679,6 +1681,13 @@
|
|||
}
|
||||
});
|
||||
},
|
||||
hideHeaderWhenNoFilesMatch:function() {
|
||||
if (this._filter && this.fileSummary.summary.totalDirs + this.fileSummary.summary.totalFiles === 0) {
|
||||
this.$el.find('#filestable thead th').addClass('hidden');
|
||||
} else {
|
||||
this.$el.find('#filestable thead th').removeClass('hidden');
|
||||
}
|
||||
},
|
||||
/**
|
||||
* get the current filter
|
||||
* @param filter
|
||||
|
|
|
@ -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: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
|
||||
|
@ -182,11 +205,14 @@
|
|||
|
||||
var info = t('files', '{dirs} and {files}', infoVars);
|
||||
|
||||
var $summary = $('<td><span class="info">'+info+'</span></td>'+fileSize+'<td class="date"></td>');
|
||||
var $summary = $('<td><span class="info">'+info+' <span class="filter">'+filterInfo+'</span></span></td>'+fileSize+'<td class="date"></td>');
|
||||
|
||||
if (!this.summary.totalFiles && !this.summary.totalDirs) {
|
||||
this.$el.addClass('hidden');
|
||||
}
|
||||
if (!summary.filter) {
|
||||
$summary.find('.filter').addClass('hidden');
|
||||
}
|
||||
|
||||
this.$el.append($summary);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,8 @@
|
|||
attach: function(search) {
|
||||
search.setFilter('files', function (query) {
|
||||
if (OCA.Files.Search.fileAppLoaded()) {
|
||||
if (query) {
|
||||
OCA.Files.App.fileList.setFilter(query);
|
||||
} else {
|
||||
OCA.Files.App.fileList.unfilter();
|
||||
}
|
||||
OCA.Files.App.fileList.setFilter(query);
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
@ -227,7 +227,7 @@
|
|||
// not showing result, decrease counter
|
||||
var count = $status.data('count') - 1;
|
||||
$status.data('count', count)
|
||||
.text(t('search', '{count} search results in other folders', {count:count}, count));
|
||||
.text(t('search', '{count} search results in other places', {count:count}, count));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue