diff options
author | Robin Appelman <robin@icewind.nl> | 2016-07-22 15:20:51 +0200 |
---|---|---|
committer | Robin Appelman <robin@icewind.nl> | 2016-07-22 15:20:51 +0200 |
commit | 2e3114cc28b44468d449838c3b75ed7e4e5decea (patch) | |
tree | 2b62a1aca17e8c996a31565f484ae7d0b1f55ea8 /apps/files/js | |
parent | b94ff97a77be3947e62373cd4c6b75d7dfe5e5cc (diff) | |
download | nextcloud-server-2e3114cc28b44468d449838c3b75ed7e4e5decea.tar.gz nextcloud-server-2e3114cc28b44468d449838c3b75ed7e4e5decea.zip |
Add recent file listing
Diffstat (limited to 'apps/files/js')
-rw-r--r-- | apps/files/js/recentfilelist.js | 105 | ||||
-rw-r--r-- | apps/files/js/recentplugin.js | 117 |
2 files changed, 222 insertions, 0 deletions
diff --git a/apps/files/js/recentfilelist.js b/apps/files/js/recentfilelist.js new file mode 100644 index 00000000000..e63a71f8549 --- /dev/null +++ b/apps/files/js/recentfilelist.js @@ -0,0 +1,105 @@ +/* + * 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) +$(document).ready(function () { + (function (OCA) { + /** + * @class OCA.Files.RecentFileList + * @augments OCA.Files.RecentFileList + * + * @classdesc Recent file list. + * Displays the list of recently modified files + * + * @param $el container element with existing markup for the #controls + * and a table + * @param [options] map of options, see other parameters + */ + var RecentFileList = function ($el, options) { + options.sorting = { + mode: 'mtime', + direction: 'desc' + }; + this.initialize($el, options); + }; + RecentFileList.prototype = _.extend({}, OCA.Files.FileList.prototype, + /** @lends OCA.Files.RecentFileList.prototype */ { + id: 'recent', + appName: t('files', 'Recent'), + + _clientSideSort: true, + _allowSelection: false, + + /** + * @private + */ + initialize: function () { + OCA.Files.FileList.prototype.initialize.apply(this, arguments); + if (this.initialized) { + return; + } + OC.Plugins.attach('OCA.Files.RecentFileList', this); + }, + + updateEmptyContent: function () { + var dir = this.getCurrentDirectory(); + if (dir === '/') { + // root has special permissions + this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty); + this.$el.find('#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) { + this._reloadCall.abort(); + } + + // there is only root + this._setCurrentDir('/', false); + + this._reloadCall = $.ajax({ + url: OC.generateUrl('/apps/files/api/v1/recent'), + type: 'GET', + dataType: 'json' + }); + var callBack = this.reloadCallback.bind(this); + return this._reloadCall.then(callBack, callBack); + }, + + reloadCallback: function (result) { + delete this._reloadCall; + this.hideMask(); + + if (result.files) { + this.setFiles(result.files.sort(this._sortComparator)); + return true; + } + return false; + } + }); + + OCA.Files.RecentFileList = RecentFileList; + })(OCA); +}); + diff --git a/apps/files/js/recentplugin.js b/apps/files/js/recentplugin.js new file mode 100644 index 00000000000..fcd427b18a2 --- /dev/null +++ b/apps/files/js/recentplugin.js @@ -0,0 +1,117 @@ +/* + * 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) { + /** + * @namespace OCA.Files.RecentPlugin + * + * Registers the recent file list from the files app sidebar. + */ + OCA.Files.RecentPlugin = { + name: 'Recent', + + /** + * @type OCA.Files.RecentFileList + */ + recentFileList: null, + + attach: function () { + var self = this; + $('#app-content-recent').on('show.plugin-recent', function (e) { + self.showFileList($(e.target)); + }); + $('#app-content-recent').on('hide.plugin-recent', function () { + self.hideFileList(); + }); + }, + + detach: function () { + if (this.recentFileList) { + this.recentFileList.destroy(); + OCA.Files.fileActions.off('setDefault.plugin-recent', this._onActionsUpdated); + OCA.Files.fileActions.off('registerAction.plugin-recent', this._onActionsUpdated); + $('#app-content-recent').off('.plugin-recent'); + this.recentFileList = null; + } + }, + + showFileList: function ($el) { + if (!this.recentFileList) { + this.recentFileList = this._createRecentFileList($el); + } + return this.recentFileList; + }, + + hideFileList: function () { + if (this.recentFileList) { + this.recentFileList.$fileList.empty(); + } + }, + + /** + * Creates the recent file list. + * + * @param $el container for the file list + * @return {OCA.Files.RecentFileList} file list + */ + _createRecentFileList: function ($el) { + var fileActions = this._createFileActions(); + // register recent list for sidebar section + return new OCA.Files.RecentFileList( + $el, { + fileActions: fileActions, + scrollContainer: $('#app-content') + } + ); + }, + + _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-recent', this._onActionsUpdated); + OCA.Files.fileActions.on('registerAction.plugin-recent', 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}); + var path = OC.joinPaths(context.$file.attr('data-path'), filename); + OCA.Files.App.fileList.changeDirectory(path, true, true); + }); + fileActions.setDefault('dir', 'Open'); + return fileActions; + }, + + _onActionsUpdated: function (ev) { + if (ev.action) { + this.recentFileList.fileActions.registerAction(ev.action); + } else if (ev.defaultAction) { + this.recentFileList.fileActions.setDefault( + ev.defaultAction.mime, + ev.defaultAction.name + ); + } + } + }; + +})(OCA); + +OC.Plugins.register('OCA.Files.App', OCA.Files.RecentPlugin); + |