Refactoring/simplification of the pull-request about links

This commit is contained in:
Frederic Guillot
2015-02-14 16:11:13 -05:00
parent 364382b1b5
commit f7e4c3928a
77 changed files with 1407 additions and 2588 deletions

View File

@@ -2,7 +2,8 @@
namespace Controller;
use Model\Subtask as SubTaskModel;
use Model\Subtask as SubtaskModel;
use Model\Task as TaskModel;
/**
* Application controller
@@ -39,7 +40,7 @@ class App extends Base
*/
public function index($user_id = 0, $action = 'index')
{
$status = array(SubTaskModel::STATUS_TODO, SubTaskModel::STATUS_INPROGRESS);
$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);
@@ -88,11 +89,8 @@ class App extends Base
if (empty($payload['text'])) {
$this->response->html('<p>'.t('Nothing to preview...').'</p>');
}
else {
$this->response->html(
$this->template->markdown($payload['text'])
);
}
$this->response->html($this->template->markdown($payload['text']));
}
/**
@@ -104,4 +102,21 @@ class App extends Base
{
$this->response->css($this->color->getCss());
}
/**
* Task autocompletion (Ajax)
*
* @access public
*/
public function autocomplete()
{
$this->response->json(
$this->taskFilter
->create()
->filterByProjects($this->projectPermission->getActiveMemberProjectIds($this->userSession->getId()))
->excludeTasks(array($this->request->getIntegerParam('exclude_task_id')))
->filterByTitle($this->request->getStringParam('term'))
->toAutoCompletion()
);
}
}

View File

@@ -141,7 +141,7 @@ abstract class Base
private function sendHeaders($action)
{
// HTTP secure headers
$this->response->csp(array('style-src' => "'self' 'unsafe-inline'"));
$this->response->csp(array('style-src' => "'self' 'unsafe-inline'", 'img-src' => "'self' data:"));
$this->response->nosniff();
$this->response->xss();
@@ -201,7 +201,7 @@ abstract class Base
{
$project_id = $this->request->getIntegerParam('project_id');
$task_id = $this->request->getIntegerParam('task_id');
// Allow urls without "project_id"
if ($task_id > 0 && $project_id === 0) {
$project_id = $this->taskFinder->getProjectId($task_id);

View File

@@ -410,7 +410,7 @@ class Board extends Base
{
$task = $this->getTask();
$this->response->html($this->template->render('board/tasklinks', array(
'links' => $this->taskLink->getAll($task['id']),
'links' => $this->taskLink->getLinks($task['id']),
'task' => $task,
)));
}

View File

@@ -2,7 +2,7 @@
namespace Controller;
use Model\Task;
use Model\Task as TaskModel;
/**
* Project Calendar controller
@@ -74,7 +74,7 @@ class Calendar extends Base
$this->taskFilter
->create()
->filterByOwner($user_id)
->filterByStatus(Task::STATUS_OPEN)
->filterByStatus(TaskModel::STATUS_OPEN)
->filterByDueDateRange(
$this->request->getStringParam('start'),
$this->request->getStringParam('end')

View File

@@ -87,17 +87,12 @@ class Config extends Base
*
* @access public
*/
public function board(array $values = array(), array $errors = array())
public function board()
{
$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').' &gt; '.t('Board settings'),
)));
}

View File

@@ -1,11 +1,13 @@
<?php
namespace Controller;
/**
* Link controller
*
* @package controller
* @author Olivier Maridat
* @author Olivier Maridat
* @author Frederic Guillot
*/
class Link extends Base
{
@@ -21,13 +23,10 @@ class Link extends Base
{
$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
*
@@ -36,49 +35,27 @@ class Link extends Base
*/
private function getLink()
{
$link = $this->link->getById($this->request->getIntegerParam('link_id'), $this->request->getIntegerParam('project_id', -1));
$link = $this->link->getById($this->request->getIntegerParam('link_id'));
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
* List of links
*
* @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']),
'links' => $this->link->getMergedList(),
'values' => $values,
'errors' => $errors,
'project' => $project,
'title' => t('Settings').' &gt; '.t('Board\'s links settings'),
'title' => t('Settings').' &gt; '.t('Task\'s links'),
)));
}
@@ -91,19 +68,18 @@ class Link extends Base
{
$values = $this->request->getValues();
list($valid, $errors) = $this->link->validateCreation($values);
if ($valid) {
if ($this->link->create($values)) {
if ($this->link->create($values['label'], $values['opposite_label'])) {
$this->session->flash(t('Link added successfully.'));
$this->response->redirect('?controller=link&action=index&project_id='.$values['project_id']);
$this->response->redirect($this->helper->url('link', 'index'));
}
else {
$this->session->flashError(t('Unable to create your link.'));
}
}
if (!empty($values)) {
$this->link->prepare($values);
}
$this->index($values, $errors);
}
@@ -114,14 +90,15 @@ class Link extends Base
*/
public function edit(array $values = array(), array $errors = array())
{
$project = $this->getProject();
$link = $this->getLink();
$link['label'] = t($link['label']);
$this->response->html($this->layout('link/edit', array(
'values' => empty($values) ? $this->getLink() : $values,
'values' => $values ?: $link,
'errors' => $errors,
'project' => $project,
'edit' => true,
'title' => t('Links')
'labels' => $this->link->getList($link['id']),
'link' => $link,
'title' => t('Link modification')
)));
}
@@ -134,19 +111,17 @@ class Link extends Base
{
$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']);
$this->response->redirect($this->helper->url('link', 'index'));
}
else {
else {
$this->session->flashError(t('Unable to update your link.'));
}
}
if (!empty($values)) {
$this->link->prepare($values);
}
$this->edit($values, $errors);
}
@@ -157,11 +132,9 @@ class Link extends Base
*/
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')
)));
@@ -176,14 +149,14 @@ class Link extends Base
{
$this->checkCSRFParam();
$link = $this->getLink();
if ($this->link->remove($link['link_id'])) {
if ($this->link->remove($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();
$this->response->redirect($this->helper->url('link', 'index'));
}
}

View File

@@ -37,7 +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']),
'links' => $this->taskLink->getLinks($task['id']),
'task' => $task,
'columns_list' => $this->board->getColumnsList($task['project_id']),
'colors_list' => $this->color->getList(),
@@ -72,13 +72,11 @@ class Task extends Base
'files' => $this->file->getAll($task['id']),
'comments' => $this->comment->getAll($task['id']),
'subtasks' => $subtasks,
'links' => $this->taskLink->getAll($task['id']),
'links' => $this->taskLink->getLinks($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'],

View File

@@ -2,12 +2,12 @@
namespace Controller;
use Model\Task AS TaskModel;
/**
* TaskLink controller
*
* @package controller
* @author Olivier Maridat
* @author Frederic Guillot
*/
class Tasklink extends Base
{
@@ -20,9 +20,11 @@ class Tasklink extends Base
private function getTaskLink()
{
$link = $this->taskLink->getById($this->request->getIntegerParam('link_id'));
if (! $link) {
$this->notfound();
}
return $link;
}
@@ -38,16 +40,15 @@ class Tasklink extends Base
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(
$this->response->html($this->taskLayout('tasklink/create', 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,
'labels' => $this->link->getList(0, false),
'title' => t('Add a new link')
)));
}
@@ -60,69 +61,23 @@ class Tasklink extends Base
{
$task = $this->getTask();
$values = $this->request->getValues();
list($valid, $errors) = $this->taskLink->validateCreation($values);
if ($valid) {
if ($this->taskLink->create($values)) {
if ($this->taskLink->create($values['task_id'], $values['opposite_task_id'], $values['link_id'])) {
$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');
$this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])).'#links');
}
else {
$this->session->flashError(t('Unable to add the link.'));
$this->session->flashError(t('Unable to create your 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
*
@@ -132,6 +87,7 @@ class Tasklink extends Base
{
$task = $this->getTask();
$link = $this->getTaskLink();
$this->response->html($this->taskLayout('tasklink/remove', array(
'link' => $link,
'task' => $task,
@@ -147,14 +103,14 @@ class Tasklink extends Base
{
$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();
$this->response->redirect($this->helper->url('task', 'show', array('task_id' => $task['id'], 'project_id' => $task['project_id'])));
}
}