diff options
author | Frederic Guillot <fred@kanboard.net> | 2016-01-30 20:38:20 -0500 |
---|---|---|
committer | Frederic Guillot <fred@kanboard.net> | 2016-01-30 20:38:20 -0500 |
commit | 5c92f467867b43034b9e66b46b3b465ba9db655c (patch) | |
tree | cb0855ea64d8bba3abe4dfe978c5dbabb745911d /app/Controller | |
parent | ec66a779c9158830fe4bb0f96a44eadfe697ef00 (diff) |
Add external links for tasks with plugin api
Diffstat (limited to 'app/Controller')
-rw-r--r-- | app/Controller/Base.php | 11 | ||||
-rw-r--r-- | app/Controller/BoardTooltip.php | 14 | ||||
-rw-r--r-- | app/Controller/Comment.php | 10 | ||||
-rw-r--r-- | app/Controller/TaskExternalLink.php | 185 | ||||
-rw-r--r-- | app/Controller/Tasklink.php | 37 | ||||
-rw-r--r-- | app/Controller/Taskmodification.php | 7 |
6 files changed, 231 insertions, 33 deletions
diff --git a/app/Controller/Base.php b/app/Controller/Base.php index efeab31e..fb64bcf3 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -189,9 +189,15 @@ abstract class Base extends \Kanboard\Core\Base */ protected function taskLayout($template, array $params) { + $params['ajax'] = $this->request->isAjax() || $this->request->getIntegerParam('ajax') === 1; $content = $this->template->render($template, $params); - $params['task_content_for_layout'] = $content; + + if ($params['ajax']) { + return $content; + } + $params['title'] = $params['task']['project_name'].' > '.$params['task']['title']; + $params['task_content_for_layout'] = $content; $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); return $this->template->layout('task/layout', $params); @@ -319,7 +325,8 @@ abstract class Base extends \Kanboard\Core\Base * @param array &$project * @return string */ - protected function getProjectDescription(array &$project) { + protected function getProjectDescription(array &$project) + { if ($project['owner_id'] > 0) { $description = t('Project owner: ').'**'.$this->template->e($project['owner_name'] ?: $project['owner_username']).'**'.PHP_EOL.PHP_EOL; diff --git a/app/Controller/BoardTooltip.php b/app/Controller/BoardTooltip.php index bcf7de81..06f4d729 100644 --- a/app/Controller/BoardTooltip.php +++ b/app/Controller/BoardTooltip.php @@ -25,6 +25,20 @@ class BoardTooltip extends Base } /** + * Get links on mouseover + * + * @access public + */ + public function externallinks() + { + $task = $this->getTask(); + $this->response->html($this->template->render('board/tooltip_external_links', array( + 'links' => $this->taskExternalLink->getAll($task['id']), + 'task' => $task, + ))); + } + + /** * Get subtasks on mouseover * * @access public diff --git a/app/Controller/Comment.php b/app/Controller/Comment.php index a608dd1c..c77a4712 100644 --- a/app/Controller/Comment.php +++ b/app/Controller/Comment.php @@ -41,7 +41,6 @@ class Comment extends Base public function create(array $values = array(), array $errors = array()) { $task = $this->getTask(); - $ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax'); if (empty($values)) { $values = array( @@ -50,15 +49,6 @@ class Comment extends Base ); } - if ($ajax) { - $this->response->html($this->template->render('comment/create', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'ajax' => $ajax, - ))); - } - $this->response->html($this->taskLayout('comment/create', array( 'values' => $values, 'errors' => $errors, diff --git a/app/Controller/TaskExternalLink.php b/app/Controller/TaskExternalLink.php new file mode 100644 index 00000000..3209751b --- /dev/null +++ b/app/Controller/TaskExternalLink.php @@ -0,0 +1,185 @@ +<?php + +namespace Kanboard\Controller; + +use Kanboard\Core\ExternalLink\ExternalLinkProviderNotFound; + +/** + * Task External Link Controller + * + * @package controller + * @author Frederic Guillot + */ +class TaskExternalLink extends Base +{ + /** + * Creation form + * + * @access public + */ + public function show() + { + $task = $this->getTask(); + + $this->response->html($this->taskLayout('task_external_link/show', array( + 'links' => $this->taskExternalLink->getAll($task['id']), + 'task' => $task, + 'title' => t('List of external links'), + ))); + } + + /** + * First creation form + * + * @access public + */ + public function find(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + + $this->response->html($this->taskLayout('task_external_link/find', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'types' => $this->externalLinkManager->getTypes(), + ))); + } + + /** + * Second creation form + * + * @access public + */ + public function create() + { + try { + + $task = $this->getTask(); + $values = $this->request->getValues(); + + $provider = $this->externalLinkManager->setUserInput($values)->find(); + $link = $provider->getLink(); + + $this->response->html($this->taskLayout('task_external_link/create', array( + 'values' => array( + 'title' => $link->getTitle(), + 'url' => $link->getUrl(), + 'link_type' => $provider->getType(), + ), + 'dependencies' => $provider->getDependencies(), + 'errors' => array(), + 'task' => $task, + ))); + + } catch (ExternalLinkProviderNotFound $e) { + $errors = array('text' => array(t('Unable to fetch link information.'))); + $this->find($values, $errors); + } + } + + /** + * Save link + * + * @access public + */ + public function save() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->externalLinkValidator->validateCreation($values); + + if ($valid && $this->taskExternalLink->create($values)) { + $this->flash->success(t('Link added successfully.')); + return $this->response->redirect($this->helper->url->to('TaskExternalLink', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])), true); + } + + $this->edit($values, $errors); + } + + /** + * Edit form + * + * @access public + */ + public function edit(array $values = array(), array $errors = array()) + { + $task = $this->getTask(); + $link_id = $this->request->getIntegerParam('link_id'); + + if ($link_id > 0) { + $values = $this->taskExternalLink->getById($link_id); + } + + if (empty($values)) { + return $this->notfound(); + } + + $provider = $this->externalLinkManager->getProvider($values['link_type']); + + $this->response->html($this->taskLayout('task_external_link/edit', array( + 'values' => $values, + 'errors' => $errors, + 'task' => $task, + 'dependencies' => $provider->getDependencies(), + ))); + } + + /** + * Update link + * + * @access public + */ + public function update() + { + $task = $this->getTask(); + $values = $this->request->getValues(); + list($valid, $errors) = $this->externalLinkValidator->validateModification($values); + + if ($valid && $this->taskExternalLink->update($values)) { + $this->flash->success(t('Link updated successfully.')); + return $this->response->redirect($this->helper->url->to('TaskExternalLink', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } + + $this->edit($values, $errors); + } + + /** + * Confirmation dialog before removing a link + * + * @access public + */ + public function confirm() + { + $task = $this->getTask(); + $link_id = $this->request->getIntegerParam('link_id'); + $link = $this->taskExternalLink->getById($link_id); + + if (empty($link)) { + return $this->notfound(); + } + + $this->response->html($this->taskLayout('task_external_link/remove', array( + 'link' => $link, + 'task' => $task, + ))); + } + + /** + * Remove a link + * + * @access public + */ + public function remove() + { + $this->checkCSRFParam(); + $task = $this->getTask(); + + if ($this->taskExternalLink->remove($this->request->getIntegerParam('link_id'))) { + $this->flash->success(t('Link removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this link.')); + } + + $this->response->redirect($this->helper->url->to('TaskExternalLink', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id']))); + } +} diff --git a/app/Controller/Tasklink.php b/app/Controller/Tasklink.php index a81d3ee5..4338e7bf 100644 --- a/app/Controller/Tasklink.php +++ b/app/Controller/Tasklink.php @@ -29,6 +29,25 @@ class Tasklink extends Base } /** + * Show links + * + * @access public + */ + public function show() + { + $task = $this->getTask(); + $project = $this->project->getById($task['project_id']); + + $this->response->html($this->taskLayout('tasklink/show', array( + 'links' => $this->taskLink->getAllGroupedByLabel($task['id']), + 'task' => $task, + 'project' => $project, + 'editable' => true, + 'is_public' => false, + ))); + } + + /** * Creation form * * @access public @@ -36,18 +55,6 @@ class Tasklink extends Base public function create(array $values = array(), array $errors = array()) { $task = $this->getTask(); - $ajax = $this->request->isAjax() || $this->request->getIntegerParam('ajax'); - - if ($ajax && empty($errors)) { - $this->response->html($this->template->render('tasklink/create', array( - 'values' => $values, - 'errors' => $errors, - 'task' => $task, - 'labels' => $this->link->getList(0, false), - 'title' => t('Add a new link'), - 'ajax' => $ajax, - ))); - } $this->response->html($this->taskLayout('tasklink/create', array( 'values' => $values, @@ -76,10 +83,10 @@ class Tasklink extends Base $this->flash->success(t('Link added successfully.')); if ($ajax) { - $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); + return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id']))); } - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); + return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } $errors = array('title' => array(t('The exact same link already exists'))); @@ -130,7 +137,7 @@ class Tasklink extends Base if ($valid) { if ($this->taskLink->update($values['id'], $values['task_id'], $values['opposite_task_id'], $values['link_id'])) { $this->flash->success(t('Link updated successfully.')); - $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); + return $this->response->redirect($this->helper->url->to('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links'); } $this->flash->failure(t('Unable to update your link.')); diff --git a/app/Controller/Taskmodification.php b/app/Controller/Taskmodification.php index 2c97970b..1fcc416b 100644 --- a/app/Controller/Taskmodification.php +++ b/app/Controller/Taskmodification.php @@ -80,14 +80,9 @@ class Taskmodification extends Base 'values' => $values, 'errors' => $errors, 'task' => $task, - 'ajax' => $ajax, ); - if ($ajax) { - $this->response->html($this->template->render('task_modification/edit_description', $params)); - } else { - $this->response->html($this->taskLayout('task_modification/edit_description', $params)); - } + $this->response->html($this->taskLayout('task_modification/edit_description', $params)); } /** |