persist file sorting changes

remotes/origin/laravel-queue
Christoph Wurst 8 years ago
parent 3f492dd826
commit a4683bcfa9

@ -43,7 +43,8 @@ class Application extends App {
$server->getUserSession(),
$c->query('TagService'),
$server->getPreviewManager(),
$server->getShareManager()
$server->getShareManager(),
$server->getConfig()
);
});

@ -1,6 +1,7 @@
<?php
/**
* @author Bart Visscher <bartv@thisnet.nl>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Lukas Reschke <lukas@owncloud.com>
* @author Roeland Jago Douma <rullzer@owncloud.com>
* @author Tobias Kaminsky <tobias@kaminsky.me>
@ -48,6 +49,11 @@ $application->registerRoutes(
'verb' => 'GET',
'requirements' => array('tagName' => '.+'),
),
array(
'name' => 'API#updateFileSorting',
'url' => '/api/v1/sorting',
'verb' => 'POST'
),
[
'name' => 'view#index',
'url' => '/',

@ -1,6 +1,7 @@
<?php
/**
* @author Joas Schilling <nickvergessen@owncloud.com>
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Lukas Reschke <lukas@owncloud.com>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <rullzer@owncloud.com>
@ -29,13 +30,13 @@ namespace OCA\Files\Controller;
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 OCA\Files\Service\TagService;
use OCP\IPreview;
use OCP\Share\IManager;
use OCP\Files\FileInfo;
use OCP\Files\Node;
use OCP\IUserSession;
@ -53,6 +54,8 @@ class ApiController extends Controller {
private $previewManager;
/** IUserSession */
private $userSession;
/** IConfig */
private $config;
/**
* @param string $appName
@ -65,12 +68,14 @@ class ApiController extends Controller {
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;
}
/**
@ -196,4 +201,14 @@ class ApiController extends Controller {
return $shareTypes;
}
public function updateFileSorting($mode, $direction) {
$allowedMode = ['name', 'size', 'mtime'];
$allowedDirection = ['asc', 'desc'];
if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
return $this->buildResponse(null)->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
}
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting', $mode);
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
}
}

@ -1,5 +1,6 @@
<?php
/**
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Lukas Reschke <lukas@owncloud.com>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
@ -27,11 +28,12 @@ use OCP\AppFramework\Controller;
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;
/**
@ -54,6 +56,8 @@ class ViewController extends Controller {
protected $config;
/** @var EventDispatcherInterface */
protected $eventDispatcher;
/** @var IUserSession */
protected $userSession;
/**
* @param string $appName
@ -70,7 +74,8 @@ class ViewController extends Controller {
INavigationManager $navigationManager,
IL10N $l10n,
IConfig $config,
EventDispatcherInterface $eventDispatcherInterface) {
EventDispatcherInterface $eventDispatcherInterface,
IUserSession $userSession) {
parent::__construct($appName, $request);
$this->appName = $appName;
$this->request = $request;
@ -79,6 +84,7 @@ class ViewController extends Controller {
$this->l10n = $l10n;
$this->config = $config;
$this->eventDispatcher = $eventDispatcherInterface;
$this->userSession = $userSession;
}
/**
@ -213,7 +219,9 @@ class ViewController extends Controller {
$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');
$params['defaultFileSorting'] = $this->config->getAppValue('files', 'file_sorting', 'name');
$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', 'name');
$params['appNavigation'] = $nav;
$params['appContents'] = $contentItems;
$this->navigationManager->setActiveEntry('files_index');

@ -73,7 +73,10 @@
allowLegacyActions: true,
scrollTo: urlParams.scrollto,
filesClient: OC.Files.getClient(),
sorting: $('#defaultFileSorting').val()
sorting: {
mode: $('#defaultFileSorting').val(),
direction: $('#defaultFileSortingDirection').val()
}
}
);
this.files.initialize();

@ -240,7 +240,7 @@
this.fileSummary = this._createSummary();
if (options.sorting) {
this.setSort(options.sorting, 'asc');
this.setSort(options.sorting.mode, options.sorting.direction);
} else {
this.setSort('name', 'asc');
}
@ -1401,6 +1401,11 @@
this.reload();
}
}
$.post(OC.generateUrl('/apps/files/api/v1/sorting'), {
mode: sort,
direction: direction
});
},
/**

@ -19,4 +19,5 @@
<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;

Loading…
Cancel
Save