Split board controller into multiple classes

This commit is contained in:
Frederic Guillot
2016-05-28 14:05:57 -04:00
parent 1353929a7d
commit 8d12e2fe73
37 changed files with 129 additions and 116 deletions

View File

@@ -6,67 +6,15 @@ use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Formatter\BoardFormatter;
/**
* Board controller
* Class BoardAjaxController
*
* @package controller
* @author Frederic Guillot
* @package Kanboard\Controller
* @author Fredric Guillot
*/
class Board extends BaseController
class BoardAjaxController extends BaseController
{
/**
* Display the public version of a board
* Access checked by a simple token, no user login, read only, auto-refresh
*
* @access public
*/
public function readonly()
{
$token = $this->request->getStringParam('token');
$project = $this->project->getByToken($token);
// Token verification
if (empty($project)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
// Display the board with a specific layout
$this->response->html($this->helper->layout->app('board/view_public', array(
'project' => $project,
'swimlanes' => $this->board->getBoard($project['id']),
'title' => $project['name'],
'description' => $project['description'],
'no_layout' => true,
'not_editable' => true,
'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
)));
}
/**
* Show a board for a given project
*
* @access public
*/
public function show()
{
$project = $this->getProject();
$search = $this->helper->projectHeader->getSearchQuery($project);
$this->response->html($this->helper->layout->app('board/view_private', array(
'project' => $project,
'title' => $project['name'],
'description' => $this->helper->projectHeader->getDescription($project),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
'swimlanes' => $this->taskLexer
->build($search)
->format(BoardFormatter::getInstance($this->container)->setProjectId($project['id']))
)));
}
/**
* Save the board (Ajax request made by the drag and drop)
* Save new task positions (Ajax request made by the drag and drop)
*
* @access public
*/
@@ -106,7 +54,7 @@ class Board extends BaseController
$timestamp = $this->request->getIntegerParam('timestamp');
if (! $project_id || ! $this->request->isAjax()) {
$this->response->status(403);
throw new AccessForbiddenException();
} elseif (! $this->project->isModifiedSince($project_id, $timestamp)) {
$this->response->status(304);
} else {
@@ -167,18 +115,18 @@ class Board extends BaseController
if ($this->request->isAjax()) {
$this->response->html($this->renderBoard($project_id));
} else {
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project_id)));
$this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project_id)));
}
}
/**
* Render board
*
* @access private
* @access protected
* @param integer $project_id
* @return string
*/
private function renderBoard($project_id)
protected function renderBoard($project_id)
{
return $this->template->render('board/table_container', array(
'project' => $this->project->getById($project_id),

View File

@@ -42,6 +42,6 @@ class BoardPopoverController extends BaseController
$this->taskStatus->closeTasksBySwimlaneAndColumn($values['swimlane_id'], $values['column_id']);
$this->flash->success(t('All tasks of the column "%s" and the swimlane "%s" have been closed successfully.', $this->column->getColumnTitleById($values['column_id']), $this->swimlane->getNameById($values['swimlane_id']) ?: t($project['default_swimlane'])));
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])));
$this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])));
}
}

View File

@@ -0,0 +1,65 @@
<?php
namespace Kanboard\Controller;
use Kanboard\Core\Controller\AccessForbiddenException;
use Kanboard\Formatter\BoardFormatter;
/**
* Board controller
*
* @package Kanboard\Controller
* @author Frederic Guillot
*/
class BoardViewController extends BaseController
{
/**
* Display the public version of a board
* Access checked by a simple token, no user login, read only, auto-refresh
*
* @access public
*/
public function readonly()
{
$token = $this->request->getStringParam('token');
$project = $this->project->getByToken($token);
if (empty($project)) {
throw AccessForbiddenException::getInstance()->withoutLayout();
}
$this->response->html($this->helper->layout->app('board/view_public', array(
'project' => $project,
'swimlanes' => $this->board->getBoard($project['id']),
'title' => $project['name'],
'description' => $project['description'],
'no_layout' => true,
'not_editable' => true,
'board_public_refresh_interval' => $this->config->get('board_public_refresh_interval'),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
)));
}
/**
* Show a board for a given project
*
* @access public
*/
public function show()
{
$project = $this->getProject();
$search = $this->helper->projectHeader->getSearchQuery($project);
$this->response->html($this->helper->layout->app('board/view_private', array(
'project' => $project,
'title' => $project['name'],
'description' => $this->helper->projectHeader->getDescription($project),
'board_private_refresh_interval' => $this->config->get('board_private_refresh_interval'),
'board_highlight_period' => $this->config->get('board_highlight_period'),
'swimlanes' => $this->taskLexer
->build($search)
->format(BoardFormatter::getInstance($this->container)->setProjectId($project['id']))
)));
}
}

View File

@@ -50,7 +50,7 @@ class TaskBulkController extends BaseController
if ($valid) {
$this->createTasks($project, $values);
$this->response->redirect($this->helper->url->to(
'Board',
'BoardViewController',
'show',
array('project_id' => $project['id']),
'swimlane-'. $values['swimlane_id']

View File

@@ -82,6 +82,6 @@ class TaskCreationController extends BaseController
));
}
return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $project['id'])), true);
return $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $project['id'])), true);
}
}

View File

@@ -44,7 +44,7 @@ class TaskPopoverController extends BaseController
$this->flash->failure(t('Unable to update your task.'));
}
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id'])), true);
$this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $values['project_id'])), true);
}
/**
@@ -81,7 +81,7 @@ class TaskPopoverController extends BaseController
$this->flash->failure(t('Unable to update your task.'));
}
$this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $values['project_id'])), true);
$this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $values['project_id'])), true);
}
/**

View File

@@ -166,7 +166,7 @@ class TaskViewController extends BaseController
$this->flash->failure(t('Unable to remove this task.'));
}
return $this->response->redirect($this->helper->url->to('board', 'show', array('project_id' => $task['project_id'])), true);
return $this->response->redirect($this->helper->url->to('BoardViewController', 'show', array('project_id' => $task['project_id'])), true);
}
return $this->response->html($this->template->render('task/remove', array(