Improve automatic action creation

This commit is contained in:
Frederic Guillot
2016-03-05 17:40:49 -05:00
parent a19dc88567
commit 22c5e32def
12 changed files with 239 additions and 195 deletions

View File

@@ -3,6 +3,7 @@ Version 1.0.27 (unreleased)
Improvements: Improvements:
* Improve automatic action creation
* Move notifications to the bottom of the screen * Move notifications to the bottom of the screen
* Added the possibility to import automatic actions from another project * Added the possibility to import automatic actions from another project
* Added Ajax loading icon for submit buttons * Added Ajax loading icon for submit buttons

View File

@@ -3,7 +3,7 @@
namespace Kanboard\Controller; namespace Kanboard\Controller;
/** /**
* Automatic actions management * Automatic Actions
* *
* @package controller * @package controller
* @author Frederic Guillot * @author Frederic Guillot
@@ -37,98 +37,6 @@ class Action extends Base
))); )));
} }
/**
* Choose the event according to the action (step 2)
*
* @access public
*/
public function event()
{
$project = $this->getProject();
$values = $this->request->getValues();
if (empty($values['action_name']) || empty($values['project_id'])) {
$this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id'])));
}
$this->response->html($this->helper->layout->project('action/event', array(
'values' => $values,
'project' => $project,
'events' => $this->actionManager->getCompatibleEvents($values['action_name']),
'title' => t('Automatic actions')
)));
}
/**
* Define action parameters (step 3)
*
* @access public
*/
public function params()
{
$project = $this->getProject();
$values = $this->request->getValues();
if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) {
$this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id'])));
}
$action = $this->actionManager->getAction($values['action_name']);
$action_params = $action->getActionRequiredParameters();
if (empty($action_params)) {
$this->doCreation($project, $values + array('params' => array()));
}
$projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
unset($projects_list[$project['id']]);
$this->response->html($this->helper->layout->project('action/params', array(
'values' => $values,
'action_params' => $action_params,
'columns_list' => $this->column->getList($project['id']),
'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']),
'projects_list' => $projects_list,
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),
'links_list' => $this->link->getList(0, false),
'project' => $project,
'title' => t('Automatic actions')
)));
}
/**
* Create a new action (last step)
*
* @access public
*/
public function create()
{
$this->doCreation($this->getProject(), $this->request->getValues());
}
/**
* Save the action
*
* @access private
* @param array $project Project properties
* @param array $values Form values
*/
private function doCreation(array $project, array $values)
{
list($valid, ) = $this->actionValidator->validateCreation($values);
if ($valid) {
if ($this->action->create($values) !== false) {
$this->flash->success(t('Your automatic action have been created successfully.'));
} else {
$this->flash->failure(t('Unable to create your automatic action.'));
}
}
$this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id'])));
}
/** /**
* Confirmation dialog before removing an action * Confirmation dialog before removing an action
* *

View File

@@ -0,0 +1,121 @@
<?php
namespace Kanboard\Controller;
/**
* Action Creation
*
* @package controller
* @author Frederic Guillot
*/
class ActionCreation extends Base
{
/**
* Show the form (step 1)
*
* @access public
*/
public function create()
{
$project = $this->getProject();
$this->response->html($this->template->render('action_creation/create', array(
'project' => $project,
'values' => array('project_id' => $project['id']),
'available_actions' => $this->actionManager->getAvailableActions(),
)));
}
/**
* Choose the event according to the action (step 2)
*
* @access public
*/
public function event()
{
$project = $this->getProject();
$values = $this->request->getValues();
if (empty($values['action_name']) || empty($values['project_id'])) {
return $this->create();
}
$this->response->html($this->template->render('action_creation/event', array(
'values' => $values,
'project' => $project,
'available_actions' => $this->actionManager->getAvailableActions(),
'events' => $this->actionManager->getCompatibleEvents($values['action_name']),
)));
}
/**
* Define action parameters (step 3)
*
* @access public
*/
public function params()
{
$project = $this->getProject();
$values = $this->request->getValues();
if (empty($values['action_name']) || empty($values['project_id']) || empty($values['event_name'])) {
return $this->create();
}
$action = $this->actionManager->getAction($values['action_name']);
$action_params = $action->getActionRequiredParameters();
if (empty($action_params)) {
$this->doCreation($project, $values + array('params' => array()));
}
$projects_list = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId());
unset($projects_list[$project['id']]);
$this->response->html($this->template->render('action_creation/params', array(
'values' => $values,
'action_params' => $action_params,
'columns_list' => $this->column->getList($project['id']),
'users_list' => $this->projectUserRole->getAssignableUsersList($project['id']),
'projects_list' => $projects_list,
'colors_list' => $this->color->getList(),
'categories_list' => $this->category->getList($project['id']),
'links_list' => $this->link->getList(0, false),
'project' => $project,
'available_actions' => $this->actionManager->getAvailableActions(),
'events' => $this->actionManager->getCompatibleEvents($values['action_name']),
)));
}
/**
* Save the action (last step)
*
* @access public
*/
public function save()
{
$this->doCreation($this->getProject(), $this->request->getValues());
}
/**
* Common method to save the action
*
* @access private
* @param array $project Project properties
* @param array $values Form values
*/
private function doCreation(array $project, array $values)
{
list($valid, ) = $this->actionValidator->validateCreation($values);
if ($valid) {
if ($this->action->create($values) !== false) {
$this->flash->success(t('Your automatic action have been created successfully.'));
} else {
$this->flash->failure(t('Unable to create your automatic action.'));
}
}
$this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id'])));
}
}

View File

@@ -16,7 +16,7 @@ class ActionProject extends Base
$projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId()); $projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId());
unset($projects[$project['id']]); unset($projects[$project['id']]);
$this->response->html($this->helper->layout->project('action_project/project', array( $this->response->html($this->template->render('action_project/project', array(
'project' => $project, 'project' => $project,
'projects_list' => $projects, 'projects_list' => $projects,
))); )));
@@ -33,6 +33,6 @@ class ActionProject extends Base
$this->flash->failure(t('Unable to duplicate actions.')); $this->flash->failure(t('Unable to duplicate actions.'));
} }
$this->response->redirect($this->helper->url->to('Action', 'index', array('project_id' => $project['id']))); $this->response->redirect($this->helper->url->to('action', 'index', array('project_id' => $project['id'])));
} }
} }

View File

@@ -68,6 +68,7 @@ class AuthenticationProvider implements ServiceProviderInterface
$acl->add('Action', '*', Role::PROJECT_MANAGER); $acl->add('Action', '*', Role::PROJECT_MANAGER);
$acl->add('ActionProject', '*', Role::PROJECT_MANAGER); $acl->add('ActionProject', '*', Role::PROJECT_MANAGER);
$acl->add('ActionCreation', '*', Role::PROJECT_MANAGER);
$acl->add('Analytic', '*', Role::PROJECT_MANAGER); $acl->add('Analytic', '*', Role::PROJECT_MANAGER);
$acl->add('Board', 'save', Role::PROJECT_MEMBER); $acl->add('Board', 'save', Role::PROJECT_MEMBER);
$acl->add('BoardPopover', '*', Role::PROJECT_MEMBER); $acl->add('BoardPopover', '*', Role::PROJECT_MEMBER);

View File

@@ -3,79 +3,69 @@
<ul> <ul>
<li> <li>
<i class="fa fa-plus fa-fw"></i> <i class="fa fa-plus fa-fw"></i>
<?= $this->url->link(t('Add a new action'), 'ActionCreation', 'create', array('project_id' => $project['id']), false, 'popover') ?>
</li>
<li>
<i class="fa fa-copy fa-fw"></i>
<?= $this->url->link(t('Import from another project'), 'ActionProject', 'project', array('project_id' => $project['id']), false, 'popover') ?> <?= $this->url->link(t('Import from another project'), 'ActionProject', 'project', array('project_id' => $project['id']), false, 'popover') ?>
</li> </li>
</ul> </ul>
</div> </div>
<?php if (! empty($actions)): ?> <?php if (empty($actions)): ?>
<p class="alert"><?= t('There is no action at the moment.') ?></p>
<?php else: ?>
<table>
<tr>
<th><?= t('Automatic actions') ?></th>
<th><?= t('Action parameters') ?></th>
<th><?= t('Action') ?></th>
</tr>
<h3><?= t('Defined actions') ?></h3> <?php foreach ($actions as $action): ?>
<table> <tr>
<tr> <td>
<th><?= t('Automatic actions') ?></th> <ul>
<th><?= t('Action parameters') ?></th> <li>
<th><?= t('Action') ?></th> <?= t('Event name') ?> =
</tr> <strong><?= $this->text->in($action['event_name'], $available_events) ?></strong>
</li>
<?php foreach ($actions as $action): ?> <li>
<tr> <?= t('Action name') ?> =
<td> <strong><?= $this->text->in($action['action_name'], $available_actions) ?></strong>
<ul> </li>
<li> <ul>
<?= t('Event name') ?> = </td>
<strong><?= $this->text->in($action['event_name'], $available_events) ?></strong> <td>
</li> <ul>
<li> <?php foreach ($action['params'] as $param_name => $param_value): ?>
<?= t('Action name') ?> = <li>
<strong><?= $this->text->in($action['action_name'], $available_actions) ?></strong> <?= $this->text->in($param_name, $available_params[$action['action_name']]) ?> =
</li> <strong>
<ul> <?php if ($this->text->contains($param_name, 'column_id')): ?>
</td> <?= $this->text->in($param_value, $columns_list) ?>
<td> <?php elseif ($this->text->contains($param_name, 'user_id')): ?>
<ul> <?= $this->text->in($param_value, $users_list) ?>
<?php foreach ($action['params'] as $param_name => $param_value): ?> <?php elseif ($this->text->contains($param_name, 'project_id')): ?>
<li> <?= $this->text->in($param_value, $projects_list) ?>
<?= $this->text->in($param_name, $available_params[$action['action_name']]) ?> = <?php elseif ($this->text->contains($param_name, 'color_id')): ?>
<strong> <?= $this->text->in($param_value, $colors_list) ?>
<?php if ($this->text->contains($param_name, 'column_id')): ?> <?php elseif ($this->text->contains($param_name, 'category_id')): ?>
<?= $this->text->in($param_value, $columns_list) ?> <?= $this->text->in($param_value, $categories_list) ?>
<?php elseif ($this->text->contains($param_name, 'user_id')): ?> <?php elseif ($this->text->contains($param_name, 'link_id')): ?>
<?= $this->text->in($param_value, $users_list) ?> <?= $this->text->in($param_value, $links_list) ?>
<?php elseif ($this->text->contains($param_name, 'project_id')): ?> <?php else: ?>
<?= $this->text->in($param_value, $projects_list) ?> <?= $this->text->e($param_value) ?>
<?php elseif ($this->text->contains($param_name, 'color_id')): ?> <?php endif ?>
<?= $this->text->in($param_value, $colors_list) ?> </strong>
<?php elseif ($this->text->contains($param_name, 'category_id')): ?> </li>
<?= $this->text->in($param_value, $categories_list) ?> <?php endforeach ?>
<?php elseif ($this->text->contains($param_name, 'link_id')): ?> </ul>
<?= $this->text->in($param_value, $links_list) ?> </td>
<?php else: ?> <td>
<?= $this->text->e($param_value) ?> <?= $this->url->link(t('Remove'), 'action', 'confirm', array('project_id' => $project['id'], 'action_id' => $action['id']), false, 'popover') ?>
<?php endif ?> </td>
</strong> </tr>
</li> <?php endforeach ?>
<?php endforeach ?> </table>
</ul> <?php endif ?>
</td>
<td>
<?= $this->url->link(t('Remove'), 'action', 'confirm', array('project_id' => $project['id'], 'action_id' => $action['id']), false, 'popover') ?>
</td>
</tr>
<?php endforeach ?>
</table>
<?php endif ?>
<h3><?= t('Add an action') ?></h3>
<form method="post" action="<?= $this->url->href('action', 'event', array('project_id' => $project['id'])) ?>" class="listing">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('project_id', $values) ?>
<?= $this->form->label(t('Action'), 'action_name') ?>
<?= $this->form->select('action_name', $available_actions, $values) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Next step') ?></button>
</div>
</form>

View File

@@ -0,0 +1,16 @@
<div class="page-header">
<h2><?= t('Add an action') ?></h2>
</div>
<form class="popover-form" method="post" action="<?= $this->url->href('ActionCreation', 'event', array('project_id' => $project['id'])) ?>">
<?= $this->form->csrf() ?>
<?= $this->form->hidden('project_id', $values) ?>
<?= $this->form->label(t('Action'), 'action_name') ?>
<?= $this->form->select('action_name', $available_actions, $values) ?>
<div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Next step') ?></button>
<?= t('or') ?>
<?= $this->url->link(t('cancel'), 'Action', 'index', array(), false, 'close-popover') ?>
</div>
</form>

View File

@@ -1,15 +1,17 @@
<div class="page-header"> <div class="page-header">
<h2><?= t('Automatic actions for the project "%s"', $project['name']) ?></h2> <h2><?= t('Choose an event') ?></h2>
</div> </div>
<h3><?= t('Choose an event') ?></h3> <form class="popover-form" method="post" action="<?= $this->url->href('ActionCreation', 'params', array('project_id' => $project['id'])) ?>">
<form method="post" action="<?= $this->url->href('action', 'params', array('project_id' => $project['id'])) ?>">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
<?= $this->form->hidden('project_id', $values) ?> <?= $this->form->hidden('project_id', $values) ?>
<?= $this->form->hidden('action_name', $values) ?> <?= $this->form->hidden('action_name', $values) ?>
<?= $this->form->label(t('Action'), 'action_name') ?>
<?= $this->form->select('action_name', $available_actions, $values, array(), array('disabled')) ?>
<?= $this->form->label(t('Event'), 'event_name') ?> <?= $this->form->label(t('Event'), 'event_name') ?>
<?= $this->form->select('event_name', $events, $values) ?> <?= $this->form->select('event_name', $events, $values) ?>
@@ -20,6 +22,6 @@
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Next step') ?></button> <button type="submit" class="btn btn-blue"><?= t('Next step') ?></button>
<?= t('or') ?> <?= t('or') ?>
<?= $this->url->link(t('cancel'), 'action', 'index', array('project_id' => $project['id'])) ?> <?= $this->url->link(t('cancel'), 'action', 'index', array('project_id' => $project['id']), false, 'close-popover') ?>
</div> </div>
</form> </form>

View File

@@ -1,9 +1,8 @@
<div class="page-header"> <div class="page-header">
<h2><?= t('Automatic actions for the project "%s"', $project['name']) ?></h2> <h2><?= t('Define action parameters') ?></h2>
</div> </div>
<h3><?= t('Define action parameters') ?></h3> <form class="popover-form" method="post" action="<?= $this->url->href('ActionCreation', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
<form method="post" action="<?= $this->url->href('action', 'create', array('project_id' => $project['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
@@ -11,8 +10,13 @@
<?= $this->form->hidden('event_name', $values) ?> <?= $this->form->hidden('event_name', $values) ?>
<?= $this->form->hidden('action_name', $values) ?> <?= $this->form->hidden('action_name', $values) ?>
<?php foreach ($action_params as $param_name => $param_desc): ?> <?= $this->form->label(t('Action'), 'action_name') ?>
<?= $this->form->select('action_name', $available_actions, $values, array(), array('disabled')) ?>
<?= $this->form->label(t('Event'), 'event_name') ?>
<?= $this->form->select('event_name', $events, $values, array(), array('disabled')) ?>
<?php foreach ($action_params as $param_name => $param_desc): ?>
<?php if ($this->text->contains($param_name, 'column_id')): ?> <?php if ($this->text->contains($param_name, 'column_id')): ?>
<?= $this->form->label($param_desc, $param_name) ?> <?= $this->form->label($param_desc, $param_name) ?>
<?= $this->form->select('params['.$param_name.']', $columns_list, $values) ?> <?= $this->form->select('params['.$param_name.']', $columns_list, $values) ?>
@@ -38,12 +42,11 @@
<?= $this->form->label($param_desc, $param_name) ?> <?= $this->form->label($param_desc, $param_name) ?>
<?= $this->form->text('params['.$param_name.']', $values) ?> <?= $this->form->text('params['.$param_name.']', $values) ?>
<?php endif ?> <?php endif ?>
<?php endforeach ?> <?php endforeach ?>
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button> <button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?> <?= t('or') ?>
<?= $this->url->link(t('cancel'), 'action', 'index', array('project_id' => $project['id'])) ?> <?= $this->url->link(t('cancel'), 'action', 'index', array('project_id' => $project['id']), false, 'close-popover') ?>
</div> </div>
</form> </form>

View File

@@ -1,22 +1,20 @@
<section id="main"> <div class="page-header">
<div class="page-header"> <h2><?= t('Import actions from another project') ?></h2>
<h2><?= t('Import actions from another project') ?></h2> </div>
</div> <?php if (empty($projects_list)): ?>
<?php if (empty($projects_list)): ?> <p class="alert"><?= t('There is no available project.') ?></p>
<p class="alert"><?= t('There is no available project.') ?></p> <?php else: ?>
<?php else: ?> <form class="popover-form" method="post" action="<?= $this->url->href('ActionProject', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
<form class="popover-form" method="post" action="<?= $this->url->href('ActionProject', 'save', array('project_id' => $project['id'])) ?>" autocomplete="off">
<?= $this->form->csrf() ?> <?= $this->form->csrf() ?>
<?= $this->form->label(t('Create from another project'), 'src_project_id') ?> <?= $this->form->label(t('Create from another project'), 'src_project_id') ?>
<?= $this->form->select('src_project_id', $projects_list) ?> <?= $this->form->select('src_project_id', $projects_list) ?>
<div class="form-actions"> <div class="form-actions">
<button type="submit" class="btn btn-blue"><?= t('Save') ?></button> <button type="submit" class="btn btn-blue"><?= t('Save') ?></button>
<?= t('or') ?> <?= t('or') ?>
<?= $this->url->link(t('cancel'), 'Action', 'index', array(), false, 'close-popover') ?> <?= $this->url->link(t('cancel'), 'Action', 'index', array(), false, 'close-popover') ?>
</div> </div>
</form> </form>
<?php endif ?> <?php endif ?>
</section>

File diff suppressed because one or more lines are too long

View File

@@ -180,6 +180,10 @@ input.form-input-large {
font-weight: bold; font-weight: bold;
} }
.popover-form {
margin-bottom: 0;
}
/* preview tabs */ /* preview tabs */
label + .form-tabs { label + .form-tabs {
margin-top: 10px; margin-top: 10px;