Fix file summary to use the whole file list

- moved the summary code into a new class FileSummary
- FileSummary is calculated only once, then updated with add/remove
- added new OC.Util namespace for JS utility functions
remotes/origin/ldap_group_count
Vincent Petry 12 years ago
parent efdf0c4df0
commit 9f62059efa
  1. 1
      apps/files/index.php
  2. 136
      apps/files/js/filelist.js
  3. 176
      apps/files/js/filesummary.js
  4. 2
      apps/files/templates/index.php
  5. 48
      apps/files/tests/js/filelistSpec.js
  6. 87
      apps/files/tests/js/filesummarySpec.js
  7. 1
      apps/files_sharing/public.php
  8. 1
      apps/files_trashbin/index.php
  9. 6
      apps/files_trashbin/js/trash.js
  10. 2
      apps/files_trashbin/templates/index.php
  11. 3
      core/js/js.js
  12. 17
      core/js/tests/specs/coreSpec.js

@ -32,6 +32,7 @@ OCP\Util::addscript('files', 'file-upload');
OCP\Util::addscript('files', 'jquery.iframe-transport');
OCP\Util::addscript('files', 'jquery.fileupload');
OCP\Util::addscript('files', 'jquery-visibility');
OCP\Util::addscript('files', 'filesummary');
OCP\Util::addscript('files', 'breadcrumb');
OCP\Util::addscript('files', 'filelist');

@ -8,7 +8,7 @@
*
*/
/* global OC, t, n, FileList, FileActions, Files, BreadCrumb */
/* global OC, t, n, FileList, FileActions, Files, FileSummary, BreadCrumb */
/* global procesSelection, dragOptions, folderDropOptions */
window.FileList = {
appName: t('files', 'Files'),
@ -17,6 +17,11 @@ window.FileList = {
$el: $('#filestable'),
$fileList: $('#fileList'),
breadcrumb: null,
/**
* Instance of FileSummary
*/
fileSummary: null,
initialized: false,
// number of files per page
@ -38,6 +43,8 @@ window.FileList = {
this.$el = $('#filestable');
this.$fileList = $('#fileList');
this.fileSummary = this._createSummary();
this.breadcrumb = new BreadCrumb({
onClick: this._onClickBreadCrumb,
onDrop: this._onDropOnBreadCrumb,
@ -72,7 +79,6 @@ window.FileList = {
if (this.pageNumber + 1 >= this.totalPages) {
return;
}
var target = $(document);
if ($(window).scrollTop() + $(window).height() > $(document).height() - 20) {
this._nextPage(true);
}
@ -206,7 +212,9 @@ window.FileList = {
if (window.Files) {
Files.setupDragAndDrop();
}
this.updateFileSummary();
this.fileSummary.calculate(filesArray);
procesSelection();
$(window).scrollTop(0);
@ -404,7 +412,7 @@ window.FileList = {
// defaults to true if not defined
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
this.updateFileSummary();
this.fileSummary.add(fileData, true);
this.updateEmptyContent();
}
return tr;
@ -582,10 +590,10 @@ window.FileList = {
}
fileEl.remove();
// TODO: improve performance on batch update
FileList.isEmpty = !this.$fileList.find('tr:not(.summary)').length;
FileList.isEmpty = !this.$fileList.find('tr').length;
if (typeof(options.updateSummary) === 'undefined' || !!options.updateSummary) {
FileList.updateEmptyContent();
FileList.updateFileSummary();
this.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')}, true);
}
return fileEl;
},
@ -621,7 +629,6 @@ window.FileList = {
}
FileList.isEmpty = false;
FileList.updateEmptyContent();
FileList.updateFileSummary();
},
rename: function(oldname) {
var tr, td, input, form;
@ -825,12 +832,13 @@ window.FileList = {
var fileEl = FileList.remove(file, {updateSummary: false});
fileEl.find('input[type="checkbox"]').prop('checked', false);
fileEl.removeClass('selected');
FileList.fileSummary.remove({type: fileEl.attr('data-type'), size: fileEl.attr('data-size')});
});
}
procesSelection();
checkTrashStatus();
FileList.updateFileSummary();
FileList.updateEmptyContent();
FileList.fileSummary.update();
Files.updateStorageStatistics();
} else {
if (result.status === 'error' && result.data.message) {
@ -857,108 +865,14 @@ window.FileList = {
}
});
},
createFileSummary: function() {
if ( !FileList.isEmpty ) {
var summary = this._calculateFileSummary();
// Get translations
var directoryInfo = n('files', '%n folder', '%n folders', summary.totalDirs);
var fileInfo = n('files', '%n file', '%n files', summary.totalFiles);
var infoVars = {
dirs: '<span class="dirinfo">'+directoryInfo+'</span><span class="connector">',
files: '</span><span class="fileinfo">'+fileInfo+'</span>'
};
var info = t('files', '{dirs} and {files}', infoVars);
// don't show the filesize column, if filesize is NaN (e.g. in trashbin)
var fileSize = '';
if (!isNaN(summary.totalSize)) {
fileSize = '<td class="filesize">'+humanFileSize(summary.totalSize)+'</td>';
}
var $summary = $('<tr class="summary" data-file="undefined"><td><span class="info">'+info+'</span></td>'+fileSize+'<td></td></tr>');
this.$fileList.append($summary);
var $dirInfo = $summary.find('.dirinfo');
var $fileInfo = $summary.find('.fileinfo');
var $connector = $summary.find('.connector');
/**
* Creates the file summary section
*/
_createSummary: function() {
var $tr = $('<tr class="summary"></tr>');
this.$el.find('tfoot').append($tr);
// Show only what's necessary, e.g.: no files: don't show "0 files"
if (summary.totalDirs === 0) {
$dirInfo.addClass('hidden');
$connector.addClass('hidden');
}
if (summary.totalFiles === 0) {
$fileInfo.addClass('hidden');
$connector.addClass('hidden');
}
}
},
_calculateFileSummary: function() {
var result = {
totalDirs: 0,
totalFiles: 0,
totalSize: 0
};
$.each($('tr[data-file]'), function(index, value) {
var $value = $(value);
if ($value.data('type') === 'dir') {
result.totalDirs++;
} else if ($value.data('type') === 'file') {
result.totalFiles++;
}
if ($value.data('size') !== undefined && $value.data('id') !== -1) {
//Skip shared as it does not count toward quota
result.totalSize += parseInt($value.data('size'));
}
});
return result;
},
updateFileSummary: function() {
var $summary = this.$el.find('.summary');
// always make it the last element
this.$fileList.append($summary.detach());
// Check if we should remove the summary to show "Upload something"
if (this.isEmpty && $summary.length === 1) {
$summary.remove();
}
// If there's no summary create one (createFileSummary checks if there's data)
else if ($summary.length === 0) {
FileList.createFileSummary();
}
// There's a summary and data -> Update the summary
else if (!this.isEmpty && $summary.length === 1) {
var fileSummary = this._calculateFileSummary();
var $dirInfo = $('.summary .dirinfo');
var $fileInfo = $('.summary .fileinfo');
var $connector = $('.summary .connector');
// Substitute old content with new translations
$dirInfo.html(n('files', '%n folder', '%n folders', fileSummary.totalDirs));
$fileInfo.html(n('files', '%n file', '%n files', fileSummary.totalFiles));
$('.summary .filesize').html(humanFileSize(fileSummary.totalSize));
// Show only what's necessary (may be hidden)
if (fileSummary.totalDirs === 0) {
$dirInfo.addClass('hidden');
$connector.addClass('hidden');
} else {
$dirInfo.removeClass('hidden');
}
if (fileSummary.totalFiles === 0) {
$fileInfo.addClass('hidden');
$connector.addClass('hidden');
} else {
$fileInfo.removeClass('hidden');
}
if (fileSummary.totalDirs > 0 && fileSummary.totalFiles > 0) {
$connector.removeClass('hidden');
}
}
return new FileSummary($tr);
},
updateEmptyContent: function() {
var permissions = $('#permissions').val();
@ -1009,7 +923,7 @@ window.FileList = {
}
},
filter:function(query) {
$('#fileList tr:not(.summary)').each(function(i,e) {
$('#fileList tr').each(function(i,e) {
if ($(e).data('file').toString().toLowerCase().indexOf(query.toLowerCase()) !== -1) {
$(e).addClass("searchresult");
} else {
@ -1315,7 +1229,5 @@ $(document).ready(function() {
setTimeout(function() {
FileList.changeDirectory(dir, false, true);
}, 0);
FileList.createFileSummary();
});

@ -0,0 +1,176 @@
/**
* ownCloud
*
* @author Vincent Petry
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* global OC, n, t */
(function() {
/**
* The FileSummary class encapsulates the file summary values and
* the logic to render it in the given container
* @param $tr table row element
* $param summary optional initial summary value
*/
var FileSummary = function($tr, summary) {
this.$el = $tr;
this.render();
};
FileSummary.prototype = {
summary: {
totalFiles: 0,
totalDirs: 0,
totalSize: 0
},
/**
* Adds file
* @param file file to add
* @param update whether to update the display
*/
add: function(file, update) {
if (file.type === 'dir' || file.mime === 'httpd/unix-directory') {
this.summary.totalDirs++;
}
else {
this.summary.totalFiles++;
}
this.summary.totalSize += parseInt(file.size, 10) || 0;
if (!!update) {
this.update();
}
},
/**
* Removes file
* @param file file to remove
* @param update whether to update the display
*/
remove: function(file, update) {
if (file.type === 'dir' || file.mime === 'httpd/unix-directory') {
this.summary.totalDirs--;
}
else {
this.summary.totalFiles--;
}
this.summary.totalSize -= parseInt(file.size, 10) || 0;
if (!!update) {
this.update();
}
},
/**
* Recalculates the summary based on the given files array
* @param files array of files
*/
calculate: function(files) {
var file;
var summary = {
totalDirs: 0,
totalFiles: 0,
totalSize: 0
};
for (var i = 0; i < files.length; i++) {
file = files[i];
if (file.type === 'dir' || file.mime === 'httpd/unix-directory') {
summary.totalDirs++;
}
else {
summary.totalFiles++;
}
summary.totalSize += parseInt(file.size, 10) || 0;
}
this.setSummary(summary);
},
/**
* Sets the current summary values
* @param summary map
*/
setSummary: function(summary) {
this.summary = summary;
this.update();
},
/**
* Renders the file summary element
*/
update: function() {
if (!this.summary.totalFiles && !this.summary.totalDirs) {
this.$el.addClass('hidden');
return;
}
// There's a summary and data -> Update the summary
this.$el.removeClass('hidden');
var $dirInfo = this.$el.find('.dirinfo');
var $fileInfo = this.$el.find('.fileinfo');
var $connector = this.$el.find('.connector');
// 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));
this.$el.find('.filesize').html(OC.Util.humanFileSize(this.summary.totalSize));
// Show only what's necessary (may be hidden)
if (this.summary.totalDirs === 0) {
$dirInfo.addClass('hidden');
$connector.addClass('hidden');
} else {
$dirInfo.removeClass('hidden');
}
if (this.summary.totalFiles === 0) {
$fileInfo.addClass('hidden');
$connector.addClass('hidden');
} else {
$fileInfo.removeClass('hidden');
}
if (this.summary.totalDirs > 0 && this.summary.totalFiles > 0) {
$connector.removeClass('hidden');
}
},
render: function() {
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 fileSize;
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)
var fileSize = '';
if (!isNaN(summary.totalSize)) {
fileSize = '<td class="filesize">' + OC.Util.humanFileSize(summary.totalSize) + '</td>';
}
var info = t('files', '{dirs} and {files}', infoVars);
var $summary = $('<td><span class="info">'+info+'</span></td>'+fileSize+'<td></td>');
if (!this.summary.totalFiles && !this.summary.totalDirs) {
this.$el.addClass('hidden');
}
this.$el.append($summary);
}
};
window.FileSummary = FileSummary;
})();

@ -91,6 +91,8 @@
</thead>
<tbody id="fileList">
</tbody>
<tfoot>
</tfoot>
</table>
<div id="editor"></div><!-- FIXME Do not use this div in your app! It is deprecated and will be removed in the future! -->
<div id="uploadsize-message" title="<?php p($l->t('Upload too large'))?>">

@ -51,6 +51,7 @@ describe('FileList tests', function() {
'<table id="filestable">' +
'<thead><tr><th class="hidden">Name</th></tr></thead>' +
'<tbody id="fileList"></tbody>' +
'<tfoot></tfoot>' +
'</table>' +
'<div id="emptycontent">Empty content message</div>'
);
@ -220,7 +221,7 @@ describe('FileList tests', function() {
var $tr = FileList.add(fileData);
expect($tr.find('.filesize').text()).toEqual('0 B');
});
it('adds new file to the end of the list before the summary', function() {
it('adds new file to the end of the list', function() {
var fileData = {
type: 'file',
name: 'P comes after O.txt'
@ -228,7 +229,6 @@ describe('FileList tests', function() {
FileList.setFiles(testFiles);
$tr = FileList.add(fileData);
expect($tr.index()).toEqual(4);
expect($tr.next().hasClass('summary')).toEqual(true);
});
it('adds new file at correct position in insert mode', function() {
var fileData = {
@ -249,8 +249,8 @@ describe('FileList tests', function() {
FileList.setFiles([]);
expect(FileList.isEmpty).toEqual(true);
FileList.add(fileData);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(1);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false);
// yes, ugly...
expect($summary.find('.info').text()).toEqual('0 folders and 1 file');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(true);
@ -268,11 +268,11 @@ describe('FileList tests', function() {
$removedEl = FileList.remove('One.txt');
expect($removedEl).toBeDefined();
expect($removedEl.attr('data-file')).toEqual('One.txt');
expect($('#fileList tr:not(.summary)').length).toEqual(3);
expect($('#fileList tr').length).toEqual(3);
expect(FileList.findFileEl('One.txt').length).toEqual(0);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(1);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 2 files');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
@ -282,11 +282,11 @@ describe('FileList tests', function() {
it('Shows empty content when removing last file', function() {
FileList.setFiles([testFiles[0]]);
FileList.remove('One.txt');
expect($('#fileList tr:not(.summary)').length).toEqual(0);
expect($('#fileList tr').length).toEqual(0);
expect(FileList.findFileEl('One.txt').length).toEqual(0);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(0);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(true);
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
expect(FileList.isEmpty).toEqual(true);
@ -318,10 +318,10 @@ describe('FileList tests', function() {
expect(FileList.findFileEl('One.txt').length).toEqual(0);
expect(FileList.findFileEl('Two.jpg').length).toEqual(0);
expect(FileList.findFileEl('Three.pdf').length).toEqual(1);
expect(FileList.$fileList.find('tr:not(.summary)').length).toEqual(2);
expect(FileList.$fileList.find('tr').length).toEqual(2);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(1);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 1 file');
expect($summary.find('.dirinfo').hasClass('hidden')).toEqual(false);
expect($summary.find('.fileinfo').hasClass('hidden')).toEqual(false);
@ -342,10 +342,10 @@ describe('FileList tests', function() {
JSON.stringify({status: 'success'})
);
expect(FileList.$fileList.find('tr:not(.summary)').length).toEqual(0);
expect(FileList.$fileList.find('tr').length).toEqual(0);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(0);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(true);
expect(FileList.isEmpty).toEqual(true);
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
@ -363,7 +363,7 @@ describe('FileList tests', function() {
// files are still in the list
expect(FileList.findFileEl('One.txt').length).toEqual(1);
expect(FileList.findFileEl('Two.jpg').length).toEqual(1);
expect(FileList.$fileList.find('tr:not(.summary)').length).toEqual(4);
expect(FileList.$fileList.find('tr').length).toEqual(4);
expect(notificationStub.calledOnce).toEqual(true);
});
@ -459,14 +459,14 @@ describe('FileList tests', function() {
var addSpy = sinon.spy(FileList, 'add');
FileList.setFiles(testFiles);
expect(addSpy.callCount).toEqual(4);
expect($('#fileList tr:not(.summary)').length).toEqual(4);
expect($('#fileList tr').length).toEqual(4);
addSpy.restore();
});
it('updates summary using the file sizes', function() {
var $summary;
FileList.setFiles(testFiles);
$summary = $('#fileList .summary');
expect($summary.length).toEqual(1);
$summary = $('#filestable .summary');
expect($summary.hasClass('hidden')).toEqual(false);
expect($summary.find('.info').text()).toEqual('1 folder and 3 files');
expect($summary.find('.filesize').text()).toEqual('69 kB');
});
@ -474,20 +474,20 @@ describe('FileList tests', function() {
FileList.setFiles(testFiles);
expect($('#filestable thead th').hasClass('hidden')).toEqual(false);
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
expect(FileList.$fileList.find('.summary').length).toEqual(1);
expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(false);
});
it('hides headers, summary and show empty content message after setting empty file list', function(){
FileList.setFiles([]);
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
expect($('#emptycontent').hasClass('hidden')).toEqual(false);
expect(FileList.$fileList.find('.summary').length).toEqual(0);
expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(true);
});
it('hides headers, empty content message, and summary when list is empty and user has no creation permission', function(){
$('#permissions').val(0);
FileList.setFiles([]);
expect($('#filestable thead th').hasClass('hidden')).toEqual(true);
expect($('#emptycontent').hasClass('hidden')).toEqual(true);
expect(FileList.$fileList.find('.summary').length).toEqual(0);
expect(FileList.$el.find('.summary').hasClass('hidden')).toEqual(true);
});
it('calling findFileEl() can find existing file element', function() {
FileList.setFiles(testFiles);
@ -642,7 +642,7 @@ describe('FileList tests', function() {
var query = url.substr(url.indexOf('?') + 1);
expect(OC.parseQueryString(query)).toEqual({'dir': '/subdir'});
fakeServer.respond();
expect($('#fileList tr:not(.summary)').length).toEqual(4);
expect($('#fileList tr').length).toEqual(4);
expect(FileList.findFileEl('One.txt').length).toEqual(1);
});
it('switches dir and fetches file list when calling changeDirectory()', function() {

@ -0,0 +1,87 @@
/**
* ownCloud
*
* @author Vincent Petry
* @copyright 2014 Vincent Petry <pvince81@owncloud.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/* global FileSummary */
describe('FileSummary tests', function() {
var $container;
beforeEach(function() {
$container = $('<table><tr></tr></table>').find('tr');
});
afterEach(function() {
$container = null;
});
it('renders summary as text', function() {
var s = new FileSummary($container);
s.setSummary({
totalDirs: 5,
totalFiles: 2,
totalSize: 256000
});
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('5 folders and 2 files');
expect($container.find('.filesize').text()).toEqual('250 kB');
});
it('hides summary when no files or folders', function() {
var s = new FileSummary($container);
s.setSummary({
totalDirs: 0,
totalFiles: 0,
totalSize: 0
});
expect($container.hasClass('hidden')).toEqual(true);
});
it('increases summary when adding files', function() {
var s = new FileSummary($container);
s.setSummary({
totalDirs: 5,
totalFiles: 2,
totalSize: 256000
});
s.add({type: 'file', size: 256000});
s.add({type: 'dir', size: 100});
s.update();
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('6 folders and 3 files');
expect($container.find('.filesize').text()).toEqual('500 kB');
expect(s.summary.totalDirs).toEqual(6);
expect(s.summary.totalFiles).toEqual(3);
expect(s.summary.totalSize).toEqual(512100);
});
it('decreases summary when removing files', function() {
var s = new FileSummary($container);
s.setSummary({
totalDirs: 5,
totalFiles: 2,
totalSize: 256000
});
s.remove({type: 'file', size: 128000});
s.remove({type: 'dir', size: 100});
s.update();
expect($container.hasClass('hidden')).toEqual(false);
expect($container.find('.info').text()).toEqual('4 folders and 1 file');
expect($container.find('.filesize').text()).toEqual('125 kB');
expect(s.summary.totalDirs).toEqual(4);
expect(s.summary.totalFiles).toEqual(1);
expect(s.summary.totalSize).toEqual(127900);
});
});

@ -138,6 +138,7 @@ if (isset($path)) {
OCP\Util::addStyle('files', 'files');
OCP\Util::addStyle('files', 'upload');
OCP\Util::addScript('files', 'filesummary');
OCP\Util::addScript('files', 'breadcrumb');
OCP\Util::addScript('files', 'files');
OCP\Util::addScript('files', 'filelist');

@ -11,6 +11,7 @@ $tmpl = new OCP\Template('files_trashbin', 'index', 'user');
OCP\Util::addStyle('files', 'files');
OCP\Util::addStyle('files_trashbin', 'trash');
OCP\Util::addScript('files', 'filesummary');
OCP\Util::addScript('files', 'breadcrumb');
OCP\Util::addScript('files', 'filelist');
// filelist overrides

@ -34,10 +34,12 @@ $(document).ready(function() {
}
var files = result.data.success;
var $el;
for (var i = 0; i < files.length; i++) {
FileList.remove(OC.basename(files[i].filename), {updateSummary: false});
$el = FileList.remove(OC.basename(files[i].filename), {updateSummary: false});
FileList.fileSummary.remove({type: $el.attr('data-type'), size: $el.attr('data-size')});
}
FileList.updateFileSummary();
FileList.fileSummary.update();
FileList.updateEmptyContent();
enableActions();
}

@ -40,4 +40,6 @@
</thead>
<tbody id="fileList">
</tbody>
<tfoot>
</tfoot>
</table>

@ -1253,6 +1253,9 @@ function relative_modified_date(timestamp) {
* @todo Write documentation
*/
OC.Util = {
// TODO: remove original functions from global namespace
humanFileSize: humanFileSize,
formatDate: formatDate,
/**
* Returns whether the browser supports SVG
* @return {boolean} true if the browser supports SVG, false otherwise

@ -474,5 +474,22 @@ describe('Core base tests', function() {
);
});
});
describe('Util', function() {
describe('humanFileSize', function() {
it('renders file sizes with the correct unit', function() {
var data = [
[0, '0 B'],
[125, '125 B'],
[128000, '125 kB'],
[128000000, '122.1 MB'],
[128000000000, '119.2 GB'],
[128000000000000, '116.4 TB']
];
for (var i = 0; i < data.length; i++) {
expect(OC.Util.humanFileSize(data[i][0])).toEqual(data[i][1]);
}
});
});
});
});

Loading…
Cancel
Save