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
3 changes: 2 additions & 1 deletion apps/files/appinfo/application.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ public function __construct(array $urlParams=array()) {
$server->getUserSession(),
$c->query('TagService'),
$server->getPreviewManager(),
$server->getShareManager()
$server->getShareManager(),
$server->getConfig()
);
});

Expand Down
6 changes: 6 additions & 0 deletions apps/files/appinfo/routes.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @author Bart Visscher <[email protected]>
* @author Christoph Wurst <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
* @author Tobias Kaminsky <[email protected]>
Expand Down Expand Up @@ -48,6 +49,11 @@
'verb' => 'GET',
'requirements' => array('tagName' => '.+'),
),
array(
'name' => 'API#updateFileSorting',
'url' => '/api/v1/sorting',
'verb' => 'POST'
),
[
'name' => 'view#index',
'url' => '/',
Expand Down
32 changes: 30 additions & 2 deletions apps/files/controller/apicontroller.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
/**
* @author Joas Schilling <[email protected]>
* @author Christoph Wurst <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Morris Jobke <[email protected]>
* @author Roeland Jago Douma <[email protected]>
Expand Down Expand Up @@ -29,13 +30,14 @@

use OCP\AppFramework\Http;
use OCP\AppFramework\Controller;
use OCP\IConfig;
use OCP\IRequest;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\Http\DataDisplayResponse;
use OCP\AppFramework\Http\Response;
use OCA\Files\Service\TagService;
use OCP\IPreview;
use OCP\Share\IManager;
use OCP\Files\FileInfo;
use OCP\Files\Node;
use OCP\IUserSession;

Expand All @@ -53,6 +55,8 @@ class ApiController extends Controller {
private $previewManager;
/** IUserSession */
private $userSession;
/** IConfig */
private $config;

/**
* @param string $appName
Expand All @@ -65,12 +69,14 @@ public function __construct($appName,
IUserSession $userSession,
TagService $tagService,
IPreview $previewManager,
IManager $shareManager) {
IManager $shareManager,
IConfig $config) {
parent::__construct($appName, $request);
$this->userSession = $userSession;
$this->tagService = $tagService;
$this->previewManager = $previewManager;
$this->shareManager = $shareManager;
$this->config = $config;
}

/**
Expand Down Expand Up @@ -196,4 +202,26 @@ private function getShareTypes(Node $node) {
return $shareTypes;
}

/**
* Change the default sort mode
*
* @NoAdminRequired
*
* @param string $mode
* @param string $direction
* @return Response
*/
public function updateFileSorting($mode, $direction) {
$allowedMode = ['name', 'size', 'mtime'];
$allowedDirection = ['asc', 'desc'];
if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
$response = new Response();
$response->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
return $response;
}
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
return new Response();
}

}
13 changes: 11 additions & 2 deletions apps/files/controller/viewcontroller.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**
* @author Christoph Wurst <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Thomas Müller <[email protected]>
*
Expand Down Expand Up @@ -27,11 +28,12 @@
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\RedirectResponse;
use OCP\AppFramework\Http\TemplateResponse;
use OCP\IConfig;
use OCP\IL10N;
use OCP\INavigationManager;
use OCP\IRequest;
use OCP\IURLGenerator;
use OCP\IConfig;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand All @@ -54,6 +56,8 @@ class ViewController extends Controller {
protected $config;
/** @var EventDispatcherInterface */
protected $eventDispatcher;
/** @var IUserSession */
protected $userSession;

/**
* @param string $appName
Expand All @@ -70,7 +74,8 @@ public function __construct($appName,
INavigationManager $navigationManager,
IL10N $l10n,
IConfig $config,
EventDispatcherInterface $eventDispatcherInterface) {
EventDispatcherInterface $eventDispatcherInterface,
IUserSession $userSession) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->request = $request;
Expand All @@ -79,6 +84,7 @@ public function __construct($appName,
$this->l10n = $l10n;
$this->config = $config;
$this->eventDispatcher = $eventDispatcherInterface;
$this->userSession = $userSession;
}

/**
Expand Down Expand Up @@ -213,6 +219,9 @@ public function index($dir = '', $view = '') {
$params['mailNotificationEnabled'] = $this->config->getAppValue('core', 'shareapi_allow_mail_notification', 'no');
$params['mailPublicNotificationEnabled'] = $this->config->getAppValue('core', 'shareapi_allow_public_notification', 'no');
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
$user = $this->userSession->getUser()->getUID();
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
$this->navigationManager->setActiveEntry('files_index');
Expand Down
6 changes: 5 additions & 1 deletion apps/files/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,11 @@
fileActions: fileActions,
allowLegacyActions: true,
scrollTo: urlParams.scrollto,
filesClient: OC.Files.getClient()
filesClient: OC.Files.getClient(),
sorting: {
mode: $('#defaultFileSorting').val(),
direction: $('#defaultFileSortingDirection').val()
}
}
);
this.files.initialize();
Expand Down
22 changes: 17 additions & 5 deletions apps/files/js/filelist.js
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,11 @@

this.fileSummary = this._createSummary();

this.setSort('name', 'asc');
if (options.sorting) {
this.setSort(options.sorting.mode, options.sorting.direction, false, false);
} else {
this.setSort('name', 'asc', false, false);
}

var breadcrumbOptions = {
onClick: _.bind(this._onClickBreadCrumb, this),
Expand Down Expand Up @@ -690,14 +694,14 @@
sort = $target.attr('data-sort');
if (sort) {
if (this._sort === sort) {
this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc', true);
this.setSort(sort, (this._sortDirection === 'desc')?'asc':'desc', true, true);
}
else {
if ( sort === 'name' ) { //default sorting of name is opposite to size and mtime
this.setSort(sort, 'asc', true);
this.setSort(sort, 'asc', true, true);
}
else {
this.setSort(sort, 'desc', true);
this.setSort(sort, 'desc', true, true);
}
}
}
Expand Down Expand Up @@ -1365,8 +1369,9 @@
* @param sort sort attribute name
* @param direction sort direction, one of "asc" or "desc"
* @param update true to update the list, false otherwise (default)
* @param persist true to save changes in the database (default)
*/
setSort: function(sort, direction, update) {
setSort: function(sort, direction, update, persist) {
var comparator = FileList.Comparators[sort] || FileList.Comparators.name;
this._sort = sort;
this._sortDirection = (direction === 'desc')?'desc':'asc';
Expand Down Expand Up @@ -1397,6 +1402,13 @@
this.reload();
}
}

if (persist) {
$.post(OC.generateUrl('/apps/files/api/v1/sorting'), {
mode: sort,
direction: direction
});
}
},

/**
Expand Down
2 changes: 2 additions & 0 deletions apps/files/templates/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,6 @@
<input type="hidden" name="mailNotificationEnabled" id="mailNotificationEnabled" value="<?php p($_['mailNotificationEnabled']) ?>" />
<input type="hidden" name="mailPublicNotificationEnabled" id="mailPublicNotificationEnabled" value="<?php p($_['mailPublicNotificationEnabled']) ?>" />
<input type="hidden" name="allowShareWithLink" id="allowShareWithLink" value="<?php p($_['allowShareWithLink']) ?>" />
<input type="hidden" name="defaultFileSorting" id="defaultFileSorting" value="<?php p($_['defaultFileSorting']) ?>" />
<input type="hidden" name="defaultFileSortingDirection" id="defaultFileSortingDirection" value="<?php p($_['defaultFileSortingDirection']) ?>" />
<?php endif;
22 changes: 21 additions & 1 deletion apps/files/tests/controller/ViewControllerTest.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php
/**
* @author Christoph Wurst <[email protected]>
* @author Joas Schilling <[email protected]>
* @author Lukas Reschke <[email protected]>
* @author Vincent Petry <[email protected]>
Expand Down Expand Up @@ -33,6 +34,7 @@
use OCP\INavigationManager;
use OCP\IL10N;
use OCP\IConfig;
use OCP\IUserSession;
use Symfony\Component\EventDispatcher\EventDispatcherInterface;

/**
Expand All @@ -55,6 +57,10 @@ class ViewControllerTest extends TestCase {
private $eventDispatcher;
/** @var ViewController */
private $viewController;
/** @var IUser */
private $user;
/** @var IUserSession */
private $userSession;

public function setUp() {
parent::setUp();
Expand All @@ -64,6 +70,11 @@ public function setUp() {
$this->l10n = $this->getMock('\OCP\IL10N');
$this->config = $this->getMock('\OCP\IConfig');
$this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
$this->userSession = $this->getMock('\OCP\IUserSession');
$this->user = $this->getMock('\OCP\IUser');
$this->userSession->expects($this->any())
->method('getUser')
->will($this->returnValue($this->user));
$this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
->setConstructorArgs([
'files',
Expand All @@ -72,7 +83,8 @@ public function setUp() {
$this->navigationManager,
$this->l10n,
$this->config,
$this->eventDispatcher
$this->eventDispatcher,
$this->userSession
])
->setMethods([
'getStorageInfo',
Expand Down Expand Up @@ -143,6 +155,12 @@ public function testIndexWithRegularBrowser() {
'owner' => 'MyName',
'ownerDisplayName' => 'MyDisplayName',
]));
$this->config->expects($this->exactly(2))
->method('getUserValue')
->will($this->returnValueMap([
[$this->user->getUID(), 'files', 'file_sorting', 'name', 'name'],
[$this->user->getUID(), 'files', 'file_sorting_direction', 'asc', 'asc']
]));

$this->config
->expects($this->any())
Expand Down Expand Up @@ -224,6 +242,8 @@ public function testIndexWithRegularBrowser() {
'owner' => 'MyName',
'ownerDisplayName' => 'MyDisplayName',
'isPublic' => false,
'defaultFileSorting' => 'name',
'defaultFileSortingDirection' => 'asc',
'mailNotificationEnabled' => 'no',
'mailPublicNotificationEnabled' => 'no',
'allowShareWithLink' => 'yes',
Expand Down
Loading