From fc21d3873e3ac63222ad4065a593c715bef4c251 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 17:46:19 -0500 Subject: When creating a new project, have the possibility to select another project to duplicate --- app/Controller/ProjectCreation.php | 126 +++++++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) create mode 100644 app/Controller/ProjectCreation.php (limited to 'app/Controller/ProjectCreation.php') diff --git a/app/Controller/ProjectCreation.php b/app/Controller/ProjectCreation.php new file mode 100644 index 00000000..a3154034 --- /dev/null +++ b/app/Controller/ProjectCreation.php @@ -0,0 +1,126 @@ + t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + + $this->response->html($this->template->layout('project_creation/create', array( + 'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()), + 'values' => $values, + 'errors' => $errors, + 'is_private' => $is_private, + 'projects_list' => $projects_list, + 'title' => $is_private ? t('New private project') : t('New project'), + ))); + } + + /** + * Display a form to create a private project + * + * @access public + */ + public function createPrivate(array $values = array(), array $errors = array()) + { + $values['is_private'] = 1; + $this->create($values, $errors); + } + + /** + * Validate and save a new project + * + * @access public + */ + public function save() + { + $values = $this->request->getValues(); + list($valid, $errors) = $this->projectValidator->validateCreation($values); + + if ($valid) { + $project_id = $this->createOrDuplicate($values); + + if ($project_id > 0) { + $this->flash->success(t('Your project have been created successfully.')); + return $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id))); + } + + $this->flash->failure(t('Unable to create your project.')); + } + + $this->create($values, $errors); + } + + /** + * Create or duplicate a project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function createOrDuplicate(array $values) + { + if ($values['src_project_id'] == 0) { + return $this->createNewProject($values); + } + + return $this->duplicateNewProject($values); + } + + /** + * Save a new project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function createNewProject(array $values) + { + $project = array( + 'name' => $values['name'], + 'is_private' => $values['is_private'], + ); + + return $this->project->create($project, $this->userSession->getId(), true); + } + + /** + * Creatte from another project + * + * @access private + * @param array $values + * @return boolean|integer + */ + private function duplicateNewProject(array $values) + { + $selection = array(); + + foreach ($this->projectDuplication->getOptionalSelection() as $item) { + if (isset($values[$item]) && $values[$item] == 1) { + $selection[] = $item; + } + } + + return $this->projectDuplication->duplicate( + $values['src_project_id'], + $selection, + $this->userSession->getId(), + $values['name'], + $values['is_private'] == 1 + ); + } +} -- cgit v1.2.3 From 271543431e999032d6e91197633119309fa6c622 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sun, 31 Jan 2016 20:14:51 -0500 Subject: Make project creation form a inline popup --- app/Controller/Base.php | 3 +-- app/Controller/ProjectCreation.php | 3 +-- app/Core/Helper.php | 1 + app/Helper/Layout.php | 32 ++++++++++++++++++++++++++++++++ app/Template/app/layout.php | 4 ++-- app/Template/header.php | 4 ++-- app/Template/project_creation/create.php | 4 +--- 7 files changed, 40 insertions(+), 11 deletions(-) create mode 100644 app/Helper/Layout.php (limited to 'app/Controller/ProjectCreation.php') diff --git a/app/Controller/Base.php b/app/Controller/Base.php index 02d87aae..0939f44c 100644 --- a/app/Controller/Base.php +++ b/app/Controller/Base.php @@ -189,10 +189,9 @@ abstract class Base extends \Kanboard\Core\Base */ protected function taskLayout($template, array $params) { - $params['ajax'] = $this->request->isAjax(); $content = $this->template->render($template, $params); - if ($params['ajax']) { + if ($this->request->isAjax()) { return $content; } diff --git a/app/Controller/ProjectCreation.php b/app/Controller/ProjectCreation.php index a3154034..61ea2586 100644 --- a/app/Controller/ProjectCreation.php +++ b/app/Controller/ProjectCreation.php @@ -20,8 +20,7 @@ class ProjectCreation extends Base $is_private = isset($values['is_private']) && $values['is_private'] == 1; $projects_list = array(0 => t('Do not duplicate anything')) + $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); - $this->response->html($this->template->layout('project_creation/create', array( - 'board_selector' => $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()), + $this->response->html($this->helper->layout->app('project_creation/create', array( 'values' => $values, 'errors' => $errors, 'is_private' => $is_private, diff --git a/app/Core/Helper.php b/app/Core/Helper.php index 5edaa3f0..bf71769f 100644 --- a/app/Core/Helper.php +++ b/app/Core/Helper.php @@ -20,6 +20,7 @@ use Pimple\Container; * @property \Helper\Text $text * @property \Helper\Url $url * @property \Helper\User $user + * @property \Helper\Layout $layout */ class Helper { diff --git a/app/Helper/Layout.php b/app/Helper/Layout.php new file mode 100644 index 00000000..685c7b84 --- /dev/null +++ b/app/Helper/Layout.php @@ -0,0 +1,32 @@ +request->isAjax()) { + return $this->template->render($template, $params); + } + + $params['board_selector'] = $this->projectUserRole->getActiveProjectsByUser($this->userSession->getId()); + return $this->template->layout($template, $params); + } +} diff --git a/app/Template/app/layout.php b/app/Template/app/layout.php index 8a745327..d54b1da7 100644 --- a/app/Template/app/layout.php +++ b/app/Template/app/layout.php @@ -4,12 +4,12 @@ user->hasAccess('ProjectCreation', 'create')): ?>
  • - url->link(t('New project'), 'ProjectCreation', 'create') ?> + url->link(t('New project'), 'ProjectCreation', 'create', array(), false, 'popover') ?>
  • - url->link(t('New private project'), 'ProjectCreation', 'createPrivate') ?> + url->link(t('New private project'), 'ProjectCreation', 'createPrivate', array(), false, 'popover') ?>
  • diff --git a/app/Template/header.php b/app/Template/header.php index 36db54d5..fd9ff24d 100644 --- a/app/Template/header.php +++ b/app/Template/header.php @@ -42,10 +42,10 @@
      user->hasAccess('ProjectCreation', 'create')): ?> -
    • url->link(t('New project'), 'ProjectCreation', 'create') ?>
    • +
    • url->link(t('New project'), 'ProjectCreation', 'create', array(), false, 'popover') ?>
    • - url->link(t('New private project'), 'ProjectCreation', 'createPrivate') ?> + url->link(t('New private project'), 'ProjectCreation', 'createPrivate', array(), false, 'popover') ?>
    diff --git a/app/Template/project_creation/create.php b/app/Template/project_creation/create.php index 6caa36af..387f0ff4 100644 --- a/app/Template/project_creation/create.php +++ b/app/Template/project_creation/create.php @@ -1,8 +1,6 @@
    -- cgit v1.2.3 From ac2bf9d553abf17ca9f24cb5dcbfc011d4486215 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Mon, 8 Feb 2016 18:24:15 -0500 Subject: Fix PHP notices during creation of first project and in subtasks table --- ChangeLog | 7 +++++++ app/Controller/ProjectCreation.php | 2 +- app/Controller/SubtaskStatus.php | 1 + 3 files changed, 9 insertions(+), 1 deletion(-) (limited to 'app/Controller/ProjectCreation.php') diff --git a/ChangeLog b/ChangeLog index bf5d3d6c..a59439a9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Version 1.0.26 (unreleased) +-------------- + +Bug fixes: + +* Fix PHP notices during creation of first project and in subtasks table + Version 1.0.25 -------------- diff --git a/app/Controller/ProjectCreation.php b/app/Controller/ProjectCreation.php index 61ea2586..88f41fcd 100644 --- a/app/Controller/ProjectCreation.php +++ b/app/Controller/ProjectCreation.php @@ -73,7 +73,7 @@ class ProjectCreation extends Base */ private function createOrDuplicate(array $values) { - if ($values['src_project_id'] == 0) { + if (empty($values['src_project_id'])) { return $this->createNewProject($values); } diff --git a/app/Controller/SubtaskStatus.php b/app/Controller/SubtaskStatus.php index ef0ec081..4fb82fc0 100644 --- a/app/Controller/SubtaskStatus.php +++ b/app/Controller/SubtaskStatus.php @@ -66,6 +66,7 @@ class SubtaskStatus extends Base 'task' => $task, 'subtasks' => $this->subtask->getAll($task['id']), 'editable' => true, + 'redirect' => 'task', )); } } -- cgit v1.2.3