Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions apps/files/appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
*/
\OCP\App::registerAdmin('files', 'admin');

$l = \OC::$server->getL10N('files');

\OC::$server->getNavigationManager()->add(function () {
$urlGenerator = \OC::$server->getURLGenerator();
Expand All @@ -49,8 +50,7 @@
$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',
Expand All @@ -60,6 +60,16 @@
];
});

\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'),
Expand Down
5 changes: 5 additions & 0 deletions apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@
'verb' => 'GET',
'requirements' => array('tagName' => '.+'),
),
array(
'name' => 'API#getRecentFiles',
'url' => '/api/v1/recent/',
'verb' => 'GET'
),
array(
'name' => 'API#updateFileSorting',
'url' => '/api/v1/sorting',
Expand Down
7 changes: 6 additions & 1 deletion apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@
*/
_clientSideSort: true,

/**
* Whether or not users can change the sort attribute or direction
*/
_allowSorting: true,

/**
* Current directory
* @type String
Expand Down Expand Up @@ -718,7 +723,7 @@
$target = $target.closest('a');
}
sort = $target.attr('data-sort');
if (sort) {
if (sort && this._allowSorting) {
if (this._sort === sort) {
this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc', true, true);
}
Expand Down
106 changes: 106 additions & 0 deletions apps/files/js/recentfilelist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright (c) 2014 Vincent Petry <[email protected]>
*
* 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);
this._allowSorting = false;
};
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);
});

117 changes: 117 additions & 0 deletions apps/files/js/recentplugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
/*
* Copyright (c) 2014 Vincent Petry <[email protected]>
*
* 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);

3 changes: 2 additions & 1 deletion apps/files/lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public function __construct(array $urlParams=array()) {
$c->query('TagService'),
$server->getPreviewManager(),
$server->getShareManager(),
$server->getConfig()
$server->getConfig(),
$server->getUserFolder()
);
});

Expand Down
Loading