diff options
author | Frédéric Guillot <fred@kanboard.net> | 2014-11-15 21:49:06 -0500 |
---|---|---|
committer | Frédéric Guillot <fred@kanboard.net> | 2014-11-15 21:49:06 -0500 |
commit | aa6fffb05a7d84a36991341610675499b6ea8a79 (patch) | |
tree | e0eb08e76e61dfc5cc56ae0bfb7daf7dda49fc99 /app/Controller | |
parent | af93754ec99d8748677dc2cfd92137a8698a90fa (diff) |
Add pagination and sorting to the dashboard
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/App.php | 132 | ||||
-rw-r--r-- | app/Controller/Project.php | 8 |
2 files changed, 130 insertions, 10 deletions
diff --git a/app/Controller/App.php b/app/Controller/App.php index 993149c5..2458800a 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -20,17 +20,137 @@ class App extends Base */ public function index() { + $paginate = $this->request->getStringParam('paginate', 'userTasks'); + $offset = $this->request->getIntegerParam('offset', 0); + $direction = $this->request->getStringParam('direction'); + $order = $this->request->getStringParam('order'); + $user_id = $this->acl->getUserId(); $projects = $this->projectPermission->getMemberProjects($user_id); $project_ids = array_keys($projects); - $this->response->html($this->template->layout('app/index', array( + $params = array( + 'title' => t('Dashboard'), 'board_selector' => $this->projectPermission->getAllowedProjects($user_id), 'events' => $this->projectActivity->getProjects($project_ids, 10), - 'tasks' => $this->taskFinder->getAllTasksByUser($user_id), - 'subtasks' => $this->subTask->getAllByUser($user_id, array(SubTask::STATUS_TODO, SubTask::STATUS_INPROGRESS)), - 'projects' => $this->project->getSummary($project_ids), - 'title' => t('Dashboard'), - ))); + ); + + $params += $this->getTaskPagination($user_id, $paginate, $offset, $order, $direction); + $params += $this->getSubtaskPagination($user_id, $paginate, $offset, $order, $direction); + $params += $this->getProjectPagination($project_ids, $paginate, $offset, $order, $direction); + + $this->response->html($this->template->layout('app/dashboard', $params)); + } + + /** + * Get tasks pagination + * + * @access public + */ + private function getTaskPagination($user_id, $paginate, $offset, $order, $direction) + { + $limit = 10; + + if (! in_array($order, array('tasks.id', 'project_name', 'title'))) { + $order = 'tasks.id'; + $direction = 'ASC'; + } + + if ($paginate === 'userTasks') { + $tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit, $order, $direction); + } + else { + $offset = 0; + $tasks = $this->taskPaginator->userTasks($user_id, $offset, $limit); + } + + return array( + 'tasks' => $tasks, + 'task_pagination' => array( + 'controller' => 'app', + 'action' => 'index', + 'params' => array('paginate' => 'userTasks'), + 'direction' => $direction, + 'order' => $order, + 'total' => $this->taskPaginator->countUserTasks($user_id), + 'offset' => $offset, + 'limit' => $limit, + ) + ); + } + + /** + * Get subtasks pagination + * + * @access public + */ + private function getSubtaskPagination($user_id, $paginate, $offset, $order, $direction) + { + $status = array(SubTask::STATUS_TODO, SubTask::STATUS_INPROGRESS); + $limit = 10; + + if (! in_array($order, array('tasks.id', 'project_name', 'status', 'title'))) { + $order = 'tasks.id'; + $direction = 'ASC'; + } + + if ($paginate === 'userSubtasks') { + $subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit, $order, $direction); + } + else { + $offset = 0; + $subtasks = $this->subtaskPaginator->userSubtasks($user_id, $status, $offset, $limit); + } + + return array( + 'subtasks' => $subtasks, + 'subtask_pagination' => array( + 'controller' => 'app', + 'action' => 'index', + 'params' => array('paginate' => 'userSubtasks'), + 'direction' => $direction, + 'order' => $order, + 'total' => $this->subtaskPaginator->countUserSubtasks($user_id, $status), + 'offset' => $offset, + 'limit' => $limit, + ) + ); + } + + /** + * Get projects pagination + * + * @access public + */ + private function getProjectPagination($project_ids, $paginate, $offset, $order, $direction) + { + $limit = 5; + + if (! in_array($order, array('id', 'name'))) { + $order = 'name'; + $direction = 'ASC'; + } + + if ($paginate === 'projectSummaries') { + $projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit, $order, $direction); + } + else { + $offset = 0; + $projects = $this->projectPaginator->projectSummaries($project_ids, $offset, $limit); + } + + return array( + 'projects' => $projects, + 'project_pagination' => array( + 'controller' => 'app', + 'action' => 'index', + 'params' => array('paginate' => 'projectSummaries'), + 'direction' => $direction, + 'order' => $order, + 'total' => count($project_ids), + 'offset' => $offset, + 'limit' => $limit, + ) + ); } } diff --git a/app/Controller/Project.php b/app/Controller/Project.php index a479b1d6..cac5e0b8 100644 --- a/app/Controller/Project.php +++ b/app/Controller/Project.php @@ -428,8 +428,8 @@ class Project extends Base $limit = 25; if ($search !== '') { - $tasks = $this->taskFinder->search($project['id'], $search, $offset, $limit, $order, $direction); - $nb_tasks = $this->taskFinder->countSearch($project['id'], $search); + $tasks = $this->taskPaginator->searchTasks($project['id'], $search, $offset, $limit, $order, $direction); + $nb_tasks = $this->taskPaginator->countSearchTasks($project['id'], $search); } $this->response->html($this->template->layout('project_search', array( @@ -472,8 +472,8 @@ class Project extends Base $offset = $this->request->getIntegerParam('offset', 0); $limit = 25; - $tasks = $this->taskFinder->getClosedTasks($project['id'], $offset, $limit, $order, $direction); - $nb_tasks = $this->taskFinder->countByProjectId($project['id'], array(TaskModel::STATUS_CLOSED)); + $tasks = $this->taskPaginator->closedTasks($project['id'], $offset, $limit, $order, $direction); + $nb_tasks = $this->taskPaginator->countClosedTasks($project['id']); $this->response->html($this->template->layout('project_tasks', array( 'board_selector' => $this->projectPermission->getAllowedProjects($this->acl->getUserId()), |