My WorkspaceOrg main page, personal per-user project workspaces -- dashboard page, badges, CRUD + assign
This commit is contained in:
120
Controller/WorkspaceOrgController.php
Normal file
120
Controller/WorkspaceOrgController.php
Normal file
@@ -0,0 +1,120 @@
|
||||
<?php
|
||||
|
||||
namespace Kanboard\Plugin\WorkspaceOrg\Controller;
|
||||
|
||||
use Kanboard\Controller\BaseController;
|
||||
use Kanboard\Plugin\WorkspaceOrg\Helper\WorkspaceOrgHelper;
|
||||
|
||||
/**
|
||||
* The "My workspaces" dashboard page and its workspace CRUD + project assignment. Every action works
|
||||
* on the current user's own workspaces (user metadata), so no admin/manager gate is needed -- any
|
||||
* logged-in user organizes their own projects. State changes go through getValues() (CSRF-checked)
|
||||
* or checkCSRFParam() for the confirm link, mirroring core's TagController.
|
||||
*/
|
||||
class WorkspaceOrgController extends BaseController
|
||||
{
|
||||
private function workspaces()
|
||||
{
|
||||
return new WorkspaceOrgHelper($this->container);
|
||||
}
|
||||
|
||||
private function backToIndex()
|
||||
{
|
||||
$this->response->redirect($this->helper->url->to('WorkspaceOrgController', 'index', array('plugin' => 'WorkspaceOrg')));
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$helper = $this->workspaces();
|
||||
|
||||
$this->response->html($this->helper->layout->dashboard('workspaceOrg:workspace/index', array(
|
||||
'title' => t('My workspaces'),
|
||||
'user' => $this->getUser(),
|
||||
'groups' => $helper->grouped(),
|
||||
'options' => $helper->options(),
|
||||
'default' => WorkspaceOrgHelper::DEFAULT_WORKSPACE,
|
||||
)));
|
||||
}
|
||||
|
||||
public function create(array $values = array(), array $errors = array())
|
||||
{
|
||||
$this->response->html($this->template->render('workspaceOrg:workspace/create', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
)));
|
||||
}
|
||||
|
||||
public function save()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
$name = isset($values['name']) ? $values['name'] : '';
|
||||
|
||||
if ($name !== '' && $this->workspaces()->addWorkspace($name)) {
|
||||
$this->flash->success(t('Workspace created successfully.'));
|
||||
$this->backToIndex();
|
||||
} else {
|
||||
$this->create($values, array('name' => array(t('Invalid name, or a workspace with this name already exists.'))));
|
||||
}
|
||||
}
|
||||
|
||||
public function edit(array $values = array(), array $errors = array())
|
||||
{
|
||||
if (empty($values)) {
|
||||
$name = $this->request->getStringParam('name');
|
||||
$values = array('old' => $name, 'name' => $name);
|
||||
}
|
||||
|
||||
$this->response->html($this->template->render('workspaceOrg:workspace/edit', array(
|
||||
'values' => $values,
|
||||
'errors' => $errors,
|
||||
)));
|
||||
}
|
||||
|
||||
public function update()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
$old = isset($values['old']) ? $values['old'] : '';
|
||||
$name = isset($values['name']) ? $values['name'] : '';
|
||||
|
||||
if ($name !== '' && $this->workspaces()->renameWorkspace($old, $name)) {
|
||||
$this->flash->success(t('Workspace renamed successfully.'));
|
||||
$this->backToIndex();
|
||||
} else {
|
||||
$this->edit($values, array('name' => array(t('Invalid name, or a workspace with this name already exists.'))));
|
||||
}
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
$this->response->html($this->template->render('workspaceOrg:workspace/remove', array(
|
||||
'name' => $this->request->getStringParam('name'),
|
||||
)));
|
||||
}
|
||||
|
||||
public function remove()
|
||||
{
|
||||
$this->checkCSRFParam();
|
||||
|
||||
if ($this->workspaces()->removeWorkspace($this->request->getStringParam('name'))) {
|
||||
$this->flash->success(t('Workspace removed. Its projects moved to Default.'));
|
||||
} else {
|
||||
$this->flash->failure(t('Unable to remove this workspace.'));
|
||||
}
|
||||
|
||||
$this->backToIndex();
|
||||
}
|
||||
|
||||
public function assign()
|
||||
{
|
||||
$values = $this->request->getValues();
|
||||
$project_id = isset($values['project_id']) ? (int) $values['project_id'] : 0;
|
||||
$workspace = isset($values['workspace']) ? $values['workspace'] : WorkspaceOrgHelper::DEFAULT_WORKSPACE;
|
||||
|
||||
if ($project_id > 0) {
|
||||
$this->workspaces()->assign($project_id, $workspace);
|
||||
$this->flash->success(t('Project moved.'));
|
||||
}
|
||||
|
||||
$this->backToIndex();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user