Add external links for tasks with plugin api
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -24,6 +24,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
|
||||
*
|
||||
|
||||
@@ -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,
|
||||
|
||||
185
app/Controller/TaskExternalLink.php
Normal file
185
app/Controller/TaskExternalLink.php
Normal file
@@ -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'])));
|
||||
}
|
||||
}
|
||||
@@ -28,6 +28,25 @@ class Tasklink extends Base
|
||||
return $link;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
@@ -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.'));
|
||||
|
||||
@@ -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));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user