filter new rows

This commit is contained in:
Jörn Friedrich Dreyer 2014-12-18 10:26:41 +01:00
parent d063c8e042
commit 7e6c660b00
3 changed files with 88 additions and 20 deletions

View File

@ -111,6 +111,12 @@
*/
_selectionSummary: null,
/**
* If not empty, only files containing this string will be shown
* @type String
*/
_filter: '',
/**
* Sort attribute
* @type String
@ -551,6 +557,7 @@
_nextPage: function(animate) {
var index = this.$fileList.children().length,
count = this.pageSize(),
hidden,
tr,
fileData,
newTrs = [],
@ -562,7 +569,12 @@
while (count > 0 && index < this.files.length) {
fileData = this.files[index];
tr = this._renderRow(fileData, {updateSummary: false, silent: true});
if (this._filter) {
hidden = fileData.name.toLowerCase().indexOf(this._filter.toLowerCase()) === -1;
} else {
hidden = false;
}
tr = this._renderRow(fileData, {updateSummary: false, silent: true, hidden: hidden});
this.$fileList.append(tr);
if (isAllSelected || this._selectedFiles[fileData.id]) {
tr.addClass('selected');
@ -1638,17 +1650,41 @@
});
});
},
/**
* @deprecated use setFilter(filter)
*/
filter:function(query) {
this.setFilter('');
},
/**
* @deprecated use setFilter('')
*/
unfilter:function() {
this.setFilter('');
},
/**
* hide files matching the given filter
* @param filter
*/
setFilter:function(filter) {
this._filter = filter;
var that = this;
this.$fileList.find('tr').each(function(i,e) {
if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) === -1) {
$(e).hide();
var $e = $(e);
if ($e.data('file').toString().toLowerCase().indexOf(filter.toLowerCase()) === -1) {
$e.addClass('hidden');
that.$container.trigger('scroll');
} else {
$e.removeClass('hidden');
}
});
},
unfilter:function() {
this.$fileList.find('tr:hidden').each(function(i,e) {
$(e).show();
});
/**
* get the current filter
* @param filter
*/
getFilter:function(filter) {
return this._filter;
},
/**
* Update UI based on the current selection

View File

@ -14,12 +14,10 @@
OCA.Files.Search = {
attach: function(search) {
search.setFilter('files', function (query) {
if (query) {
if (OCA.Files) {
OCA.Files.App.fileList.filter(query);
}
} else {
if (OCA.Files) {
if (OCA.Files.Search.fileAppLoaded()) {
if (query) {
OCA.Files.App.fileList.setFilter(query);
} else {
OCA.Files.App.fileList.unfilter();
}
}
@ -34,6 +32,9 @@
search.setHandler(['file', 'audio', 'image'], OCA.Files.Search.handleFileClick);
},
renderFolderResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render folder icon, show path beneath filename,
show size and last modified date on the right */
// backward compatibility:
@ -43,13 +44,17 @@
result.mime = result.mime_type;
}
var $pathDiv = $('<div class="path"></div>').text(result.path)
var $pathDiv = $('<div class="path"></div>').text(result.path);
$row.find('td.info div.name').after($pathDiv).text(result.name);
$row.find('td.result a').attr('href', result.link);
$row.find('td.icon').css('background-image', 'url(' + OC.imagePath('core', 'filetypes/folder') + ')');
return $row;
},
renderFileResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right */
// backward compatibility:
@ -64,7 +69,7 @@
$row.find('td.result a').attr('href', result.link);
if (OCA.Files) {
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.lazyLoadPreview({
path: result.path,
mime: result.mime,
@ -84,20 +89,36 @@
OC.generateUrl('/apps/files/?dir={dir}&scrollto={scrollto}', {dir: dir, scrollto: result.name})
);
}
return $row;
},
renderAudioResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right
show Artist and Album */
return $row;
},
renderImageResult: function($row, result) {
if (OCA.Files.Search.inFileList($row, result)) {
return null;
}
/*render preview icon, show path beneath filename,
show size and last modified date on the right
show width and height */
return $row;
},
inFileList: function($row, result){
if (OCA.Files.Search.fileAppLoaded() && OCA.Files.App.fileList.inList(result.name)) {
return true;
} else {
return false;
}
},
handleFolderClick: function($row, result, event) {
// open folder
if (OCA.Files) {
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.changeDirectory(result.path);
return false;
} else {
@ -105,13 +126,16 @@
}
},
handleFileClick: function($row, result, event) {
if (OCA.Files) {
if (OCA.Files.Search.fileAppLoaded()) {
OCA.Files.App.fileList.changeDirectory(OC.dirname(result.path));
OCA.Files.App.fileList.scrollTo(result.name);
return false;
} else {
return true;
}
},
fileAppLoaded: function() {
return OCA.Files && OCA.Files.App;
}
};
})();

View File

@ -26,7 +26,7 @@
Search.prototype = {
/**
* Initialize the search box and results
* Initialize the search box
*
* @param $searchBox container element with existing markup for the #searchbox form
* @private
@ -182,6 +182,7 @@
$('#app-content').on('scroll', _.bind(onScroll, this));
lastResults = results;
$status = $searchResults.find('#status')
.data('count', results.length)
.text(t('search', '{count} search results in other folders', {count:results.length}, results.length));
placeStatus();
showResults(results);
@ -210,7 +211,7 @@
* Give plugins the ability to customize the search results. see result.js for examples
*/
if (that.hasRenderer(result.type)) {
that.getRenderer(result.type)($row, result);
$row = that.getRenderer(result.type)($row, result);
} else {
// for backward compatibility add text div
$row.find('td.info div.name').addClass('result');
@ -220,7 +221,14 @@
OC.search.customResults[result.type]($row, result);
}
}
$searchResults.find('tbody').append($row);
if ($row) {
$searchResults.find('tbody').append($row);
} else {
// 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));
}
});
}
function renderCurrent() {