Save task list order in user session

This commit is contained in:
Timo
2020-04-23 05:40:39 +02:00
committed by GitHub
parent e089d3059a
commit 027f875ac6
3 changed files with 60 additions and 2 deletions

View File

@@ -35,11 +35,16 @@ class TaskListController extends BaseController
$formatter = $this->taskListFormatter; $formatter = $this->taskListFormatter;
} }
list($order, $direction) = $this->userSession->getListOrder($project['id']);
$direction = $this->request->getStringParam('direction', $direction);
$order = $this->request->getStringParam('order', $order);
$this->userSession->setListOrder($project['id'], $order, $direction);
$paginator = $this->paginator $paginator = $this->paginator
->setUrl('TaskListController', 'show', array('project_id' => $project['id'])) ->setUrl('TaskListController', 'show', array('project_id' => $project['id']))
->setMax(30) ->setMax(30)
->setOrder(TaskModel::TABLE.'.id') ->setOrder($order)
->setDirection('DESC') ->setDirection($direction)
->setFormatter($formatter) ->setFormatter($formatter)
->setQuery($this->taskLexer ->setQuery($this->taskLexer
->build($search) ->build($search)

View File

@@ -240,4 +240,35 @@ class UserSession extends Base
{ {
session_set('filters:'.$projectID, $filters); session_set('filters:'.$projectID, $filters);
} }
/**
* Get project list order from the session
*
* @access public
* @param integer $projectID
* @return array
*/
public function getListOrder($projectID)
{
$default = ['tasks.id', 'DESC'];
if (! session_exists('listOrder:'.$projectID)) {
return $default;
}
return session_get('listOrder:'.$projectID);
}
/**
* Save project list order in the session
*
* @access public
* @param integer $projectID
* @param string $listOrder
* @param string $listDirection
*/
public function setListOrder($projectID, $listOrder, $listDirection)
{
session_set('listOrder:'.$projectID, [$listOrder, $listDirection]);
}
} }

View File

@@ -97,6 +97,28 @@ class UserSessionTest extends Base
$this->assertEquals('assignee:bob', $userSession->getFilters(2)); $this->assertEquals('assignee:bob', $userSession->getFilters(2));
} }
public function testListOrder()
{
$userSession = new UserSession($this->container);
list($order, $direction) = $userSession->getListOrder(1);
$this->assertEquals('tasks.id', $order);
$this->assertEquals('DESC', $direction);
$userSession->setListOrder(1, 'tasks.priority', 'ASC');
list($order, $direction) = $userSession->getListOrder(1);
$this->assertEquals('tasks.priority', $order);
$this->assertEquals('ASC', $direction);
list($order, $direction) = $userSession->getListOrder(2);
$this->assertEquals('tasks.id', $order);
$this->assertEquals('DESC', $direction);
$userSession->setListOrder(2, 'tasks.is_active', 'DESC');
list($order, $direction) = $userSession->getListOrder(2);
$this->assertEquals('tasks.is_active', $order);
$this->assertEquals('DESC', $direction);
}
public function testPostAuthentication() public function testPostAuthentication()
{ {
$userSession = new UserSession($this->container); $userSession = new UserSession($this->container);