diff options
Diffstat (limited to 'app/Controller/App.php')
-rw-r--r-- | app/Controller/App.php | 117 |
1 files changed, 107 insertions, 10 deletions
diff --git a/app/Controller/App.php b/app/Controller/App.php index feec4221..8a97e8c7 100644 --- a/app/Controller/App.php +++ b/app/Controller/App.php @@ -2,7 +2,8 @@ namespace Controller; -use Model\Project as ProjectModel; +use Model\Subtask as SubtaskModel; +use Model\Task as TaskModel; /** * Application controller @@ -13,21 +14,117 @@ use Model\Project as ProjectModel; class App extends Base { /** + * Check if the user is connected + * + * @access public + */ + public function status() + { + $this->response->text('OK'); + } + + /** + * User dashboard view for admins + * + * @access public + */ + public function dashboard() + { + $this->index($this->request->getIntegerParam('user_id'), 'dashboard'); + } + + /** * Dashboard for the current user * * @access public */ - public function index() + public function index($user_id = 0, $action = 'index') { - $user_id = $this->acl->getUserId(); - $projects = $this->projectPermission->getAllowedProjects($user_id); - - $this->response->html($this->template->layout('app_index', array( - 'board_selector' => $projects, - 'events' => $this->projectActivity->getProjects(array_keys($projects), 10), - 'tasks' => $this->taskFinder->getAllTasksByUser($user_id), - 'menu' => 'dashboard', + $status = array(SubTaskModel::STATUS_TODO, SubtaskModel::STATUS_INPROGRESS); + $user_id = $user_id ?: $this->userSession->getId(); + $projects = $this->projectPermission->getActiveMemberProjects($user_id); + $project_ids = array_keys($projects); + + $task_paginator = $this->paginator + ->setUrl('app', $action, array('pagination' => 'tasks', 'user_id' => $user_id)) + ->setMax(10) + ->setOrder('tasks.id') + ->setQuery($this->taskFinder->getUserQuery($user_id)) + ->calculateOnlyIf($this->request->getStringParam('pagination') === 'tasks'); + + $subtask_paginator = $this->paginator + ->setUrl('app', $action, array('pagination' => 'subtasks', 'user_id' => $user_id)) + ->setMax(10) + ->setOrder('tasks.id') + ->setQuery($this->subtask->getUserQuery($user_id, $status)) + ->calculateOnlyIf($this->request->getStringParam('pagination') === 'subtasks'); + + $project_paginator = $this->paginator + ->setUrl('app', $action, array('pagination' => 'projects', 'user_id' => $user_id)) + ->setMax(10) + ->setOrder('name') + ->setQuery($this->project->getQueryColumnStats($project_ids)) + ->calculateOnlyIf($this->request->getStringParam('pagination') === 'projects'); + + $this->response->html($this->template->layout('app/dashboard', array( 'title' => t('Dashboard'), + 'board_selector' => $this->projectPermission->getAllowedProjects($user_id), + 'events' => $this->projectActivity->getProjects($project_ids, 5), + 'task_paginator' => $task_paginator, + 'subtask_paginator' => $subtask_paginator, + 'project_paginator' => $project_paginator, + 'user_id' => $user_id, ))); } + + /** + * Render Markdown text and reply with the HTML Code + * + * @access public + */ + public function preview() + { + $payload = $this->request->getJson(); + + if (empty($payload['text'])) { + $this->response->html('<p>'.t('Nothing to preview...').'</p>'); + } + + $this->response->html($this->helper->text->markdown($payload['text'])); + } + + /** + * Colors stylesheet + * + * @access public + */ + public function colors() + { + $this->response->css($this->color->getCss()); + } + + /** + * Task autocompletion (Ajax) + * + * @access public + */ + public function autocomplete() + { + $search = $this->request->getStringParam('term'); + + $filter = $this->taskFilter + ->create() + ->filterByProjects($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId())) + ->excludeTasks(array($this->request->getIntegerParam('exclude_task_id'))); + + // Search by task id or by title + if (ctype_digit($search)) { + $filter->filterById($search); + } + else { + $filter->filterByTitle($search); + } + + $this->response->json($filter->toAutoCompletion()); + } } |