Signed-off-by: John Molakvoæ <skjnldsv@protonmail.com>pull/38950/head
parent
7929ad4a93
commit
e3bac437c2
@ -1,102 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> |
||||
* |
||||
* This file is licensed under the Affero General Public License version 3 |
||||
* or later. |
||||
* |
||||
* See the COPYING-README file. |
||||
* |
||||
*/ |
||||
|
||||
// HACK: this piece needs to be loaded AFTER the files app (for unit tests)
|
||||
window.addEventListener('DOMContentLoaded', function() { |
||||
(function(OCA) { |
||||
/** |
||||
* @class OCA.Files.FavoritesFileList |
||||
* @augments OCA.Files.FavoritesFileList |
||||
* |
||||
* @classdesc Favorites file list. |
||||
* Displays the list of files marked as favorites |
||||
* |
||||
* @param $el container element with existing markup for the .files-controls |
||||
* and a table |
||||
* @param [options] map of options, see other parameters |
||||
*/ |
||||
var FavoritesFileList = function($el, options) { |
||||
this.initialize($el, options); |
||||
}; |
||||
FavoritesFileList.prototype = _.extend({}, OCA.Files.FileList.prototype, |
||||
/** @lends OCA.Files.FavoritesFileList.prototype */ { |
||||
id: 'favorites', |
||||
appName: t('files','Favorites'), |
||||
|
||||
_clientSideSort: true, |
||||
_allowSelection: false, |
||||
|
||||
/** |
||||
* @private |
||||
*/ |
||||
initialize: function($el, options) { |
||||
OCA.Files.FileList.prototype.initialize.apply(this, arguments); |
||||
if (this.initialized) { |
||||
return; |
||||
} |
||||
OC.Plugins.attach('OCA.Files.FavoritesFileList', this); |
||||
}, |
||||
|
||||
updateEmptyContent: function() { |
||||
var dir = this.getCurrentDirectory(); |
||||
if (dir === '/') { |
||||
// root has special permissions
|
||||
this.$el.find('.emptyfilelist.emptycontent').toggleClass('hidden', !this.isEmpty); |
||||
this.$el.find('.files-filestable thead th').toggleClass('hidden', this.isEmpty); |
||||
} |
||||
else { |
||||
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments); |
||||
} |
||||
}, |
||||
|
||||
getDirectoryPermissions: function() { |
||||
return OC.PERMISSION_READ | OC.PERMISSION_DELETE; |
||||
}, |
||||
|
||||
updateStorageStatistics: function() { |
||||
// no op because it doesn't have
|
||||
// storage info like free space / used space
|
||||
}, |
||||
|
||||
reload: function() { |
||||
this.showMask(); |
||||
if (this._reloadCall?.abort) { |
||||
this._reloadCall.abort(); |
||||
} |
||||
|
||||
// there is only root
|
||||
this._setCurrentDir('/', false); |
||||
|
||||
this._reloadCall = this.filesClient.getFilteredFiles( |
||||
{ |
||||
favorite: true |
||||
}, |
||||
{ |
||||
properties: this._getWebdavProperties() |
||||
} |
||||
); |
||||
var callBack = this.reloadCallback.bind(this); |
||||
return this._reloadCall.then(callBack, callBack); |
||||
}, |
||||
|
||||
reloadCallback: function(status, result) { |
||||
if (result) { |
||||
// prepend empty dir info because original handler
|
||||
result.unshift({}); |
||||
} |
||||
|
||||
return OCA.Files.FileList.prototype.reloadCallback.call(this, status, result); |
||||
}, |
||||
}); |
||||
|
||||
OCA.Files.FavoritesFileList = FavoritesFileList; |
||||
})(OCA); |
||||
}); |
||||
|
||||
@ -1,120 +0,0 @@ |
||||
/* |
||||
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> |
||||
* |
||||
* This file is licensed under the Affero General Public License version 3 |
||||
* or later. |
||||
* |
||||
* See the COPYING-README file. |
||||
* |
||||
*/ |
||||
|
||||
(function(OCA) { |
||||
/** |
||||
* Registers the favorites file list from the files app sidebar. |
||||
* |
||||
* @namespace OCA.Files.FavoritesPlugin |
||||
*/ |
||||
OCA.Files.FavoritesPlugin = { |
||||
name: 'Favorites', |
||||
|
||||
/** |
||||
* @type OCA.Files.FavoritesFileList |
||||
*/ |
||||
favoritesFileList: null, |
||||
|
||||
attach: function() { |
||||
var self = this; |
||||
$('#app-content-favorites').on('show.plugin-favorites', function(e) { |
||||
self.showFileList($(e.target)); |
||||
}); |
||||
$('#app-content-favorites').on('hide.plugin-favorites', function() { |
||||
self.hideFileList(); |
||||
}); |
||||
}, |
||||
|
||||
detach: function() { |
||||
if (this.favoritesFileList) { |
||||
this.favoritesFileList.destroy(); |
||||
OCA.Files.fileActions.off('setDefault.plugin-favorites', this._onActionsUpdated); |
||||
OCA.Files.fileActions.off('registerAction.plugin-favorites', this._onActionsUpdated); |
||||
$('#app-content-favorites').off('.plugin-favorites'); |
||||
this.favoritesFileList = null; |
||||
} |
||||
}, |
||||
|
||||
showFileList: function($el) { |
||||
if (!this.favoritesFileList) { |
||||
this.favoritesFileList = this._createFavoritesFileList($el); |
||||
} |
||||
return this.favoritesFileList; |
||||
}, |
||||
|
||||
hideFileList: function() { |
||||
if (this.favoritesFileList) { |
||||
this.favoritesFileList.$fileList.empty(); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* Creates the favorites file list. |
||||
* |
||||
* @param $el container for the file list |
||||
* @return {OCA.Files.FavoritesFileList} file list |
||||
*/ |
||||
_createFavoritesFileList: function($el) { |
||||
var fileActions = this._createFileActions(); |
||||
// register favorite list for sidebar section
|
||||
return new OCA.Files.FavoritesFileList( |
||||
$el, { |
||||
fileActions: fileActions, |
||||
// The file list is created when a "show" event is handled,
|
||||
// so it should be marked as "shown" like it would have been
|
||||
// done if handling the event with the file list already
|
||||
// created.
|
||||
shown: true |
||||
} |
||||
); |
||||
}, |
||||
|
||||
_createFileActions: function() { |
||||
// inherit file actions from the files app
|
||||
var fileActions = new OCA.Files.FileActions(); |
||||
// note: not merging the legacy actions because legacy apps are not
|
||||
// compatible with the sharing overview and need to be adapted first
|
||||
fileActions.registerDefaultActions(); |
||||
fileActions.merge(OCA.Files.fileActions); |
||||
|
||||
if (!this._globalActionsInitialized) { |
||||
// in case actions are registered later
|
||||
this._onActionsUpdated = _.bind(this._onActionsUpdated, this); |
||||
OCA.Files.fileActions.on('setDefault.plugin-favorites', this._onActionsUpdated); |
||||
OCA.Files.fileActions.on('registerAction.plugin-favorites', this._onActionsUpdated); |
||||
this._globalActionsInitialized = true; |
||||
} |
||||
|
||||
// when the user clicks on a folder, redirect to the corresponding
|
||||
// folder in the files app instead of opening it directly
|
||||
fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) { |
||||
OCA.Files.App.setActiveView('files', {silent: true}); |
||||
OCA.Files.App.fileList.changeDirectory(OC.joinPaths(context.$file.attr('data-path'), filename), true, true); |
||||
}); |
||||
fileActions.setDefault('dir', 'Open'); |
||||
return fileActions; |
||||
}, |
||||
|
||||
_onActionsUpdated: function(ev) { |
||||
if (ev.action) { |
||||
this.favoritesFileList.fileActions.registerAction(ev.action); |
||||
} else if (ev.defaultAction) { |
||||
this.favoritesFileList.fileActions.setDefault( |
||||
ev.defaultAction.mime, |
||||
ev.defaultAction.name |
||||
); |
||||
} |
||||
} |
||||
}; |
||||
|
||||
})(OCA); |
||||
|
||||
OC.Plugins.register('OCA.Files.App', OCA.Files.FavoritesPlugin); |
||||
|
||||
@ -1,347 +0,0 @@ |
||||
/* |
||||
* @Copyright 2014 Vincent Petry <pvince81@owncloud.com> |
||||
* |
||||
* @author Vincent Petry |
||||
* @author Felix Nüsse <felix.nuesse@t-online.de> |
||||
* |
||||
* |
||||
* This file is licensed under the Affero General Public License version 3 |
||||
* or later. |
||||
* |
||||
* See the COPYING-README file. |
||||
* |
||||
*/ |
||||
|
||||
(function () { |
||||
|
||||
/** |
||||
* @class OCA.Files.Navigation |
||||
* @classdesc Navigation control for the files app sidebar. |
||||
* |
||||
* @param $el element containing the navigation |
||||
*/ |
||||
var Navigation = function ($el) { |
||||
this.initialize($el); |
||||
}; |
||||
|
||||
/** |
||||
* @memberof OCA.Files |
||||
*/ |
||||
Navigation.prototype = { |
||||
|
||||
/** |
||||
* Currently selected item in the list |
||||
*/ |
||||
_activeItem: null, |
||||
|
||||
/** |
||||
* Currently selected container |
||||
*/ |
||||
$currentContent: null, |
||||
|
||||
/** |
||||
* Key for the quick-acces-list |
||||
*/ |
||||
$quickAccessListKey: 'sublist-favorites', |
||||
/** |
||||
* Initializes the navigation from the given container |
||||
* |
||||
* @private |
||||
* @param $el element containing the navigation |
||||
*/ |
||||
initialize: function ($el) { |
||||
this.$el = $el; |
||||
this._activeItem = null; |
||||
this.$currentContent = null; |
||||
this._setupEvents(); |
||||
|
||||
this.setInitialQuickaccessSettings(); |
||||
}, |
||||
|
||||
/** |
||||
* Setup UI events |
||||
*/ |
||||
_setupEvents: function () { |
||||
this.$el.on('click', 'li a', _.bind(this._onClickItem, this)); |
||||
this.$el.on('click', 'li button', _.bind(this._onClickMenuButton, this)); |
||||
|
||||
var trashBinElement = $('.nav-trashbin'); |
||||
trashBinElement.droppable({ |
||||
over: function (event, ui) { |
||||
trashBinElement.addClass('dropzone-background'); |
||||
}, |
||||
out: function (event, ui) { |
||||
trashBinElement.removeClass('dropzone-background'); |
||||
}, |
||||
activate: function (event, ui) { |
||||
var element = trashBinElement.find('a').first(); |
||||
element.addClass('nav-icon-trashbin-starred').removeClass('nav-icon-trashbin'); |
||||
}, |
||||
deactivate: function (event, ui) { |
||||
var element = trashBinElement.find('a').first(); |
||||
element.addClass('nav-icon-trashbin').removeClass('nav-icon-trashbin-starred'); |
||||
}, |
||||
drop: function (event, ui) { |
||||
trashBinElement.removeClass('dropzone-background'); |
||||
|
||||
var $selectedFiles = $(ui.draggable); |
||||
|
||||
// FIXME: when there are a lot of selected files the helper
|
||||
// contains only a subset of them; the list of selected
|
||||
// files should be gotten from the file list instead to
|
||||
// ensure that all of them are removed.
|
||||
var item = ui.helper.find('tr'); |
||||
for (var i = 0; i < item.length; i++) { |
||||
$selectedFiles.trigger('droppedOnTrash', item[i].getAttribute('data-file'), item[i].getAttribute('data-dir')); |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
/** |
||||
* Returns the container of the currently active app. |
||||
* |
||||
* @return app container |
||||
*/ |
||||
getActiveContainer: function () { |
||||
return this.$currentContent; |
||||
}, |
||||
|
||||
/** |
||||
* Returns the currently active item |
||||
* |
||||
* @return item ID |
||||
*/ |
||||
getActiveItem: function () { |
||||
return this._activeItem; |
||||
}, |
||||
|
||||
/** |
||||
* Switch the currently selected item, mark it as selected and |
||||
* make the content container visible, if any. |
||||
* |
||||
* @param string itemId id of the navigation item to select |
||||
* @param array options "silent" to not trigger event |
||||
*/ |
||||
setActiveItem: function (itemId, options) { |
||||
var currentItem = this.$el.find('li[data-id="' + itemId + '"]'); |
||||
var itemDir = currentItem.data('dir'); |
||||
var itemView = currentItem.data('view'); |
||||
var oldItemId = this._activeItem; |
||||
if (itemId === this._activeItem) { |
||||
if (!options || !options.silent) { |
||||
this.$el.trigger( |
||||
new $.Event('itemChanged', { |
||||
itemId: itemId, |
||||
previousItemId: oldItemId, |
||||
dir: itemDir, |
||||
view: itemView |
||||
}) |
||||
); |
||||
} |
||||
return; |
||||
} |
||||
this.$el.find('li a').removeClass('active').removeAttr('aria-current'); |
||||
if (this.$currentContent) { |
||||
this.$currentContent.addClass('hidden'); |
||||
this.$currentContent.trigger(jQuery.Event('hide')); |
||||
} |
||||
this._activeItem = itemId; |
||||
currentItem.children('a').addClass('active').attr('aria-current', 'page'); |
||||
this.$currentContent = $('#app-content-' + (typeof itemView === 'string' && itemView !== '' ? itemView : itemId)); |
||||
this.$currentContent.removeClass('hidden'); |
||||
if (!options || !options.silent) { |
||||
this.$currentContent.trigger(jQuery.Event('show', { |
||||
itemId: itemId, |
||||
previousItemId: oldItemId, |
||||
dir: itemDir, |
||||
view: itemView |
||||
})); |
||||
this.$el.trigger( |
||||
new $.Event('itemChanged', { |
||||
itemId: itemId, |
||||
previousItemId: oldItemId, |
||||
dir: itemDir, |
||||
view: itemView |
||||
}) |
||||
); |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* Returns whether a given item exists |
||||
*/ |
||||
itemExists: function (itemId) { |
||||
return this.$el.find('li[data-id="' + itemId + '"]').length; |
||||
}, |
||||
|
||||
/** |
||||
* Event handler for when clicking on an item. |
||||
*/ |
||||
_onClickItem: function (ev) { |
||||
var $target = $(ev.target); |
||||
var itemId = $target.closest('li').attr('data-id'); |
||||
if (!_.isUndefined(itemId)) { |
||||
this.setActiveItem(itemId); |
||||
} |
||||
ev.preventDefault(); |
||||
}, |
||||
|
||||
/** |
||||
* Event handler for clicking a button |
||||
*/ |
||||
_onClickMenuButton: function (ev) { |
||||
var $target = $(ev.target); |
||||
var $menu = $target.parent('li'); |
||||
var itemId = $target.closest('button').attr('id'); |
||||
|
||||
var collapsibleToggles = []; |
||||
var dotmenuToggles = []; |
||||
|
||||
if ($menu.hasClass('collapsible') && $menu.data('expandedstate')) { |
||||
$menu.toggleClass('open'); |
||||
var targetAriaExpanded = $target.attr('aria-expanded'); |
||||
if (targetAriaExpanded === 'false') { |
||||
$target.attr('aria-expanded', 'true'); |
||||
} else if (targetAriaExpanded === 'true') { |
||||
$target.attr('aria-expanded', 'false'); |
||||
} |
||||
$menu.toggleAttr('data-expanded', 'true', 'false'); |
||||
var show = $menu.hasClass('open') ? 1 : 0; |
||||
var key = $menu.data('expandedstate'); |
||||
$.post(OC.generateUrl("/apps/files/api/v1/toggleShowFolder/" + key), {show: show}); |
||||
} |
||||
|
||||
dotmenuToggles.forEach(function foundToggle (item) { |
||||
if (item[0] === ("#" + itemId)) { |
||||
document.getElementById(item[1]).classList.toggle('open'); |
||||
} |
||||
}); |
||||
|
||||
ev.preventDefault(); |
||||
}, |
||||
|
||||
/** |
||||
* Sort initially as setup of sidebar for QuickAccess |
||||
*/ |
||||
setInitialQuickaccessSettings: function () { |
||||
var quickAccessKey = this.$quickAccessListKey; |
||||
var quickAccessMenu = document.getElementById(quickAccessKey); |
||||
if (quickAccessMenu) { |
||||
var list = quickAccessMenu.getElementsByTagName('li'); |
||||
this.QuickSort(list, 0, list.length - 1); |
||||
} |
||||
|
||||
var favoritesListElement = $(quickAccessMenu).parent(); |
||||
favoritesListElement.droppable({ |
||||
over: function (event, ui) { |
||||
favoritesListElement.addClass('dropzone-background'); |
||||
}, |
||||
out: function (event, ui) { |
||||
favoritesListElement.removeClass('dropzone-background'); |
||||
}, |
||||
activate: function (event, ui) { |
||||
var element = favoritesListElement.find('a').first(); |
||||
element.addClass('nav-icon-favorites-starred').removeClass('nav-icon-favorites'); |
||||
}, |
||||
deactivate: function (event, ui) { |
||||
var element = favoritesListElement.find('a').first(); |
||||
element.addClass('nav-icon-favorites').removeClass('nav-icon-favorites-starred'); |
||||
}, |
||||
drop: function (event, ui) { |
||||
favoritesListElement.removeClass('dropzone-background'); |
||||
|
||||
var $selectedFiles = $(ui.draggable); |
||||
|
||||
if (ui.helper.find('tr').size() === 1) { |
||||
var $tr = $selectedFiles.closest('tr'); |
||||
if ($tr.attr("data-favorite")) { |
||||
return; |
||||
} |
||||
$selectedFiles.trigger('droppedOnFavorites', $tr.attr('data-file')); |
||||
} else { |
||||
// FIXME: besides the issue described for dropping on
|
||||
// the trash bin, for favoriting it is not possible to
|
||||
// use the data from the helper; due to some bugs the
|
||||
// tags are not always added to the selected files, and
|
||||
// thus that data can not be accessed through the helper
|
||||
// to prevent triggering the favorite action on an
|
||||
// already favorited file (which would remove it from
|
||||
// favorites).
|
||||
OC.Notification.showTemporary(t('files', 'You can only favorite a single file or folder at a time')); |
||||
} |
||||
} |
||||
}); |
||||
}, |
||||
|
||||
/** |
||||
* Sorting-Algorithm for QuickAccess |
||||
*/ |
||||
QuickSort: function (list, start, end) { |
||||
var lastMatch; |
||||
if (list.length > 1) { |
||||
lastMatch = this.quicksort_helper(list, start, end); |
||||
if (start < lastMatch - 1) { |
||||
this.QuickSort(list, start, lastMatch - 1); |
||||
} |
||||
if (lastMatch < end) { |
||||
this.QuickSort(list, lastMatch, end); |
||||
} |
||||
} |
||||
}, |
||||
|
||||
/** |
||||
* Sorting-Algorithm-Helper for QuickAccess |
||||
*/ |
||||
quicksort_helper: function (list, start, end) { |
||||
var pivot = Math.floor((end + start) / 2); |
||||
var pivotElement = this.getCompareValue(list, pivot); |
||||
var i = start; |
||||
var j = end; |
||||
|
||||
while (i <= j) { |
||||
while (this.getCompareValue(list, i) < pivotElement) { |
||||
i++; |
||||
} |
||||
while (this.getCompareValue(list, j) > pivotElement) { |
||||
j--; |
||||
} |
||||
if (i <= j) { |
||||
this.swap(list, i, j); |
||||
i++; |
||||
j--; |
||||
} |
||||
} |
||||
return i; |
||||
}, |
||||
|
||||
/** |
||||
* Sorting-Algorithm-Helper for QuickAccess |
||||
* This method allows easy access to the element which is sorted by. |
||||
*/ |
||||
getCompareValue: function (nodes, int, strategy) { |
||||
return nodes[int].getElementsByTagName('a')[0].innerHTML.toLowerCase(); |
||||
}, |
||||
|
||||
/** |
||||
* Sorting-Algorithm-Helper for QuickAccess |
||||
* This method allows easy swapping of elements. |
||||
*/ |
||||
swap: function (list, j, i) { |
||||
var before = function(node, insertNode) { |
||||
node.parentNode.insertBefore(insertNode, node); |
||||
} |
||||
before(list[i], list[j]); |
||||
before(list[j], list[i]); |
||||
} |
||||
|
||||
}; |
||||
|
||||
OCA.Files.Navigation = Navigation; |
||||
|
||||
})(); |
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@ -1,116 +0,0 @@ |
||||
/** |
||||
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> |
||||
* |
||||
* @author Christoph Wurst <christoph@winzerhof-wurst.at> |
||||
* @author Jan-Christoph Borchardt <hey@jancborchardt.net> |
||||
* @author Vincent Petry <vincent@nextcloud.com> |
||||
* |
||||
* @license AGPL-3.0-or-later |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* |
||||
*/ |
||||
|
||||
describe('OCA.Files.FavoritesFileList tests', function() { |
||||
var fileList; |
||||
|
||||
beforeEach(function() { |
||||
// init parameters and test table elements
|
||||
$('#testArea').append( |
||||
'<div id="app-content">' + |
||||
// init horrible parameters
|
||||
'<input type="hidden" id="permissions" value="31"></input>' + |
||||
// dummy controls
|
||||
'<div class="files-controls">' + |
||||
' <div class="actions creatable"></div>' + |
||||
' <div class="notCreatable"></div>' + |
||||
'</div>' + |
||||
// dummy table
|
||||
// TODO: at some point this will be rendered by the fileList class itself!
|
||||
'<table class="files-filestable list-container view-grid">' + |
||||
'<thead><tr>' + |
||||
'<th class="hidden column-name">' + |
||||
'<a class="name columntitle" data-sort="name"><span>Name</span><span class="sort-indicator"></span></a>' + |
||||
'</th>' + |
||||
'<th class="hidden column-mtime">' + |
||||
'<a class="columntitle" data-sort="mtime"><span class="sort-indicator"></span></a>' + |
||||
'</th>' + |
||||
'</tr></thead>' + |
||||
'<tbody class="files-fileList"></tbody>' + |
||||
'<tfoot></tfoot>' + |
||||
'</table>' + |
||||
'<div class="emptyfilelist emptycontent">Empty content message</div>' + |
||||
'</div>' |
||||
); |
||||
}); |
||||
|
||||
describe('loading file list', function() { |
||||
var fetchStub; |
||||
|
||||
beforeEach(function() { |
||||
fileList = new OCA.Files.FavoritesFileList( |
||||
$('#app-content') |
||||
); |
||||
OCA.Files.FavoritesPlugin.attach(fileList); |
||||
|
||||
fetchStub = sinon.stub(fileList.filesClient, 'getFilteredFiles'); |
||||
}); |
||||
afterEach(function() { |
||||
fetchStub.restore(); |
||||
fileList.destroy(); |
||||
fileList = undefined; |
||||
}); |
||||
it('render files', function(done) { |
||||
var deferred = $.Deferred(); |
||||
fetchStub.returns(deferred.promise()); |
||||
|
||||
fileList.reload(); |
||||
|
||||
expect(fetchStub.calledOnce).toEqual(true); |
||||
|
||||
deferred.resolve(207, [{ |
||||
id: 7, |
||||
name: 'test.txt', |
||||
path: '/somedir', |
||||
size: 123, |
||||
mtime: 11111000, |
||||
tags: [OC.TAG_FAVORITE], |
||||
permissions: OC.PERMISSION_ALL, |
||||
mimetype: 'text/plain' |
||||
}]); |
||||
|
||||
setTimeout(function() { |
||||
var $rows = fileList.$el.find('tbody tr'); |
||||
var $tr = $rows.eq(0); |
||||
expect($rows.length).toEqual(1); |
||||
expect($tr.attr('data-id')).toEqual('7'); |
||||
expect($tr.attr('data-type')).toEqual('file'); |
||||
expect($tr.attr('data-file')).toEqual('test.txt'); |
||||
expect($tr.attr('data-path')).toEqual('/somedir'); |
||||
expect($tr.attr('data-size')).toEqual('123'); |
||||
expect(parseInt($tr.attr('data-permissions'), 10)) |
||||
.toEqual(OC.PERMISSION_ALL); |
||||
expect($tr.attr('data-mime')).toEqual('text/plain'); |
||||
expect($tr.attr('data-mtime')).toEqual('11111000'); |
||||
expect($tr.find('a.name').attr('href')).toEqual( |
||||
OC.getRootPath() + |
||||
'/remote.php/webdav/somedir/test.txt' |
||||
); |
||||
expect($tr.find('.nametext').text().trim()).toEqual('test.txt'); |
||||
|
||||
done(); |
||||
}, 0); |
||||
}); |
||||
}); |
||||
}); |
||||
@ -1,119 +0,0 @@ |
||||
/** |
||||
* Copyright (c) 2014 Vincent Petry <pvince81@owncloud.com> |
||||
* |
||||
* @author John Molakvoæ <skjnldsv@protonmail.com> |
||||
* @author Vincent Petry <vincent@nextcloud.com> |
||||
* |
||||
* @license AGPL-3.0-or-later |
||||
* |
||||
* This program is free software: you can redistribute it and/or modify |
||||
* it under the terms of the GNU Affero General Public License as |
||||
* published by the Free Software Foundation, either version 3 of the |
||||
* License, or (at your option) any later version. |
||||
* |
||||
* This program 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 program. If not, see <http://www.gnu.org/licenses/>.
|
||||
* |
||||
*/ |
||||
|
||||
describe('OCA.Files.FavoritesPlugin tests', function() { |
||||
var Plugin = OCA.Files.FavoritesPlugin; |
||||
var fileList; |
||||
|
||||
beforeEach(function() { |
||||
$('#testArea').append( |
||||
'<div id="content">' + |
||||
'<div id="app-navigation">' + |
||||
'<ul><li data-id="files"><a>Files</a></li>' + |
||||
'<li data-id="sharingin"><a></a></li>' + |
||||
'<li data-id="sharingout"><a></a></li>' + |
||||
'</ul></div>' + |
||||
'<div id="app-content">' + |
||||
'<div id="app-content-files" class="hidden">' + |
||||
'</div>' + |
||||
'<div id="app-content-favorites" class="hidden">' + |
||||
'</div>' + |
||||
'</div>' + |
||||
'</div>' + |
||||
'</div>' |
||||
); |
||||
OC.Plugins.attach('OCA.Files.App', Plugin); |
||||
fileList = Plugin.showFileList($('#app-content-favorites')); |
||||
}); |
||||
afterEach(function() { |
||||
OC.Plugins.detach('OCA.Files.App', Plugin); |
||||
}); |
||||
|
||||
describe('initialization', function() { |
||||
it('inits favorites list on show', function() { |
||||
expect(fileList).toBeDefined(); |
||||
}); |
||||
}); |
||||
describe('file actions', function() { |
||||
it('provides default file actions', function() { |
||||
var fileActions = fileList.fileActions; |
||||
|
||||
expect(fileActions.actions.all).toBeDefined(); |
||||
expect(fileActions.actions.all.Delete).toBeDefined(); |
||||
expect(fileActions.actions.all.Rename).toBeDefined(); |
||||
expect(fileActions.actions.all.Download).toBeDefined(); |
||||
|
||||
expect(fileActions.defaults.dir).toEqual('Open'); |
||||
}); |
||||
it('provides custom file actions', function() { |
||||
var actionStub = sinon.stub(); |
||||
// regular file action
|
||||
OCA.Files.fileActions.register( |
||||
'all', |
||||
'RegularTest', |
||||
OC.PERMISSION_READ, |
||||
OC.imagePath('core', 'actions/shared'), |
||||
actionStub |
||||
); |
||||
|
||||
Plugin.favoritesFileList = null; |
||||
fileList = Plugin.showFileList($('#app-content-favorites')); |
||||
|
||||
expect(fileList.fileActions.actions.all.RegularTest).toBeDefined(); |
||||
}); |
||||
it('redirects to files app when opening a directory', function() { |
||||
var oldList = OCA.Files.App.fileList; |
||||
// dummy new list to make sure it exists
|
||||
OCA.Files.App.fileList = new OCA.Files.FileList($('<table><thead></thead><tbody></tbody></table>')); |
||||
|
||||
var setActiveViewStub = sinon.stub(OCA.Files.App, 'setActiveView'); |
||||
// create dummy table so we can click the dom
|
||||
var $table = '<table><thead></thead><tbody class="files-fileList"></tbody></table>'; |
||||
$('#app-content-favorites').append($table); |
||||
|
||||
Plugin.favoritesFileList = null; |
||||
fileList = Plugin.showFileList($('#app-content-favorites')); |
||||
|
||||
fileList.setFiles([{ |
||||
name: 'testdir', |
||||
type: 'dir', |
||||
path: '/somewhere/inside/subdir', |
||||
counterParts: ['user2'], |
||||
shareOwner: 'user2' |
||||
}]); |
||||
|
||||
fileList.findFileEl('testdir').find('td .nametext').click(); |
||||
|
||||
expect(OCA.Files.App.fileList.getCurrentDirectory()).toEqual('/somewhere/inside/subdir/testdir'); |
||||
|
||||
expect(setActiveViewStub.calledOnce).toEqual(true); |
||||
expect(setActiveViewStub.calledWith('files')).toEqual(true); |
||||
|
||||
setActiveViewStub.restore(); |
||||
|
||||
// restore old list
|
||||
OCA.Files.App.fileList = oldList; |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
Loading…
Reference in new issue