Display number of hidden files in files summary (#25870)

When dot files are hidden, the table summary and selection summary will
not show how many hidden files were included.
This commit is contained in:
Vincent Petry 2016-08-19 16:44:58 +02:00 committed by Lukas Reschke
parent 3647fbe7cd
commit 7fa66409ae
No known key found for this signature in database
GPG Key ID: B9F6980CF6E759B1
4 changed files with 230 additions and 52 deletions

View File

@ -199,6 +199,7 @@
* @param options.folderDropOptions folder drop options, disabled by default * @param options.folderDropOptions folder drop options, disabled by default
* @param options.scrollTo name of file to scroll to after the first load * @param options.scrollTo name of file to scroll to after the first load
* @param {OC.Files.Client} [options.filesClient] files API client * @param {OC.Files.Client} [options.filesClient] files API client
* @param {OC.Backbone.Model} [options.filesConfig] files app configuration
* @private * @private
*/ */
initialize: function($el, options) { initialize: function($el, options) {
@ -239,6 +240,7 @@
this._filesConfig.on('change:showhidden', function() { this._filesConfig.on('change:showhidden', function() {
var showHidden = this.get('showhidden'); var showHidden = this.get('showhidden');
self.$el.toggleClass('hide-hidden-files', !showHidden); self.$el.toggleClass('hide-hidden-files', !showHidden);
self.updateSelectionSummary();
if (!showHidden) { if (!showHidden) {
// hiding files could make the page too small, need to try rendering next page // hiding files could make the page too small, need to try rendering next page
@ -264,7 +266,7 @@
this.files = []; this.files = [];
this._selectedFiles = {}; this._selectedFiles = {};
this._selectionSummary = new OCA.Files.FileSummary(); this._selectionSummary = new OCA.Files.FileSummary(undefined, {config: this._filesConfig});
// dummy root dir info // dummy root dir info
this.dirInfo = new OC.Files.FileInfo({}); this.dirInfo = new OC.Files.FileInfo({});
@ -2304,7 +2306,7 @@
var $tr = $('<tr class="summary"></tr>'); var $tr = $('<tr class="summary"></tr>');
this.$el.find('tfoot').append($tr); this.$el.find('tfoot').append($tr);
return new OCA.Files.FileSummary($tr); return new OCA.Files.FileSummary($tr, {config: this._filesConfig});
}, },
updateEmptyContent: function() { updateEmptyContent: function() {
var permissions = this.getDirectoryPermissions(); var permissions = this.getDirectoryPermissions();
@ -2451,6 +2453,7 @@
var summary = this._selectionSummary.summary; var summary = this._selectionSummary.summary;
var selection; var selection;
var showHidden = !!this._filesConfig.get('showhidden');
if (summary.totalFiles === 0 && summary.totalDirs === 0) { if (summary.totalFiles === 0 && summary.totalDirs === 0) {
this.$el.find('#headerName a.name>span:first').text(t('files','Name')); this.$el.find('#headerName a.name>span:first').text(t('files','Name'));
this.$el.find('#headerSize a>span:first').text(t('files','Size')); this.$el.find('#headerSize a>span:first').text(t('files','Size'));
@ -2477,6 +2480,11 @@
selection = fileInfo; selection = fileInfo;
} }
if (!showHidden && summary.totalHidden > 0) {
var hiddenInfo = n('files', 'including %n hidden', 'including %n hidden', summary.totalHidden);
selection += ' (' + hiddenInfo + ')';
}
this.$el.find('#headerName a.name>span:first').text(selection); this.$el.find('#headerName a.name>span:first').text(selection);
this.$el.find('#modified a>span:first').text(''); this.$el.find('#modified a>span:first').text('');
this.$el.find('table').addClass('multiselect'); this.$el.find('table').addClass('multiselect');

View File

@ -20,6 +20,15 @@
*/ */
(function() { (function() {
var INFO_TEMPLATE =
'<span class="info">' +
'<span class="dirinfo"></span>' +
'<span class="connector"> and </span>' +
'<span class="fileinfo"></span>' +
'<span class="hiddeninfo"></span>' +
'<span class="filter"></span>' +
'</span>';
/** /**
* The FileSummary class encapsulates the file summary values and * The FileSummary class encapsulates the file summary values and
* the logic to render it in the given container * the logic to render it in the given container
@ -28,26 +37,51 @@
* @memberof OCA.Files * @memberof OCA.Files
* *
* @param $tr table row element * @param $tr table row element
* @param {OC.Backbone.Model} [options.filesConfig] files app configuration
*/ */
var FileSummary = function($tr) { var FileSummary = function($tr, options) {
options = options || {};
var self = this;
this.$el = $tr; this.$el = $tr;
var filesConfig = options.config;
if (filesConfig) {
this._showHidden = !!filesConfig.get('showhidden');
filesConfig.on('change:showhidden', function() {
self._showHidden = !!this.get('showhidden');
self.update();
});
}
this.clear(); this.clear();
this.render(); this.render();
}; };
FileSummary.prototype = { FileSummary.prototype = {
_showHidden: null,
summary: { summary: {
totalFiles: 0, totalFiles: 0,
totalDirs: 0, totalDirs: 0,
totalHidden: 0,
totalSize: 0, totalSize: 0,
filter:'', filter:'',
sumIsPending:false sumIsPending:false
}, },
/**
* Returns whether the given file info must be hidden
*
* @param {OC.Files.FileInfo} fileInfo file info
*
* @return {boolean} true if the file is a hidden file, false otherwise
*/
_isHiddenFile: function(file) {
return file.name && file.name.charAt(0) === '.';
},
/** /**
* Adds file * Adds file
* @param file file to add * @param {OC.Files.FileInfo} file file to add
* @param update whether to update the display * @param {boolean} update whether to update the display
*/ */
add: function(file, update) { add: function(file, update) {
if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) {
@ -59,6 +93,10 @@
else { else {
this.summary.totalFiles++; this.summary.totalFiles++;
} }
if (this._isHiddenFile(file)) {
this.summary.totalHidden++;
}
var size = parseInt(file.size, 10) || 0; var size = parseInt(file.size, 10) || 0;
if (size >=0) { if (size >=0) {
this.summary.totalSize += size; this.summary.totalSize += size;
@ -71,8 +109,8 @@
}, },
/** /**
* Removes file * Removes file
* @param file file to remove * @param {OC.Files.FileInfo} file file to remove
* @param update whether to update the display * @param {boolean} update whether to update the display
*/ */
remove: function(file, update) { remove: function(file, update) {
if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) { if (file.name && file.name.toLowerCase().indexOf(this.summary.filter) === -1) {
@ -84,6 +122,9 @@
else { else {
this.summary.totalFiles--; this.summary.totalFiles--;
} }
if (this._isHiddenFile(file)) {
this.summary.totalHidden--;
}
var size = parseInt(file.size, 10) || 0; var size = parseInt(file.size, 10) || 0;
if (size >=0) { if (size >=0) {
this.summary.totalSize -= size; this.summary.totalSize -= size;
@ -111,6 +152,7 @@
var summary = { var summary = {
totalDirs: 0, totalDirs: 0,
totalFiles: 0, totalFiles: 0,
totalHidden: 0,
totalSize: 0, totalSize: 0,
filter: this.summary.filter, filter: this.summary.filter,
sumIsPending: false sumIsPending: false
@ -127,6 +169,9 @@
else { else {
summary.totalFiles++; summary.totalFiles++;
} }
if (this._isHiddenFile(file)) {
summary.totalHidden++;
}
var size = parseInt(file.size, 10) || 0; var size = parseInt(file.size, 10) || 0;
if (size >=0) { if (size >=0) {
summary.totalSize += size; summary.totalSize += size;
@ -154,6 +199,13 @@
this.update(); this.update();
}, },
_infoTemplate: function(data) {
if (!this._infoTemplateCompiled) {
this._infoTemplateCompiled = Handlebars.compile(INFO_TEMPLATE);
}
return this._infoTemplateCompiled(data);
},
/** /**
* Renders the file summary element * Renders the file summary element
*/ */
@ -171,10 +223,12 @@
var $fileInfo = this.$el.find('.fileinfo'); var $fileInfo = this.$el.find('.fileinfo');
var $connector = this.$el.find('.connector'); var $connector = this.$el.find('.connector');
var $filterInfo = this.$el.find('.filter'); var $filterInfo = this.$el.find('.filter');
var $hiddenInfo = this.$el.find('.hiddeninfo');
// Substitute old content with new translations // Substitute old content with new translations
$dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs)); $dirInfo.html(n('files', '%n folder', '%n folders', this.summary.totalDirs));
$fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles)); $fileInfo.html(n('files', '%n file', '%n files', this.summary.totalFiles));
$hiddenInfo.html(' (' + n('files', 'including %n hidden', 'including %n hidden', this.summary.totalHidden) + ')');
var fileSize = this.summary.sumIsPending ? t('files', 'Pending') : OC.Util.humanFileSize(this.summary.totalSize); var fileSize = this.summary.sumIsPending ? t('files', 'Pending') : OC.Util.humanFileSize(this.summary.totalSize);
this.$el.find('.filesize').html(fileSize); this.$el.find('.filesize').html(fileSize);
@ -194,6 +248,7 @@
if (this.summary.totalDirs > 0 && this.summary.totalFiles > 0) { if (this.summary.totalDirs > 0 && this.summary.totalFiles > 0) {
$connector.removeClass('hidden'); $connector.removeClass('hidden');
} }
$hiddenInfo.toggleClass('hidden', this.summary.totalHidden === 0 || this._showHidden)
if (this.summary.filter === '') { if (this.summary.filter === '') {
$filterInfo.html(''); $filterInfo.html('');
$filterInfo.addClass('hidden'); $filterInfo.addClass('hidden');
@ -206,19 +261,7 @@
if (!this.$el) { if (!this.$el) {
return; return;
} }
// TODO: ideally this should be separate to a template or something
var summary = this.summary; 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 = '';
if (this.summary.filter !== '') {
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">',
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
};
// don't show the filesize column, if filesize is NaN (e.g. in trashbin) // don't show the filesize column, if filesize is NaN (e.g. in trashbin)
var fileSize = ''; var fileSize = '';
@ -227,15 +270,14 @@
fileSize = '<td class="filesize">' + fileSize + '</td>'; fileSize = '<td class="filesize">' + fileSize + '</td>';
} }
var info = t('files', '{dirs} and {files}', infoVars, null, {'escape': false}); var $summary = $(
'<td>' + this._infoTemplate() + '</td>' +
var $summary = $('<td><span class="info">'+info+'<span class="filter">'+filterInfo+'</span></span></td>'+fileSize+'<td class="date"></td>'); fileSize +
'<td class="date"></td>'
if (!this.summary.totalFiles && !this.summary.totalDirs) { );
this.$el.addClass('hidden'); this.$el.addClass('hidden');
}
this.$el.append($summary); this.$el.append($summary);
this.update();
} }
}; };
OCA.Files.FileSummary = FileSummary; OCA.Files.FileSummary = FileSummary;

View File

@ -385,8 +385,9 @@ describe('OCA.Files.FileList tests', function() {
$summary = $('#filestable .summary'); $summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
// yes, ugly... // yes, ugly...
expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); expect($summary.find('.fileinfo').text()).toEqual('1 file');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.connector').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.filesize').text()).toEqual('12 B'); expect($summary.find('.filesize').text()).toEqual('12 B');
expect($('#filestable thead th').hasClass('hidden')).toEqual(false); expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
@ -456,7 +457,8 @@ describe('OCA.Files.FileList tests', function() {
$summary = $('#filestable .summary'); $summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 2 files'); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('2 files');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.filesize').text()).toEqual('69 KB'); expect($summary.find('.filesize').text()).toEqual('69 KB');
@ -511,7 +513,8 @@ describe('OCA.Files.FileList tests', function() {
$summary = $('#filestable .summary'); $summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 1 file'); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('1 file');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false); expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.filesize').text()).toEqual('57 KB'); expect($summary.find('.filesize').text()).toEqual('57 KB');
@ -677,12 +680,14 @@ describe('OCA.Files.FileList tests', function() {
deferredRename.resolve(201); deferredRename.resolve(201);
expect($summary.find('.info').text()).toEqual('1 folder and 3 files'); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('3 files');
}); });
it('Leaves the summary alone when cancel renaming', function() { it('Leaves the summary alone when cancel renaming', function() {
var $summary = $('#filestable .summary'); var $summary = $('#filestable .summary');
doCancelRename(); doCancelRename();
expect($summary.find('.info').text()).toEqual('1 folder and 3 files'); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('3 files');
}); });
it('Shows busy state while rename in progress', function() { it('Shows busy state while rename in progress', function() {
var $tr; var $tr;
@ -856,11 +861,14 @@ describe('OCA.Files.FileList tests', function() {
}); });
var $tr = fileList.add(fileData); var $tr = fileList.add(fileData);
expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
var model = fileList.getModelForFile('test file'); var model = fileList.getModelForFile('test file');
model.set({size: '100'}); model.set({size: '100'});
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
}); });
}) })
describe('List rendering', function() { describe('List rendering', function() {
@ -877,7 +885,8 @@ describe('OCA.Files.FileList tests', function() {
fileList.setFiles(testFiles); fileList.setFiles(testFiles);
$summary = $('#filestable .summary'); $summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 3 files'); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('3 files');
expect($summary.find('.filesize').text()).toEqual('69 KB'); expect($summary.find('.filesize').text()).toEqual('69 KB');
}); });
it('shows headers, summary and hide empty content message after setting files', function(){ it('shows headers, summary and hide empty content message after setting files', function(){
@ -962,10 +971,12 @@ describe('OCA.Files.FileList tests', function() {
fileList.setFiles([testFiles[0]]); fileList.setFiles([testFiles[0]]);
$summary = $('#filestable .summary'); $summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
fileList.remove('unexist.txt'); fileList.remove('unexist.txt');
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('0 folders and 1 file'); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
}); });
}); });
describe('Filtered list rendering', function() { describe('Filtered list rendering', function() {
@ -987,14 +998,18 @@ describe('OCA.Files.FileList tests', function() {
expect($('#fileList tr:not(.hidden)').length).toEqual(3); expect($('#fileList tr:not(.hidden)').length).toEqual(3);
expect(fileList.files.length).toEqual(4); expect(fileList.files.length).toEqual(4);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'"); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('2 files');
expect($summary.find('.filter').text()).toEqual(" match 'e'");
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
fileList.setFilter('ee'); fileList.setFilter('ee');
expect($('#fileList tr:not(.hidden)').length).toEqual(1); expect($('#fileList tr:not(.hidden)').length).toEqual(1);
expect(fileList.files.length).toEqual(4); expect(fileList.files.length).toEqual(4);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'"); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
expect($summary.find('.filter').text()).toEqual(" matches 'ee'");
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
fileList.setFilter('eee'); fileList.setFilter('eee');
@ -1007,21 +1022,26 @@ describe('OCA.Files.FileList tests', function() {
expect($('#fileList tr:not(.hidden)').length).toEqual(1); expect($('#fileList tr:not(.hidden)').length).toEqual(1);
expect(fileList.files.length).toEqual(4); expect(fileList.files.length).toEqual(4);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches 'ee'"); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
expect($summary.find('.filter').text()).toEqual(" matches 'ee'");
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
fileList.setFilter('e'); fileList.setFilter('e');
expect($('#fileList tr:not(.hidden)').length).toEqual(3); expect($('#fileList tr:not(.hidden)').length).toEqual(3);
expect(fileList.files.length).toEqual(4); expect(fileList.files.length).toEqual(4);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("1 folder and 2 files match 'e'"); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('2 files');
expect($summary.find('.filter').text()).toEqual(" match 'e'");
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
fileList.setFilter(''); fileList.setFilter('');
expect($('#fileList tr:not(.hidden)').length).toEqual(4); expect($('#fileList tr:not(.hidden)').length).toEqual(4);
expect(fileList.files.length).toEqual(4); expect(fileList.files.length).toEqual(4);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("1 folder and 3 files"); expect($summary.find('.dirinfo').text()).toEqual('1 folder');
expect($summary.find('.fileinfo').text()).toEqual('3 files');
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
}); });
it('filters the list of non-rendered rows using filter()', function() { it('filters the list of non-rendered rows using filter()', function() {
@ -1032,7 +1052,9 @@ describe('OCA.Files.FileList tests', function() {
fileList.setFilter('63'); fileList.setFilter('63');
expect($('#fileList tr:not(.hidden)').length).toEqual(1); expect($('#fileList tr:not(.hidden)').length).toEqual(1);
expect($summary.hasClass('hidden')).toEqual(false); expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual("0 folders and 1 file matches '63'"); expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
expect($summary.find('.fileinfo').text()).toEqual('1 file');
expect($summary.find('.filter').text()).toEqual(" matches '63'");
expect($nofilterresults.hasClass('hidden')).toEqual(true); expect($nofilterresults.hasClass('hidden')).toEqual(true);
}); });
it('hides the emptyfiles notice when using filter()', function() { it('hides the emptyfiles notice when using filter()', function() {
@ -1654,6 +1676,18 @@ describe('OCA.Files.FileList tests', function() {
$('#fileList tr td.filename input:checkbox').click(); $('#fileList tr td.filename input:checkbox').click();
expect($('.select-all').prop('checked')).toEqual(false); expect($('.select-all').prop('checked')).toEqual(false);
}); });
it('Selecting all files also selects hidden files when invisible', function() {
filesConfig.set('showhidden', false);
var $tr = fileList.add(new FileInfo({
name: '.hidden',
type: 'dir',
mimetype: 'httpd/unix-directory',
size: 150
}));
$('.select-all').click();
expect($tr.find('td.filename input:checkbox').prop('checked')).toEqual(true);
expect(_.pluck(fileList.getSelectedFiles(), 'name')).toContain('.hidden');
});
it('Clicking "select all" will select/deselect all files', function() { it('Clicking "select all" will select/deselect all files', function() {
fileList.setFiles(generateFiles(0, 41)); fileList.setFiles(generateFiles(0, 41));
$('.select-all').click(); $('.select-all').click();
@ -1731,6 +1765,44 @@ describe('OCA.Files.FileList tests', function() {
fileList.findFileEl('One.txt').find('input:checkbox').click().click(); fileList.findFileEl('One.txt').find('input:checkbox').click().click();
expect($summary.text()).toEqual('Name'); expect($summary.text()).toEqual('Name');
}); });
it('Displays the number of hidden files in selection summary if hidden files are invisible', function() {
filesConfig.set('showhidden', false);
var $tr = fileList.add(new FileInfo({
name: '.hidden',
type: 'dir',
mimetype: 'httpd/unix-directory',
size: 150
}));
$('.select-all').click();
var $summary = $('#headerName a.name>span:first');
expect($summary.text()).toEqual('2 folders and 3 files (including 1 hidden)');
});
it('Does not displays the number of hidden files in selection summary if hidden files are visible', function() {
filesConfig.set('showhidden', true);
var $tr = fileList.add(new FileInfo({
name: '.hidden',
type: 'dir',
mimetype: 'httpd/unix-directory',
size: 150
}));
$('.select-all').click();
var $summary = $('#headerName a.name>span:first');
expect($summary.text()).toEqual('2 folders and 3 files');
});
it('Toggling hidden file visibility updates selection summary', function() {
filesConfig.set('showhidden', false);
var $tr = fileList.add(new FileInfo({
name: '.hidden',
type: 'dir',
mimetype: 'httpd/unix-directory',
size: 150
}));
$('.select-all').click();
var $summary = $('#headerName a.name>span:first');
expect($summary.text()).toEqual('2 folders and 3 files (including 1 hidden)');
filesConfig.set('showhidden', true);
expect($summary.text()).toEqual('2 folders and 3 files');
});
it('Select/deselect files shows/hides file actions', function() { it('Select/deselect files shows/hides file actions', function() {
var $actions = $('#headerName .selectedActions'); var $actions = $('#headerName .selectedActions');
var $checkbox = fileList.findFileEl('One.txt').find('input:checkbox'); var $checkbox = fileList.findFileEl('One.txt').find('input:checkbox');

View File

@ -39,7 +39,8 @@ describe('OCA.Files.FileSummary tests', function() {
totalSize: 256000 totalSize: 256000
}); });
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('5 folders and 2 files'); expect($container.find('.dirinfo').text()).toEqual('5 folders');
expect($container.find('.fileinfo').text()).toEqual('2 files');
expect($container.find('.filesize').text()).toEqual('250 KB'); expect($container.find('.filesize').text()).toEqual('250 KB');
}); });
it('hides summary when no files or folders', function() { it('hides summary when no files or folders', function() {
@ -62,7 +63,8 @@ describe('OCA.Files.FileSummary tests', function() {
s.add({type: 'dir', size: 100}); s.add({type: 'dir', size: 100});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('6 folders and 3 files'); expect($container.find('.dirinfo').text()).toEqual('6 folders');
expect($container.find('.fileinfo').text()).toEqual('3 files');
expect($container.find('.filesize').text()).toEqual('500 KB'); expect($container.find('.filesize').text()).toEqual('500 KB');
expect(s.summary.totalDirs).toEqual(6); expect(s.summary.totalDirs).toEqual(6);
expect(s.summary.totalFiles).toEqual(3); expect(s.summary.totalFiles).toEqual(3);
@ -79,7 +81,8 @@ describe('OCA.Files.FileSummary tests', function() {
s.remove({type: 'dir', size: 100}); s.remove({type: 'dir', size: 100});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('4 folders and 1 file'); expect($container.find('.dirinfo').text()).toEqual('4 folders');
expect($container.find('.fileinfo').text()).toEqual('1 file');
expect($container.find('.filesize').text()).toEqual('125 KB'); expect($container.find('.filesize').text()).toEqual('125 KB');
expect(s.summary.totalDirs).toEqual(4); expect(s.summary.totalDirs).toEqual(4);
expect(s.summary.totalFiles).toEqual(1); expect(s.summary.totalFiles).toEqual(1);
@ -95,7 +98,9 @@ describe('OCA.Files.FileSummary tests', function() {
filter: 'foo' filter: 'foo'
}); });
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('5 folders and 2 files match \'foo\''); expect($container.find('.dirinfo').text()).toEqual('5 folders');
expect($container.find('.fileinfo').text()).toEqual('2 files');
expect($container.find('.filter').text()).toEqual(' match \'foo\'');
expect($container.find('.filesize').text()).toEqual('250 KB'); expect($container.find('.filesize').text()).toEqual('250 KB');
}); });
it('hides filtered summary when no files or folders', function() { it('hides filtered summary when no files or folders', function() {
@ -122,7 +127,9 @@ describe('OCA.Files.FileSummary tests', function() {
s.add({name: 'foo', type: 'dir', size: 102}); s.add({name: 'foo', type: 'dir', size: 102});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('6 folders and 3 files match \'foo\''); expect($container.find('.dirinfo').text()).toEqual('6 folders');
expect($container.find('.fileinfo').text()).toEqual('3 files');
expect($container.find('.filter').text()).toEqual(' match \'foo\'');
expect($container.find('.filesize').text()).toEqual('500 KB'); expect($container.find('.filesize').text()).toEqual('500 KB');
expect(s.summary.totalDirs).toEqual(6); expect(s.summary.totalDirs).toEqual(6);
expect(s.summary.totalFiles).toEqual(3); expect(s.summary.totalFiles).toEqual(3);
@ -142,7 +149,9 @@ describe('OCA.Files.FileSummary tests', function() {
s.remove({name: 'foo', type: 'dir', size: 98}); s.remove({name: 'foo', type: 'dir', size: 98});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('4 folders and 1 file match \'foo\''); expect($container.find('.dirinfo').text()).toEqual('4 folders');
expect($container.find('.fileinfo').text()).toEqual('1 file');
expect($container.find('.filter').text()).toEqual(' match \'foo\'');
expect($container.find('.filesize').text()).toEqual('125 KB'); expect($container.find('.filesize').text()).toEqual('125 KB');
expect(s.summary.totalDirs).toEqual(4); expect(s.summary.totalDirs).toEqual(4);
expect(s.summary.totalFiles).toEqual(1); expect(s.summary.totalFiles).toEqual(1);
@ -158,7 +167,8 @@ describe('OCA.Files.FileSummary tests', function() {
s.add({type: 'dir', size: -1}); s.add({type: 'dir', size: -1});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(false); expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('1 folder and 0 files'); expect($container.find('.dirinfo').text()).toEqual('1 folder');
expect($container.find('.fileinfo').hasClass('hidden')).toEqual(true);
expect($container.find('.filesize').text()).toEqual('Pending'); expect($container.find('.filesize').text()).toEqual('Pending');
expect(s.summary.totalDirs).toEqual(1); expect(s.summary.totalDirs).toEqual(1);
expect(s.summary.totalFiles).toEqual(0); expect(s.summary.totalFiles).toEqual(0);
@ -175,10 +185,56 @@ describe('OCA.Files.FileSummary tests', function() {
s.remove({type: 'dir', size: -1}); s.remove({type: 'dir', size: -1});
s.update(); s.update();
expect($container.hasClass('hidden')).toEqual(true); expect($container.hasClass('hidden')).toEqual(true);
expect($container.find('.info').text()).toEqual('0 folders and 0 files');
expect($container.find('.filesize').text()).toEqual('0 B');
expect(s.summary.totalDirs).toEqual(0); expect(s.summary.totalDirs).toEqual(0);
expect(s.summary.totalFiles).toEqual(0); expect(s.summary.totalFiles).toEqual(0);
expect(s.summary.totalSize).toEqual(0); expect(s.summary.totalSize).toEqual(0);
}); });
describe('hidden files', function() {
var config;
var summary;
beforeEach(function() {
config = new OC.Backbone.Model();
summary = new FileSummary($container, {
config: config
});
});
it('renders hidden count section when hidden files are hidden', function() {
config.set('showhidden', false);
summary.add({name: 'abc', type: 'file', size: 256000});
summary.add({name: 'def', type: 'dir', size: 100});
summary.add({name: '.hidden', type: 'dir', size: 512000});
summary.update();
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.dirinfo').text()).toEqual('2 folders');
expect($container.find('.fileinfo').text()).toEqual('1 file');
expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(false);
expect($container.find('.hiddeninfo').text()).toEqual(' (including 1 hidden)');
expect($container.find('.filesize').text()).toEqual('750 KB');
});
it('does not render hidden count section when hidden files exist but are visible', function() {
config.set('showhidden', true);
summary.add({name: 'abc', type: 'file', size: 256000});
summary.add({name: 'def', type: 'dir', size: 100});
summary.add({name: '.hidden', type: 'dir', size: 512000});
summary.update();
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.dirinfo').text()).toEqual('2 folders');
expect($container.find('.fileinfo').text()).toEqual('1 file');
expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
expect($container.find('.filesize').text()).toEqual('750 KB');
});
it('does not render hidden count section when no hidden files exist', function() {
config.set('showhidden', false);
summary.add({name: 'abc', type: 'file', size: 256000});
summary.add({name: 'def', type: 'dir', size: 100});
summary.update();
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.dirinfo').text()).toEqual('1 folder');
expect($container.find('.fileinfo').text()).toEqual('1 file');
expect($container.find('.hiddeninfo').hasClass('hidden')).toEqual(true);
expect($container.find('.filesize').text()).toEqual('250 KB');
});
});
}); });