diff options
author | Vincent Petry <pvince81@owncloud.com> | 2014-05-12 19:54:20 +0200 |
---|---|---|
committer | Vincent Petry <pvince81@owncloud.com> | 2014-05-15 17:51:04 +0200 |
commit | 6fd084243b65a556d4775209ba3916145ef5912a (patch) | |
tree | 6162c2af1861d8e3b8bbf1340ac55c4affc5ad61 /apps/files_trashbin | |
parent | 9d38e3602b2faf37d861729c52690ce51b8fee97 (diff) | |
download | nextcloud-server-6fd084243b65a556d4775209ba3916145ef5912a.tar.gz nextcloud-server-6fd084243b65a556d4775209ba3916145ef5912a.zip |
Fixed many issues, clean up
- fixed upload and storage statistics
- fixed infinite scroll to use the correct contain for scroll detection
- fixed unit test that sometimes fail for rename case
- controls are now sticky again
- fixed selection overlay to be aligned with the table
- fixed "select all" checkbox that had id conflicts
- fixed public page
- fixed global actions permissions detection
- fix when URL contains an invalid view id
- viewer mode now hides the sidebar (ex: text editor)
- added unit tests for trashbin
- clean up storage info in template (most is retrieved via ajax call now)
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r-- | apps/files_trashbin/appinfo/app.php | 2 | ||||
-rw-r--r-- | apps/files_trashbin/css/trash.css | 13 | ||||
-rw-r--r-- | apps/files_trashbin/js/app.js | 8 | ||||
-rw-r--r-- | apps/files_trashbin/js/filelist.js | 30 | ||||
-rw-r--r-- | apps/files_trashbin/js/files.js | 23 | ||||
-rw-r--r-- | apps/files_trashbin/list.php (renamed from apps/files_trashbin/index.php) | 1 | ||||
-rw-r--r-- | apps/files_trashbin/templates/index.php | 4 | ||||
-rw-r--r-- | apps/files_trashbin/tests/js/filelistSpec.js | 140 |
8 files changed, 156 insertions, 65 deletions
diff --git a/apps/files_trashbin/appinfo/app.php b/apps/files_trashbin/appinfo/app.php index 06c2e3447fe..b8900ee0de3 100644 --- a/apps/files_trashbin/appinfo/app.php +++ b/apps/files_trashbin/appinfo/app.php @@ -8,7 +8,7 @@ $l = OC_L10N::get('files_trashbin'); array( "id" => 'trashbin', "appname" => 'files_trashbin', - "script" => 'index.php', + "script" => 'list.php', "order" => 1, "name" => $l->t('Deleted files') ) diff --git a/apps/files_trashbin/css/trash.css b/apps/files_trashbin/css/trash.css index 7ca3e355fc2..04b4a175c83 100644 --- a/apps/files_trashbin/css/trash.css +++ b/apps/files_trashbin/css/trash.css @@ -1,4 +1,13 @@ -#fileList tr[data-type="file"] td a.name, -#fileList tr[data-type="file"] td a.name span { +/* + * Copyright (c) 2014 + * + * This file is licensed under the Affero General Public License version 3 + * or later. + * + * See the COPYING-README file. + * + */ +#app-content-trashbin tbody tr[data-type="file"] td a.name, +#app-content-trashbin tbody tr[data-type="file"] td a.name span { cursor: default; } diff --git a/apps/files_trashbin/js/app.js b/apps/files_trashbin/js/app.js index 9ab78e7cbb3..aa499ae1791 100644 --- a/apps/files_trashbin/js/app.js +++ b/apps/files_trashbin/js/app.js @@ -17,7 +17,11 @@ OCA.Trashbin.App = { return; } this._initialized = true; - this.fileList = new OCA.Trashbin.FileList($el); + this.fileList = new OCA.Trashbin.FileList( + $('#app-content-trashbin'), { + scrollContainer: $('#app-content') + } + ); this.registerFileActions(this.fileList); }, @@ -68,7 +72,7 @@ OCA.Trashbin.App = { }; $(document).ready(function() { - $('#app-content-trashbin').on('show', function() { + $('#app-content-trashbin').one('show', function() { var App = OCA.Trashbin.App; App.initialize($('#app-content-trashbin')); // force breadcrumb init diff --git a/apps/files_trashbin/js/filelist.js b/apps/files_trashbin/js/filelist.js index d3206958e8b..205f879f335 100644 --- a/apps/files_trashbin/js/filelist.js +++ b/apps/files_trashbin/js/filelist.js @@ -30,6 +30,7 @@ this.initialize($el); }; FileList.prototype = _.extend({}, OCA.Files.FileList.prototype, { + id: 'trashbin', appName: t('files_trashbin', 'Deleted files'), initialize: function() { @@ -37,11 +38,6 @@ this.$el.find('.undelete').click('click', _.bind(this._onClickRestoreSelected, this)); this.setSort('mtime', 'desc'); - - // override crumb URL maker - this.breadcrumb.getCrumbUrl = function(part, index) { - return OC.linkTo('files_trashbin', 'index.php')+"?view=trashbin&dir=" + encodeURIComponent(part.dir); - }; /** * Override crumb making to add "Deleted Files" entry * and convert files with ".d" extensions to a more @@ -58,6 +54,13 @@ return result; }, + /** + * Override to only return read permissions + */ + getDirectoryPermissions: function() { + return OC.PERMISSION_READ | OC.PERMISSION_DELETE; + }, + _setCurrentDir: function(targetDir) { OCA.Files.FileList.prototype._setCurrentDir.apply(this, arguments); @@ -97,8 +100,12 @@ return OC.filePath('files_trashbin', 'ajax', action + '.php') + q; }, + setupUploadEvents: function() { + // override and do nothing + }, + linkTo: function(dir){ - return OC.linkTo('files_trashbin', 'index.php')+"?dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); + return OC.linkTo('files', 'index.php')+"?view=trashbin&dir="+ encodeURIComponent(dir).replace(/%2F/g, '/'); }, updateEmptyContent: function(){ @@ -126,7 +133,7 @@ _onClickRestoreSelected: function(event) { event.preventDefault(); var self = this; - var allFiles = this.$el.find('#select_all').is(':checked'); + var allFiles = this.$el.find('.select-all').is(':checked'); var files = []; var params = {}; this.disableActions(); @@ -171,7 +178,7 @@ _onClickDeleteSelected: function(event) { event.preventDefault(); var self = this; - var allFiles = this.$el.find('#select_all').is(':checked'); + var allFiles = this.$el.find('.select-all').is(':checked'); var files = []; var params = {}; if (allFiles) { @@ -230,7 +237,7 @@ return OC.generateUrl('/apps/files_trashbin/ajax/preview.php?') + $.param(urlSpec); }, - getDownloadUrl: function(action, params) { + getDownloadUrl: function() { // no downloads return '#'; }, @@ -243,6 +250,11 @@ disableActions: function() { this.$el.find('.action').css('display', 'none'); this.$el.find(':input:checkbox').css('display', 'none'); + }, + + updateStorageStatistics: function() { + // no op because the trashbin doesn't have + // storage info like free space / used space } }); diff --git a/apps/files_trashbin/js/files.js b/apps/files_trashbin/js/files.js deleted file mode 100644 index f46b96a40b3..00000000000 --- a/apps/files_trashbin/js/files.js +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2014 - * - * This file is licensed under the Affero General Public License version 3 - * or later. - * - * See the COPYING-README file. - * - */ - -(function() { - - var Files = _.extend({}, OCA.Files.Files, { - updateStorageStatistics: function() { - // no op because the trashbin doesn't have - // storage info like free space / used space - } - - }); - - OCA.Trashbin.Files = Files; -})(); - diff --git a/apps/files_trashbin/index.php b/apps/files_trashbin/list.php index 08227b7f322..b4047b82ef9 100644 --- a/apps/files_trashbin/index.php +++ b/apps/files_trashbin/list.php @@ -7,6 +7,5 @@ OCP\User::checkLoggedIn(); $tmpl = new OCP\Template('files_trashbin', 'index', ''); OCP\Util::addStyle('files_trashbin', 'trash'); OCP\Util::addScript('files_trashbin', 'app'); -OCP\Util::addScript('files_trashbin', 'files'); OCP\Util::addScript('files_trashbin', 'filelist'); $tmpl->printPage(); diff --git a/apps/files_trashbin/templates/index.php b/apps/files_trashbin/templates/index.php index 6622c1d8f5f..fc18e88c41e 100644 --- a/apps/files_trashbin/templates/index.php +++ b/apps/files_trashbin/templates/index.php @@ -13,8 +13,8 @@ <tr> <th id='headerName' class="hidden column-name"> <div id="headerName-container"> - <input type="checkbox" id="select_all" /> - <label for="select_all"></label> + <input type="checkbox" id="select_all_trash" class="select-all"/> + <label for="select_all_trash"></label> <a class="name sort columntitle" data-sort="name"><span><?php p($l->t( 'Name' )); ?></span><span class="sort-indicator"></span></a> <span id="selectedActionsList" class='selectedActions'> <a href="" class="undelete"> diff --git a/apps/files_trashbin/tests/js/filelistSpec.js b/apps/files_trashbin/tests/js/filelistSpec.js index 291b2ffe14c..d41c24c3cc9 100644 --- a/apps/files_trashbin/tests/js/filelistSpec.js +++ b/apps/files_trashbin/tests/js/filelistSpec.js @@ -24,19 +24,16 @@ describe('OCA.Trashbin.FileList tests', function() { var FileActions = OCA.Files.FileActions; beforeEach(function() { - // init horrible parameters - var $body = $('body'); - $body.append('<input type="hidden" id="dir" value="/"></input>'); - // dummy files table - $body.append('<table id="filestable"></table>'); - alertStub = sinon.stub(OC.dialogs, 'alert'); notificationStub = sinon.stub(OC.Notification, 'show'); // init parameters and test table elements $('#testArea').append( '<div id="app-content-trashbin">' + + // init horrible parameters '<input type="hidden" id="dir" value="/"></input>' + + // set this but it shouldn't be used (could be the one from the + // files app) '<input type="hidden" id="permissions" value="31"></input>' + // dummy controls '<div id="controls">' + @@ -47,13 +44,13 @@ describe('OCA.Trashbin.FileList tests', function() { // TODO: at some point this will be rendered by the fileList class itself! '<table id="filestable">' + '<thead><tr><th id="headerName" class="hidden">' + - '<input type="checkbox" id="select_all">' + + '<input type="checkbox" id="select_all_trash" class="select-all">' + '<span class="name">Name</span>' + '<span class="selectedActions hidden">' + '<a href class="undelete">Restore</a>' + '<a href class="delete-selected">Delete</a></span>' + '</th></tr></thead>' + - '<tbody id="fileList"></tbody>' + + '<tbody id="fileList"></tbody>' + '<tfoot></tfoot>' + '</table>' + '<div id="emptycontent">Empty content message</div>' + @@ -66,7 +63,6 @@ describe('OCA.Trashbin.FileList tests', function() { name: 'One.txt', mtime: 11111000, mimetype: 'text/plain', - size: 12, etag: 'abc' }, { id: 2, @@ -74,7 +70,6 @@ describe('OCA.Trashbin.FileList tests', function() { name: 'Two.jpg', mtime: 22222000, mimetype: 'image/jpeg', - size: 12049, etag: 'def', }, { id: 3, @@ -82,7 +77,6 @@ describe('OCA.Trashbin.FileList tests', function() { name: 'Three.pdf', mtime: 33333000, mimetype: 'application/pdf', - size: 58009, etag: '123', }, { id: 4, @@ -90,7 +84,6 @@ describe('OCA.Trashbin.FileList tests', function() { mtime: 99999000, name: 'somedir', mimetype: 'httpd/unix-directory', - size: 250, etag: '456' }]; @@ -106,10 +99,91 @@ describe('OCA.Trashbin.FileList tests', function() { notificationStub.restore(); alertStub.restore(); }); + describe('Initialization', function() { + it('Sorts by mtime by default', function() { + expect(fileList._sort).toEqual('mtime'); + expect(fileList._sortDirection).toEqual('desc'); + }); + it('Always returns read and delete permission', function() { + expect(fileList.getDirectoryPermissions()).toEqual(OC.PERMISSION_READ | OC.PERMISSION_DELETE); + }); + }); + describe('Breadcrumbs', function() { + beforeEach(function() { + var data = { + status: 'success', + data: { + files: testFiles, + permissions: 1 + } + }; + fakeServer.respondWith(/\/index\.php\/apps\/files_trashbin\/ajax\/list.php\?dir=%2Fsubdir/, [ + 200, { + "Content-Type": "application/json" + }, + JSON.stringify(data) + ]); + }); + it('links the breadcrumb to the trashbin view', function() { + fileList.changeDirectory('/subdir', false, true); + fakeServer.respond(); + var $crumbs = fileList.$el.find('#controls .crumb'); + expect($crumbs.length).toEqual(2); + expect($crumbs.eq(0).find('a').text()).toEqual(''); + expect($crumbs.eq(0).find('a').attr('href')) + .toEqual(OC.webroot + '/index.php/apps/files?view=trashbin&dir=/'); + expect($crumbs.eq(1).find('a').text()).toEqual('subdir'); + expect($crumbs.eq(1).find('a').attr('href')) + .toEqual(OC.webroot + '/index.php/apps/files?view=trashbin&dir=/subdir'); + }); + }); describe('Rendering rows', function() { - // TODO. test that rows show the correct name but - // have the real file name with the ".d" suffix - // TODO: with and without dir listing + it('renders rows with the correct data when in root', function() { + // dir listing is false when in root + $('#dir').val('/'); + fileList.setFiles(testFiles); + var $rows = fileList.$el.find('tbody tr'); + var $tr = $rows.eq(0); + expect($rows.length).toEqual(4); + expect($tr.attr('data-id')).toEqual('1'); + expect($tr.attr('data-type')).toEqual('file'); + expect($tr.attr('data-file')).toEqual('One.txt.d11111'); + expect($tr.attr('data-size')).not.toBeDefined(); + expect($tr.attr('data-etag')).toEqual('abc'); + expect($tr.attr('data-permissions')).toEqual('9'); // read and delete + expect($tr.attr('data-mime')).toEqual('text/plain'); + expect($tr.attr('data-mtime')).toEqual('11111000'); + expect($tr.find('a.name').attr('href')).toEqual('#'); + + expect($tr.find('.nametext').text().trim()).toEqual('One.txt'); + + expect(fileList.findFileEl('One.txt.d11111')[0]).toEqual($tr[0]); + }); + it('renders rows with the correct data when in subdirectory', function() { + // dir listing is true when in a subdir + $('#dir').val('/subdir'); + + fileList.setFiles(testFiles); + var $rows = fileList.$el.find('tbody tr'); + var $tr = $rows.eq(0); + expect($rows.length).toEqual(4); + expect($tr.attr('data-id')).toEqual('1'); + expect($tr.attr('data-type')).toEqual('file'); + expect($tr.attr('data-file')).toEqual('One.txt'); + expect($tr.attr('data-size')).not.toBeDefined(); + expect($tr.attr('data-etag')).toEqual('abc'); + expect($tr.attr('data-permissions')).toEqual('9'); // read and delete + expect($tr.attr('data-mime')).toEqual('text/plain'); + expect($tr.attr('data-mtime')).toEqual('11111000'); + expect($tr.find('a.name').attr('href')).toEqual('#'); + + expect($tr.find('.nametext').text().trim()).toEqual('One.txt'); + + expect(fileList.findFileEl('One.txt')[0]).toEqual($tr[0]); + }); + it('does not render a size column', function() { + expect(fileList.$el.find('tbody tr .filesize').length).toEqual(0); + }); }); describe('File actions', function() { describe('Deleting single files', function() { @@ -142,7 +216,6 @@ describe('OCA.Trashbin.FileList tests', function() { fileList.findFileEl('somedir.d99999').find('input:checkbox').click(); }); describe('Delete', function() { - // TODO: also test with "allFiles" it('Deletes selected files when "Delete" clicked', function() { var request; $('.selectedActions .delete-selected').click(); @@ -154,7 +227,16 @@ describe('OCA.Trashbin.FileList tests', function() { fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, - JSON.stringify({status: 'success'}) + JSON.stringify({ + status: 'success', + data: { + success: [ + {filename: 'One.txt.d11111'}, + {filename: 'Three.pdf.d33333'}, + {filename: 'somedir.d99999'} + ] + } + }) ); expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0); expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0); @@ -163,7 +245,7 @@ describe('OCA.Trashbin.FileList tests', function() { }); it('Deletes all files when all selected when "Delete" clicked', function() { var request; - $('#select_all').click(); + $('.select-all').click(); $('.selectedActions .delete-selected').click(); expect(fakeServer.requests.length).toEqual(1); request = fakeServer.requests[0]; @@ -179,7 +261,6 @@ describe('OCA.Trashbin.FileList tests', function() { }); }); describe('Restore', function() { - // TODO: also test with "allFiles" it('Restores selected files when "Restore" clicked', function() { var request; $('.selectedActions .undelete').click(); @@ -191,16 +272,25 @@ describe('OCA.Trashbin.FileList tests', function() { fakeServer.requests[0].respond( 200, { 'Content-Type': 'application/json' }, - JSON.stringify({status: 'success'}) + JSON.stringify({ + status: 'success', + data: { + success: [ + {filename: 'One.txt.d11111'}, + {filename: 'Three.pdf.d33333'}, + {filename: 'somedir.d99999'} + ] + } + }) ); - expect(fileList.findFileEl('One.txt').length).toEqual(0); - expect(fileList.findFileEl('Three.pdf').length).toEqual(0); - expect(fileList.findFileEl('somedir').length).toEqual(0); - expect(fileList.findFileEl('Two.jpg').length).toEqual(1); + expect(fileList.findFileEl('One.txt.d11111').length).toEqual(0); + expect(fileList.findFileEl('Three.pdf.d33333').length).toEqual(0); + expect(fileList.findFileEl('somedir.d99999').length).toEqual(0); + expect(fileList.findFileEl('Two.jpg.d22222').length).toEqual(1); }); it('Restores all files when all selected when "Restore" clicked', function() { var request; - $('#select_all').click(); + $('.select-all').click(); $('.selectedActions .undelete').click(); expect(fakeServer.requests.length).toEqual(1); request = fakeServer.requests[0]; |