Skip to content

Commit 45d0215

Browse files
committed
Add recent files list
1 parent 5e1793d commit 45d0215

File tree

11 files changed

+431
-30
lines changed

11 files changed

+431
-30
lines changed

apps/files/appinfo/app.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
*/
2828
\OCP\App::registerAdmin('files', 'admin');
2929

30+
$urlGenerator = \OC::$server->getURLGenerator();
31+
$l = \OC::$server->getL10N('files');
3032

31-
\OC::$server->getNavigationManager()->add(function () {
32-
$urlGenerator = \OC::$server->getURLGenerator();
33-
$l = \OC::$server->getL10N('files');
33+
\OC::$server->getNavigationManager()->add(function () use ($urlGenerator, $l) {
3434
return [
3535
'id' => 'files_index',
3636
'order' => 0,
@@ -48,8 +48,7 @@
4848
$templateManager->registerTemplate('application/vnd.oasis.opendocument.text', 'core/templates/filetemplates/template.odt');
4949
$templateManager->registerTemplate('application/vnd.oasis.opendocument.spreadsheet', 'core/templates/filetemplates/template.ods');
5050

51-
\OCA\Files\App::getNavigationManager()->add(function () {
52-
$l = \OC::$server->getL10N('files');
51+
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
5352
return [
5453
'id' => 'files',
5554
'appname' => 'files',
@@ -59,6 +58,16 @@
5958
];
6059
});
6160

61+
\OCA\Files\App::getNavigationManager()->add(function () use ($l) {
62+
return [
63+
'id' => 'recent',
64+
'appname' => 'files',
65+
'script' => 'list.php',
66+
'order' => 2,
67+
'name' => $l->t('Recent'),
68+
];
69+
});
70+
6271
\OC::$server->getActivityManager()->registerExtension(function() {
6372
return new \OCA\Files\Activity(
6473
\OC::$server->query('L10NFactory'),

apps/files/appinfo/routes.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@
4949
'verb' => 'GET',
5050
'requirements' => array('tagName' => '.+'),
5151
),
52+
array(
53+
'name' => 'API#getRecentFiles',
54+
'url' => '/api/v1/recent/',
55+
'verb' => 'GET'
56+
),
5257
array(
5358
'name' => 'API#updateFileSorting',
5459
'url' => '/api/v1/sorting',

apps/files/js/recentfilelist.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/*
2+
* Copyright (c) 2014 Vincent Petry <[email protected]>
3+
*
4+
* This file is licensed under the Affero General Public License version 3
5+
* or later.
6+
*
7+
* See the COPYING-README file.
8+
*
9+
*/
10+
11+
// HACK: this piece needs to be loaded AFTER the files app (for unit tests)
12+
$(document).ready(function () {
13+
(function (OCA) {
14+
/**
15+
* @class OCA.Files.RecentFileList
16+
* @augments OCA.Files.RecentFileList
17+
*
18+
* @classdesc Recent file list.
19+
* Displays the list of recently modified files
20+
*
21+
* @param $el container element with existing markup for the #controls
22+
* and a table
23+
* @param [options] map of options, see other parameters
24+
*/
25+
var RecentFileList = function ($el, options) {
26+
options.sorting = {
27+
mode: 'mtime',
28+
direction: 'desc'
29+
};
30+
this.initialize($el, options);
31+
};
32+
RecentFileList.prototype = _.extend({}, OCA.Files.FileList.prototype,
33+
/** @lends OCA.Files.RecentFileList.prototype */ {
34+
id: 'recent',
35+
appName: t('files', 'Recent'),
36+
37+
_clientSideSort: true,
38+
_allowSelection: false,
39+
40+
/**
41+
* @private
42+
*/
43+
initialize: function () {
44+
OCA.Files.FileList.prototype.initialize.apply(this, arguments);
45+
if (this.initialized) {
46+
return;
47+
}
48+
OC.Plugins.attach('OCA.Files.RecentFileList', this);
49+
},
50+
51+
updateEmptyContent: function () {
52+
var dir = this.getCurrentDirectory();
53+
if (dir === '/') {
54+
// root has special permissions
55+
this.$el.find('#emptycontent').toggleClass('hidden', !this.isEmpty);
56+
this.$el.find('#filestable thead th').toggleClass('hidden', this.isEmpty);
57+
}
58+
else {
59+
OCA.Files.FileList.prototype.updateEmptyContent.apply(this, arguments);
60+
}
61+
},
62+
63+
getDirectoryPermissions: function () {
64+
return OC.PERMISSION_READ | OC.PERMISSION_DELETE;
65+
},
66+
67+
updateStorageStatistics: function () {
68+
// no op because it doesn't have
69+
// storage info like free space / used space
70+
},
71+
72+
reload: function () {
73+
this.showMask();
74+
if (this._reloadCall) {
75+
this._reloadCall.abort();
76+
}
77+
78+
// there is only root
79+
this._setCurrentDir('/', false);
80+
81+
this._reloadCall = $.ajax({
82+
url: OC.generateUrl('/apps/files/api/v1/recent'),
83+
type: 'GET',
84+
dataType: 'json'
85+
});
86+
var callBack = this.reloadCallback.bind(this);
87+
return this._reloadCall.then(callBack, callBack);
88+
},
89+
90+
reloadCallback: function (result) {
91+
delete this._reloadCall;
92+
this.hideMask();
93+
94+
if (result.files) {
95+
this.setFiles(result.files.sort(this._sortComparator));
96+
return true;
97+
}
98+
return false;
99+
}
100+
});
101+
102+
OCA.Files.RecentFileList = RecentFileList;
103+
})(OCA);
104+
});
105+

apps/files/js/recentplugin.js

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
/*
2+
* Copyright (c) 2014 Vincent Petry <[email protected]>
3+
*
4+
* This file is licensed under the Affero General Public License version 3
5+
* or later.
6+
*
7+
* See the COPYING-README file.
8+
*
9+
*/
10+
11+
(function (OCA) {
12+
/**
13+
* @namespace OCA.Files.RecentPlugin
14+
*
15+
* Registers the recent file list from the files app sidebar.
16+
*/
17+
OCA.Files.RecentPlugin = {
18+
name: 'Recent',
19+
20+
/**
21+
* @type OCA.Files.RecentFileList
22+
*/
23+
recentFileList: null,
24+
25+
attach: function () {
26+
var self = this;
27+
$('#app-content-recent').on('show.plugin-recent', function (e) {
28+
self.showFileList($(e.target));
29+
});
30+
$('#app-content-recent').on('hide.plugin-recent', function () {
31+
self.hideFileList();
32+
});
33+
},
34+
35+
detach: function () {
36+
if (this.recentFileList) {
37+
this.recentFileList.destroy();
38+
OCA.Files.fileActions.off('setDefault.plugin-recent', this._onActionsUpdated);
39+
OCA.Files.fileActions.off('registerAction.plugin-recent', this._onActionsUpdated);
40+
$('#app-content-recent').off('.plugin-recent');
41+
this.recentFileList = null;
42+
}
43+
},
44+
45+
showFileList: function ($el) {
46+
if (!this.recentFileList) {
47+
this.recentFileList = this._createRecentFileList($el);
48+
}
49+
return this.recentFileList;
50+
},
51+
52+
hideFileList: function () {
53+
if (this.recentFileList) {
54+
this.recentFileList.$fileList.empty();
55+
}
56+
},
57+
58+
/**
59+
* Creates the recent file list.
60+
*
61+
* @param $el container for the file list
62+
* @return {OCA.Files.RecentFileList} file list
63+
*/
64+
_createRecentFileList: function ($el) {
65+
var fileActions = this._createFileActions();
66+
// register recent list for sidebar section
67+
return new OCA.Files.RecentFileList(
68+
$el, {
69+
fileActions: fileActions,
70+
scrollContainer: $('#app-content')
71+
}
72+
);
73+
},
74+
75+
_createFileActions: function () {
76+
// inherit file actions from the files app
77+
var fileActions = new OCA.Files.FileActions();
78+
// note: not merging the legacy actions because legacy apps are not
79+
// compatible with the sharing overview and need to be adapted first
80+
fileActions.registerDefaultActions();
81+
fileActions.merge(OCA.Files.fileActions);
82+
83+
if (!this._globalActionsInitialized) {
84+
// in case actions are registered later
85+
this._onActionsUpdated = _.bind(this._onActionsUpdated, this);
86+
OCA.Files.fileActions.on('setDefault.plugin-recent', this._onActionsUpdated);
87+
OCA.Files.fileActions.on('registerAction.plugin-recent', this._onActionsUpdated);
88+
this._globalActionsInitialized = true;
89+
}
90+
91+
// when the user clicks on a folder, redirect to the corresponding
92+
// folder in the files app instead of opening it directly
93+
fileActions.register('dir', 'Open', OC.PERMISSION_READ, '', function (filename, context) {
94+
OCA.Files.App.setActiveView('files', {silent: true});
95+
var path = OC.joinPaths(context.$file.attr('data-path'), filename);
96+
OCA.Files.App.fileList.changeDirectory(path, true, true);
97+
});
98+
fileActions.setDefault('dir', 'Open');
99+
return fileActions;
100+
},
101+
102+
_onActionsUpdated: function (ev) {
103+
if (ev.action) {
104+
this.recentFileList.fileActions.registerAction(ev.action);
105+
} else if (ev.defaultAction) {
106+
this.recentFileList.fileActions.setDefault(
107+
ev.defaultAction.mime,
108+
ev.defaultAction.name
109+
);
110+
}
111+
}
112+
};
113+
114+
})(OCA);
115+
116+
OC.Plugins.register('OCA.Files.App', OCA.Files.RecentPlugin);
117+

apps/files/lib/AppInfo/Application.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,8 @@ public function __construct(array $urlParams=array()) {
4646
$c->query('TagService'),
4747
$server->getPreviewManager(),
4848
$server->getShareManager(),
49-
$server->getConfig()
49+
$server->getConfig(),
50+
$server->getUserFolder()
5051
);
5152
});
5253

0 commit comments

Comments
 (0)