summaryrefslogtreecommitdiffstats
path: root/apps
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2016-07-22 15:20:51 +0200
committerRobin Appelman <robin@icewind.nl>2016-07-22 15:20:51 +0200
commit2e3114cc28b44468d449838c3b75ed7e4e5decea (patch)
tree2b62a1aca17e8c996a31565f484ae7d0b1f55ea8 /apps
parentb94ff97a77be3947e62373cd4c6b75d7dfe5e5cc (diff)
downloadnextcloud-server-2e3114cc28b44468d449838c3b75ed7e4e5decea.tar.gz
nextcloud-server-2e3114cc28b44468d449838c3b75ed7e4e5decea.zip
Add recent file listing
Diffstat (limited to 'apps')
-rw-r--r--apps/files/appinfo/app.php14
-rw-r--r--apps/files/js/recentfilelist.js105
-rw-r--r--apps/files/js/recentplugin.js117
-rw-r--r--apps/files/lib/Controller/ViewController.php2
-rw-r--r--apps/files/recentlist.php7
-rw-r--r--apps/files/templates/recentlist.php42
6 files changed, 285 insertions, 2 deletions
diff --git a/apps/files/appinfo/app.php b/apps/files/appinfo/app.php
index cc86e9bf270..850c335c27d 100644
--- a/apps/files/appinfo/app.php
+++ b/apps/files/appinfo/app.php
@@ -28,6 +28,7 @@
*/
\OCP\App::registerAdmin('files', 'admin');
+$l = \OC::$server->getL10N('files');
\OC::$server->getNavigationManager()->add(function () {
$urlGenerator = \OC::$server->getURLGenerator();
@@ -49,8 +50,7 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.presentat
$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
-\OCA\Files\App::getNavigationManager()->add(function () {
- $l = \OC::$server->getL10N('files');
+\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
return [
'id' => 'files',
'appname' => 'files',
@@ -60,6 +60,16 @@ $templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadshe
];
});
+\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
+ return [
+ 'id' => 'recent',
+ 'appname' => 'files',
+ 'script' => 'recentlist.php',
+ 'order' => 2,
+ 'name' => $l->t('Recent'),
+ ];
+});
+
\OC::$server->getActivityManager()->registerExtension(function() {
return new \OCA\Files\Activity(
\OC::$server->query('L10NFactory'),
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);
+
diff --git a/apps/files/lib/Controller/ViewController.php b/apps/files/lib/Controller/ViewController.php
index 5e342e6589b..9dbe06ff789 100644
--- a/apps/files/lib/Controller/ViewController.php
+++ b/apps/files/lib/Controller/ViewController.php
@@ -173,9 +173,11 @@ class ViewController extends Controller {
\OCP\Util::addscript('files', 'search');
\OCP\Util::addScript('files', 'favoritesfilelist');
+ \OCP\Util::addScript('files', 'recentfilelist');
\OCP\Util::addScript('files', 'tagsplugin');
\OCP\Util::addScript('files', 'gotoplugin');
\OCP\Util::addScript('files', 'favoritesplugin');
+ \OCP\Util::addScript('files', 'recentplugin');
\OCP\Util::addScript('files', 'detailfileinfoview');
\OCP\Util::addScript('files', 'sidebarpreviewmanager');
diff --git a/apps/files/recentlist.php b/apps/files/recentlist.php
new file mode 100644
index 00000000000..1976be4894a
--- /dev/null
+++ b/apps/files/recentlist.php
@@ -0,0 +1,7 @@
+<?php
+// Check if we are a user
+OCP\User::checkLoggedIn();
+
+$tmpl = new OCP\Template('files', 'recentlist', '');
+
+$tmpl->printPage();
diff --git a/apps/files/templates/recentlist.php b/apps/files/templates/recentlist.php
new file mode 100644
index 00000000000..1667eb4cc8d
--- /dev/null
+++ b/apps/files/templates/recentlist.php
@@ -0,0 +1,42 @@
+<?php /** @var $l OC_L10N */ ?>
+<div id='notification'></div>
+
+<div id="emptycontent" class="hidden"></div>
+
+<input type="hidden" name="dir" value="" id="dir">
+
+<div class="nofilterresults hidden">
+ <div class="icon-search"></div>
+ <h2><?php p($l->t('No entries found in this folder')); ?></h2>
+ <p></p>
+</div>
+
+<table id="filestable">
+ <thead>
+ <tr>
+ <th id='headerName' class="hidden column-name">
+ <div id="headerName-container">
+ <a class="name sort columntitle"
+ data-sort="name"><span><?php p($l->t('Name')); ?></span></a>
+ </div>
+ </th>
+ <th id="headerSize" class="hidden column-size">
+ <a class="size sort columntitle"
+ data-sort="size"><span><?php p($l->t('Size')); ?></span></a>
+ </th>
+ <th id="headerDate" class="hidden column-mtime">
+ <a id="modified" class="columntitle"
+ data-sort="mtime"><span><?php p($l->t('Modified')); ?></span><span
+ class="sort-indicator"></span></a>
+ <span class="selectedActions"><a href="" class="delete-selected">
+ <span><?php p($l->t('Delete')) ?></span>
+ <span class="icon icon-delete"></span>
+ </a></span>
+ </th>
+ </tr>
+ </thead>
+ <tbody id="fileList">
+ </tbody>
+ <tfoot>
+ </tfoot>
+</table>