Add task links (Merge pull-request #610)

This commit is contained in:
Frederic Guillot
2015-02-13 17:50:20 -05:00
parent 124f7cad28
commit 364382b1b5
38 changed files with 1769 additions and 41 deletions

View File

@@ -43,6 +43,7 @@ use Symfony\Component\EventDispatcher\Event;
* @property \Model\Subtask $subtask
* @property \Model\Swimlane $swimlane
* @property \Model\Task $task
* @property \Model\Link $link
* @property \Model\TaskCreation $taskCreation
* @property \Model\TaskModification $taskModification
* @property \Model\TaskDuplication $taskDuplication
@@ -54,6 +55,7 @@ use Symfony\Component\EventDispatcher\Event;
* @property \Model\TaskPermission $taskPermission
* @property \Model\TaskStatus $taskStatus
* @property \Model\TaskValidator $taskValidator
* @property \Model\TaskLink $taskLink
* @property \Model\CommentHistory $commentHistory
* @property \Model\SubtaskHistory $subtaskHistory
* @property \Model\SubtaskTimeTracking $subtaskTimeTracking

View File

@@ -401,6 +401,20 @@ class Board extends Base
);
}
/**
* Get links on mouseover
*
* @access public
*/
public function tasklinks()
{
$task = $this->getTask();
$this->response->html($this->template->render('board/tasklinks', array(
'links' => $this->taskLink->getAll($task['id']),
'task' => $task,
)));
}
/**
* Get subtasks on mouseover
*

View File

@@ -87,12 +87,17 @@ class Config extends Base
*
* @access public
*/
public function board()
public function board(array $values = array(), array $errors = array())
{
$this->common('board');
$this->response->html($this->layout('config/board', array(
'default_columns' => implode(', ', $this->board->getDefaultColumns()),
'links' => $this->link->getMergedList(),
'values' => $values + array(
'project_id' => -1
),
'errors' => $errors,
'title' => t('Settings').' > '.t('Board settings'),
)));
}

189
app/Controller/Link.php Normal file
View File

@@ -0,0 +1,189 @@
<?php
namespace Controller;
/**
* Link controller
*
* @package controller
* @author Olivier Maridat
*/
class Link extends Base
{
/**
* Common layout for config views
*
* @access private
* @param string $template Template name
* @param array $params Template parameters
* @return string
*/
private function layout($template, array $params)
{
$params['board_selector'] = $this->projectPermission->getAllowedProjects($this->userSession->getId());
$params['config_content_for_layout'] = $this->template->render($template, $params);
if (isset($params['values']['project_id']) && -1 != $params['values']['project_id']) {
return $this->projectLayout($template, $params);
}
return $this->template->layout('config/layout', $params);
}
/**
* Get the current link
*
* @access private
* @return array
*/
private function getLink()
{
$link = $this->link->getById($this->request->getIntegerParam('link_id'), $this->request->getIntegerParam('project_id', -1));
if (! $link) {
$this->notfound();
}
$link['link_id'] = $link[0]['link_id'];
$link['project_id'] = $link[0]['project_id'];
return $link;
}
/**
* Method to get a project
*
* @access protected
* @param integer $project_id Default project id
* @return array
*/
protected function getProject($project_id = -1)
{
$project = array('id' => $project_id);
$project_id = $this->request->getIntegerParam('project_id', $project_id);
if (-1 != $project_id) {
$project = parent::getProject($project_id);
}
return $project;
}
/**
* List of links for a given project
*
* @access public
*/
public function index(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$values['project_id'] = $project['id'];
$values[] = array();
$this->response->html($this->layout('link/index', array(
'links' => $this->link->getMergedList($project['id']),
'values' => $values,
'errors' => $errors,
'project' => $project,
'title' => t('Settings').' &gt; '.t('Board\'s links settings'),
)));
}
/**
* Validate and save a new link
*
* @access public
*/
public function save()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->link->validateCreation($values);
if ($valid) {
if ($this->link->create($values)) {
$this->session->flash(t('Link added successfully.'));
$this->response->redirect('?controller=link&action=index&project_id='.$values['project_id']);
}
else {
$this->session->flashError(t('Unable to create your link.'));
}
}
if (!empty($values)) {
$this->link->prepare($values);
}
$this->index($values, $errors);
}
/**
* Edit form
*
* @access public
*/
public function edit(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$this->response->html($this->layout('link/edit', array(
'values' => empty($values) ? $this->getLink() : $values,
'errors' => $errors,
'project' => $project,
'edit' => true,
'title' => t('Links')
)));
}
/**
* Edit a link (validate the form and update the database)
*
* @access public
*/
public function update()
{
$values = $this->request->getValues();
list($valid, $errors) = $this->link->validateModification($values);
if ($valid) {
if ($this->link->update($values)) {
$this->session->flash(t('Link updated successfully.'));
$this->response->redirect('?controller=link&action=index&project_id='.$values['project_id']);
}
else {
$this->session->flashError(t('Unable to update your link.'));
}
}
if (!empty($values)) {
$this->link->prepare($values);
}
$this->edit($values, $errors);
}
/**
* Confirmation dialog before removing a link
*
* @access public
*/
public function confirm()
{
$project = $this->getProject();
$link = $this->getLink();
$this->response->html($this->layout('link/remove', array(
'project' => $project,
'link' => $link,
'title' => t('Remove a link')
)));
}
/**
* Remove a link
*
* @access public
*/
public function remove()
{
$this->checkCSRFParam();
$link = $this->getLink();
if ($this->link->remove($link['link_id'])) {
$this->session->flash(t('Link removed successfully.'));
$this->response->redirect('?controller=link&action=index&project_id='.$link['project_id']);
}
else {
$this->session->flashError(t('Unable to remove this link.'));
}
$this->confirm();
}
}

View File

@@ -3,6 +3,7 @@
namespace Controller;
use Model\Project as ProjectModel;
use Model\Task as TaskModel;
/**
* Task controller
@@ -36,6 +37,7 @@ class Task extends Base
'project' => $project,
'comments' => $this->comment->getAll($task['id']),
'subtasks' => $this->subtask->getAll($task['id']),
'links' => $this->taskLink->getAll($task['id']),
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->color->getList(),
@@ -70,10 +72,13 @@ class Task extends Base
'files' => $this->file->getAll($task['id']),
'comments' => $this->comment->getAll($task['id']),
'subtasks' => $subtasks,
'links' => $this->taskLink->getAll($task['id']),
'task' => $task,
'values' => $values,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->color->getList(),
'link_list' => $this->link->getLinkLabelList($task['project_id'], false),
'task_list' => $this->taskFinder->getList($task['project_id'], TaskModel::STATUS_OPEN, $task['id']),
'date_format' => $this->config->get('application_date_format'),
'date_formats' => $this->dateParser->getAvailableFormats(),
'title' => $task['project_name'].' &gt; '.$task['title'],

160
app/Controller/Tasklink.php Normal file
View File

@@ -0,0 +1,160 @@
<?php
namespace Controller;
use Model\Task AS TaskModel;
/**
* TaskLink controller
*
* @package controller
* @author Olivier Maridat
*/
class Tasklink extends Base
{
/**
* Get the current link
*
* @access private
* @return array
*/
private function getTaskLink()
{
$link = $this->taskLink->getById($this->request->getIntegerParam('link_id'));
if (! $link) {
$this->notfound();
}
return $link;
}
/**
* Creation form
*
* @access public
*/
public function create(array $values = array(), array $errors = array())
{
$task = $this->getTask();
if (empty($values)) {
$values = array(
'task_id' => $task['id'],
'another_link' => $this->request->getIntegerParam('another_link', 0)
);
}
$this->response->html($this->taskLayout('tasklink/edit', array(
'values' => $values,
'errors' => $errors,
'link_list' => $this->link->getLinkLabelList($task['project_id']),
'task_list' => $this->taskFinder->getList($task['project_id'], TaskModel::STATUS_OPEN, $task['id']),
'task' => $task,
)));
}
/**
* Validation and creation
*
* @access public
*/
public function save()
{
$task = $this->getTask();
$values = $this->request->getValues();
list($valid, $errors) = $this->taskLink->validateCreation($values);
if ($valid) {
if ($this->taskLink->create($values)) {
$this->session->flash(t('Link added successfully.'));
if (isset($values['another_link']) && $values['another_link'] == 1) {
$this->response->redirect('?controller=tasklink&action=create&task_id='.$task['id'].'&project_id='.$task['project_id'].'&another_link=1');
}
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
}
else {
$this->session->flashError(t('Unable to add the link.'));
}
}
$this->create($values, $errors);
}
/**
* Edit form
*
* @access public
*/
public function edit(array $values = array(), array $errors = array())
{
$task = $this->getTask();
$taskLink = $this->getTaskLink();
$this->response->html($this->taskLayout('tasklink/edit', array(
'values' => empty($values) ? $taskLink : $values,
'errors' => $errors,
'link_list' => $this->link->getLinkLabelList($task['project_id'], false),
'task_list' => $this->taskFinder->getList($task['project_id'], TaskModel::STATUS_OPEN, $task['id']),
'link' => $taskLink,
'task' => $task,
'edit' => true,
)));
}
/**
* Update and validate a link
*
* @access public
*/
public function update()
{
$task = $this->getTask();
$values = $this->request->getValues();
list($valid, $errors) = $this->taskLink->validateModification($values);
if ($valid) {
if ($this->taskLink->update($values)) {
$this->session->flash(t('Link updated successfully.'));
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
}
else {
$this->session->flashError(t('Unable to update the link.'));
}
}
$this->edit($values, $errors);
}
/**
* Confirmation dialog before removing a link
*
* @access public
*/
public function confirm()
{
$task = $this->getTask();
$link = $this->getTaskLink();
$this->response->html($this->taskLayout('tasklink/remove', array(
'link' => $link,
'task' => $task,
)));
}
/**
* Remove a link
*
* @access public
*/
public function remove()
{
$this->checkCSRFParam();
$task = $this->getTask();
if ($this->taskLink->remove($this->request->getIntegerParam('link_id'))) {
$this->session->flash(t('Link removed successfully.'));
$this->response->redirect('?controller=task&action=show&task_id='.$task['id'].'&project_id='.$task['project_id'].'#links');
}
else {
$this->session->flashError(t('Unable to remove this link.'));
}
$this->confirm();
}
}