fix default value, update js/php tests
This commit is contained in:
parent
a4683bcfa9
commit
576f7244e6
|
@ -34,6 +34,7 @@ use OCP\IConfig;
|
||||||
use OCP\IRequest;
|
use OCP\IRequest;
|
||||||
use OCP\AppFramework\Http\DataResponse;
|
use OCP\AppFramework\Http\DataResponse;
|
||||||
use OCP\AppFramework\Http\DataDisplayResponse;
|
use OCP\AppFramework\Http\DataDisplayResponse;
|
||||||
|
use OCP\AppFramework\Http\Response;
|
||||||
use OCA\Files\Service\TagService;
|
use OCA\Files\Service\TagService;
|
||||||
use OCP\IPreview;
|
use OCP\IPreview;
|
||||||
use OCP\Share\IManager;
|
use OCP\Share\IManager;
|
||||||
|
@ -201,14 +202,26 @@ class ApiController extends Controller {
|
||||||
return $shareTypes;
|
return $shareTypes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Change the default sort mode
|
||||||
|
*
|
||||||
|
* @NoAdminRequired
|
||||||
|
*
|
||||||
|
* @param string $mode
|
||||||
|
* @param string $direction
|
||||||
|
* @return Response
|
||||||
|
*/
|
||||||
public function updateFileSorting($mode, $direction) {
|
public function updateFileSorting($mode, $direction) {
|
||||||
$allowedMode = ['name', 'size', 'mtime'];
|
$allowedMode = ['name', 'size', 'mtime'];
|
||||||
$allowedDirection = ['asc', 'desc'];
|
$allowedDirection = ['asc', 'desc'];
|
||||||
if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
|
if (!in_array($mode, $allowedMode) || !in_array($direction, $allowedDirection)) {
|
||||||
return $this->buildResponse(null)->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
|
$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', $mode);
|
||||||
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
|
$this->config->setUserValue($this->userSession->getUser()->getUID(), 'files', 'file_sorting_direction', $direction);
|
||||||
|
return new Response();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -221,7 +221,7 @@ class ViewController extends Controller {
|
||||||
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
|
$params['allowShareWithLink'] = $this->config->getAppValue('core', 'shareapi_allow_links', 'yes');
|
||||||
$user = $this->userSession->getUser()->getUID();
|
$user = $this->userSession->getUser()->getUID();
|
||||||
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
$params['defaultFileSorting'] = $this->config->getUserValue($user, 'files', 'file_sorting', 'name');
|
||||||
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'name');
|
$params['defaultFileSortingDirection'] = $this->config->getUserValue($user, 'files', 'file_sorting_direction', 'asc');
|
||||||
$params['appNavigation'] = $nav;
|
$params['appNavigation'] = $nav;
|
||||||
$params['appContents'] = $contentItems;
|
$params['appContents'] = $contentItems;
|
||||||
$this->navigationManager->setActiveEntry('files_index');
|
$this->navigationManager->setActiveEntry('files_index');
|
||||||
|
|
|
@ -240,9 +240,9 @@
|
||||||
this.fileSummary = this._createSummary();
|
this.fileSummary = this._createSummary();
|
||||||
|
|
||||||
if (options.sorting) {
|
if (options.sorting) {
|
||||||
this.setSort(options.sorting.mode, options.sorting.direction);
|
this.setSort(options.sorting.mode, options.sorting.direction, false, false);
|
||||||
} else {
|
} else {
|
||||||
this.setSort('name', 'asc');
|
this.setSort('name', 'asc', false, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
var breadcrumbOptions = {
|
var breadcrumbOptions = {
|
||||||
|
@ -694,14 +694,14 @@
|
||||||
sort = $target.attr('data-sort');
|
sort = $target.attr('data-sort');
|
||||||
if (sort) {
|
if (sort) {
|
||||||
if (this._sort === 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 {
|
else {
|
||||||
if ( sort === 'name' ) { //default sorting of name is opposite to size and mtime
|
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 {
|
else {
|
||||||
this.setSort(sort, 'desc', true);
|
this.setSort(sort, 'desc', true, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1369,8 +1369,9 @@
|
||||||
* @param sort sort attribute name
|
* @param sort sort attribute name
|
||||||
* @param direction sort direction, one of "asc" or "desc"
|
* @param direction sort direction, one of "asc" or "desc"
|
||||||
* @param update true to update the list, false otherwise (default)
|
* @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;
|
var comparator = FileList.Comparators[sort] || FileList.Comparators.name;
|
||||||
this._sort = sort;
|
this._sort = sort;
|
||||||
this._sortDirection = (direction === 'desc')?'desc':'asc';
|
this._sortDirection = (direction === 'desc')?'desc':'asc';
|
||||||
|
@ -1402,10 +1403,12 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (persist) {
|
||||||
$.post(OC.generateUrl('/apps/files/api/v1/sorting'), {
|
$.post(OC.generateUrl('/apps/files/api/v1/sorting'), {
|
||||||
mode: sort,
|
mode: sort,
|
||||||
direction: direction
|
direction: direction
|
||||||
});
|
});
|
||||||
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
* @author Joas Schilling <nickvergessen@owncloud.com>
|
* @author Joas Schilling <nickvergessen@owncloud.com>
|
||||||
* @author Lukas Reschke <lukas@owncloud.com>
|
* @author Lukas Reschke <lukas@owncloud.com>
|
||||||
* @author Vincent Petry <pvince81@owncloud.com>
|
* @author Vincent Petry <pvince81@owncloud.com>
|
||||||
|
@ -33,6 +34,7 @@ use OCP\AppFramework\Http\RedirectResponse;
|
||||||
use OCP\INavigationManager;
|
use OCP\INavigationManager;
|
||||||
use OCP\IL10N;
|
use OCP\IL10N;
|
||||||
use OCP\IConfig;
|
use OCP\IConfig;
|
||||||
|
use OCP\IUserSession;
|
||||||
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -55,6 +57,10 @@ class ViewControllerTest extends TestCase {
|
||||||
private $eventDispatcher;
|
private $eventDispatcher;
|
||||||
/** @var ViewController */
|
/** @var ViewController */
|
||||||
private $viewController;
|
private $viewController;
|
||||||
|
/** @var IUser */
|
||||||
|
private $user;
|
||||||
|
/** @var IUserSession */
|
||||||
|
private $userSession;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
parent::setUp();
|
parent::setUp();
|
||||||
|
@ -64,6 +70,11 @@ class ViewControllerTest extends TestCase {
|
||||||
$this->l10n = $this->getMock('\OCP\IL10N');
|
$this->l10n = $this->getMock('\OCP\IL10N');
|
||||||
$this->config = $this->getMock('\OCP\IConfig');
|
$this->config = $this->getMock('\OCP\IConfig');
|
||||||
$this->eventDispatcher = $this->getMock('\Symfony\Component\EventDispatcher\EventDispatcherInterface');
|
$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')
|
$this->viewController = $this->getMockBuilder('\OCA\Files\Controller\ViewController')
|
||||||
->setConstructorArgs([
|
->setConstructorArgs([
|
||||||
'files',
|
'files',
|
||||||
|
@ -72,7 +83,8 @@ class ViewControllerTest extends TestCase {
|
||||||
$this->navigationManager,
|
$this->navigationManager,
|
||||||
$this->l10n,
|
$this->l10n,
|
||||||
$this->config,
|
$this->config,
|
||||||
$this->eventDispatcher
|
$this->eventDispatcher,
|
||||||
|
$this->userSession
|
||||||
])
|
])
|
||||||
->setMethods([
|
->setMethods([
|
||||||
'getStorageInfo',
|
'getStorageInfo',
|
||||||
|
@ -143,6 +155,12 @@ class ViewControllerTest extends TestCase {
|
||||||
'owner' => 'MyName',
|
'owner' => 'MyName',
|
||||||
'ownerDisplayName' => 'MyDisplayName',
|
'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
|
$this->config
|
||||||
->expects($this->any())
|
->expects($this->any())
|
||||||
|
@ -224,6 +242,8 @@ class ViewControllerTest extends TestCase {
|
||||||
'owner' => 'MyName',
|
'owner' => 'MyName',
|
||||||
'ownerDisplayName' => 'MyDisplayName',
|
'ownerDisplayName' => 'MyDisplayName',
|
||||||
'isPublic' => false,
|
'isPublic' => false,
|
||||||
|
'defaultFileSorting' => 'name',
|
||||||
|
'defaultFileSortingDirection' => 'asc',
|
||||||
'mailNotificationEnabled' => 'no',
|
'mailNotificationEnabled' => 'no',
|
||||||
'mailPublicNotificationEnabled' => 'no',
|
'mailPublicNotificationEnabled' => 'no',
|
||||||
'allowShareWithLink' => 'yes',
|
'allowShareWithLink' => 'yes',
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
<?php
|
<?php
|
||||||
/**
|
/**
|
||||||
|
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
|
||||||
* @author Lukas Reschke <lukas@owncloud.com>
|
* @author Lukas Reschke <lukas@owncloud.com>
|
||||||
* @author Morris Jobke <hey@morrisjobke.de>
|
* @author Morris Jobke <hey@morrisjobke.de>
|
||||||
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
* @author Roeland Jago Douma <rullzer@owncloud.com>
|
||||||
|
@ -43,6 +44,8 @@ use OCP\Image;
|
||||||
class ApiControllerTest extends TestCase {
|
class ApiControllerTest extends TestCase {
|
||||||
/** @var string */
|
/** @var string */
|
||||||
private $appName = 'files';
|
private $appName = 'files';
|
||||||
|
/** @var \OCP\IUser */
|
||||||
|
private $user;
|
||||||
/** @var IRequest */
|
/** @var IRequest */
|
||||||
private $request;
|
private $request;
|
||||||
/** @var TagService */
|
/** @var TagService */
|
||||||
|
@ -53,19 +56,21 @@ class ApiControllerTest extends TestCase {
|
||||||
private $apiController;
|
private $apiController;
|
||||||
/** @var \OCP\Share\IManager */
|
/** @var \OCP\Share\IManager */
|
||||||
private $shareManager;
|
private $shareManager;
|
||||||
|
/** @var \OCP\IConfig */
|
||||||
|
private $config;
|
||||||
|
|
||||||
public function setUp() {
|
public function setUp() {
|
||||||
$this->request = $this->getMockBuilder('\OCP\IRequest')
|
$this->request = $this->getMockBuilder('\OCP\IRequest')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
$user = $this->getMock('\OCP\IUser');
|
$this->user = $this->getMock('\OCP\IUser');
|
||||||
$user->expects($this->any())
|
$this->user->expects($this->any())
|
||||||
->method('getUID')
|
->method('getUID')
|
||||||
->will($this->returnValue('user1'));
|
->will($this->returnValue('user1'));
|
||||||
$userSession = $this->getMock('\OCP\IUserSession');
|
$userSession = $this->getMock('\OCP\IUserSession');
|
||||||
$userSession->expects($this->any())
|
$userSession->expects($this->any())
|
||||||
->method('getUser')
|
->method('getUser')
|
||||||
->will($this->returnValue($user));
|
->will($this->returnValue($this->user));
|
||||||
$this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService')
|
$this->tagService = $this->getMockBuilder('\OCA\Files\Service\TagService')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
@ -75,6 +80,7 @@ class ApiControllerTest extends TestCase {
|
||||||
$this->preview = $this->getMockBuilder('\OCP\IPreview')
|
$this->preview = $this->getMockBuilder('\OCP\IPreview')
|
||||||
->disableOriginalConstructor()
|
->disableOriginalConstructor()
|
||||||
->getMock();
|
->getMock();
|
||||||
|
$this->config = $this->getMock('\OCP\IConfig');
|
||||||
|
|
||||||
$this->apiController = new ApiController(
|
$this->apiController = new ApiController(
|
||||||
$this->appName,
|
$this->appName,
|
||||||
|
@ -82,7 +88,8 @@ class ApiControllerTest extends TestCase {
|
||||||
$userSession,
|
$userSession,
|
||||||
$this->tagService,
|
$this->tagService,
|
||||||
$this->preview,
|
$this->preview,
|
||||||
$this->shareManager
|
$this->shareManager,
|
||||||
|
$this->config
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,4 +342,44 @@ class ApiControllerTest extends TestCase {
|
||||||
|
|
||||||
$this->assertEquals(Http::STATUS_OK, $ret->getStatus());
|
$this->assertEquals(Http::STATUS_OK, $ret->getStatus());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testUpdateFileSorting() {
|
||||||
|
$mode = 'mtime';
|
||||||
|
$direction = 'desc';
|
||||||
|
|
||||||
|
$this->config->expects($this->at(0))
|
||||||
|
->method('setUserValue')
|
||||||
|
->with($this->user->getUID(), 'files', 'file_sorting', $mode);
|
||||||
|
$this->config->expects($this->at(1))
|
||||||
|
->method('setUserValue')
|
||||||
|
->with($this->user->getUID(), 'files', 'file_sorting_direction', $direction);
|
||||||
|
|
||||||
|
$expected = new HTTP\Response();
|
||||||
|
$actual = $this->apiController->updateFileSorting($mode, $direction);
|
||||||
|
$this->assertEquals($expected, $actual);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function invalidSortingModeData() {
|
||||||
|
return [
|
||||||
|
['color', 'asc'],
|
||||||
|
['name', 'size'],
|
||||||
|
['foo', 'bar']
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider invalidSortingModeData
|
||||||
|
*/
|
||||||
|
public function testUpdateInvalidFileSorting($mode, $direction) {
|
||||||
|
$this->config->expects($this->never())
|
||||||
|
->method('setUserValue');
|
||||||
|
|
||||||
|
$expected = new Http\Response(null);
|
||||||
|
$expected->setStatus(Http::STATUS_UNPROCESSABLE_ENTITY);
|
||||||
|
|
||||||
|
$result = $this->apiController->updateFileSorting($mode, $direction);
|
||||||
|
|
||||||
|
$this->assertEquals($expected, $result);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2106,6 +2106,8 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
it('Toggles the sort indicator when clicking on a column header', function() {
|
it('Toggles the sort indicator when clicking on a column header', function() {
|
||||||
var ASC_CLASS = fileList.SORT_INDICATOR_ASC_CLASS;
|
var ASC_CLASS = fileList.SORT_INDICATOR_ASC_CLASS;
|
||||||
var DESC_CLASS = fileList.SORT_INDICATOR_DESC_CLASS;
|
var DESC_CLASS = fileList.SORT_INDICATOR_DESC_CLASS;
|
||||||
|
var request;
|
||||||
|
var sortingUrl = OC.generateUrl('/apps/files/api/v1/sorting');
|
||||||
fileList.$el.find('.column-size .columntitle').click();
|
fileList.$el.find('.column-size .columntitle').click();
|
||||||
// moves triangle to size column, check indicator on name is hidden
|
// moves triangle to size column, check indicator on name is hidden
|
||||||
expect(
|
expect(
|
||||||
|
@ -2118,6 +2120,10 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
expect(
|
expect(
|
||||||
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
// check if changes are persisted
|
||||||
|
expect(fakeServer.requests.length).toEqual(1);
|
||||||
|
request = fakeServer.requests[0];
|
||||||
|
expect(request.url).toEqual(sortingUrl);
|
||||||
|
|
||||||
// click again on size column, reverses direction
|
// click again on size column, reverses direction
|
||||||
fileList.$el.find('.column-size .columntitle').click();
|
fileList.$el.find('.column-size .columntitle').click();
|
||||||
|
@ -2127,6 +2133,10 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
expect(
|
expect(
|
||||||
fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS)
|
fileList.$el.find('.column-size .sort-indicator').hasClass(ASC_CLASS)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
// check if changes are persisted
|
||||||
|
expect(fakeServer.requests.length).toEqual(2);
|
||||||
|
request = fakeServer.requests[1];
|
||||||
|
expect(request.url).toEqual(sortingUrl);
|
||||||
|
|
||||||
// click again on size column, reverses direction
|
// click again on size column, reverses direction
|
||||||
fileList.$el.find('.column-size .columntitle').click();
|
fileList.$el.find('.column-size .columntitle').click();
|
||||||
|
@ -2136,6 +2146,9 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
expect(
|
expect(
|
||||||
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
fileList.$el.find('.column-size .sort-indicator').hasClass(DESC_CLASS)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
expect(fakeServer.requests.length).toEqual(3);
|
||||||
|
request = fakeServer.requests[2];
|
||||||
|
expect(request.url).toEqual(sortingUrl);
|
||||||
|
|
||||||
// click on mtime column, moves indicator there
|
// click on mtime column, moves indicator there
|
||||||
fileList.$el.find('.column-mtime .columntitle').click();
|
fileList.$el.find('.column-mtime .columntitle').click();
|
||||||
|
@ -2148,6 +2161,9 @@ describe('OCA.Files.FileList tests', function() {
|
||||||
expect(
|
expect(
|
||||||
fileList.$el.find('.column-mtime .sort-indicator').hasClass(DESC_CLASS)
|
fileList.$el.find('.column-mtime .sort-indicator').hasClass(DESC_CLASS)
|
||||||
).toEqual(true);
|
).toEqual(true);
|
||||||
|
expect(fakeServer.requests.length).toEqual(4);
|
||||||
|
request = fakeServer.requests[3];
|
||||||
|
expect(request.url).toEqual(sortingUrl);
|
||||||
});
|
});
|
||||||
it('Uses correct sort comparator when inserting files', function() {
|
it('Uses correct sort comparator when inserting files', function() {
|
||||||
testFiles.sort(OCA.Files.FileList.Comparators.size);
|
testFiles.sort(OCA.Files.FileList.Comparators.size);
|
||||||
|
|
Loading…
Reference in New Issue