summaryrefslogtreecommitdiff
path: root/app/Controller
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-05 17:40:49 -0500
committerFrederic Guillot <fred@kanboard.net>2016-03-05 17:40:49 -0500
commit22c5e32def94560881ad9ec032158cd570be44f4 (patch)
tree7cfe346a2b7d384c9cdcd143693bc8189ac18259 /app/Controller
parenta19dc88567e6869b9082064e70db380f84032cef (diff)
Improve automatic action creation
Diffstat (limited to 'app/Controller')
-rw-r--r--app/Controller/Action.php94
-rw-r--r--app/Controller/ActionCreation.php121
-rw-r--r--app/Controller/ActionProject.php4
3 files changed, 124 insertions, 95 deletions
diff --git a/app/Controller/Action.php b/app/Controller/Action.php
index 6c324324..8881e8ec 100644
--- a/app/Controller/Action.php
+++ b/app/Controller/Action.php
@@ -3,7 +3,7 @@
namespace Kanboard\Controller;
/**
- * Automatic actions management
+ * Automatic Actions
*
* @package controller
* @author Frederic Guillot
@@ -38,98 +38,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
*
* @access public
diff --git a/app/Controller/ActionCreation.php b/app/Controller/ActionCreation.php
new file mode 100644
index 00000000..24a12d92
--- /dev/null
+++ b/app/Controller/ActionCreation.php
@@ -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'])));
+ }
+}
diff --git a/app/Controller/ActionProject.php b/app/Controller/ActionProject.php
index 6de0fe58..e5063f73 100644
--- a/app/Controller/ActionProject.php
+++ b/app/Controller/ActionProject.php
@@ -16,7 +16,7 @@ class ActionProject extends Base
$projects = $this->projectUserRole->getProjectsByUser($this->userSession->getId());
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,
'projects_list' => $projects,
)));
@@ -33,6 +33,6 @@ class ActionProject extends Base
$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'])));
}
}