From ff892c5d25e0bab560f005c788189d38c2bcab7b Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Wed, 25 May 2016 22:28:09 -0400 Subject: Split project controller into multiple classes --- app/Controller/Project.php | 240 ------------------------- app/Controller/ProjectCreation.php | 2 +- app/Controller/ProjectListController.php | 41 +++++ app/Controller/ProjectStatusController.php | 102 +++++++++++ app/Controller/ProjectViewController.php | 162 +++++++++++++++++ app/Formatter/ProjectGanttFormatter.php | 2 +- app/ServiceProvider/AuthenticationProvider.php | 3 +- app/ServiceProvider/RouteProvider.php | 17 +- app/Template/dashboard/layout.php | 4 +- app/Template/gantt/projects.php | 2 +- app/Template/header.php | 2 +- app/Template/project/disable.php | 14 -- app/Template/project/dropdown.php | 2 +- app/Template/project/duplicate.php | 28 --- app/Template/project/enable.php | 14 -- app/Template/project/index.php | 85 --------- app/Template/project/integrations.php | 15 -- app/Template/project/notifications.php | 20 --- app/Template/project/remove.php | 14 -- app/Template/project/share.php | 19 -- app/Template/project/show.php | 85 --------- app/Template/project/sidebar.php | 34 ++-- app/Template/project_creation/create.php | 4 +- app/Template/project_header/dropdown.php | 4 +- app/Template/project_list/show.php | 85 +++++++++ app/Template/project_status/disable.php | 14 ++ app/Template/project_status/enable.php | 14 ++ app/Template/project_status/remove.php | 14 ++ app/Template/project_user/layout.php | 2 +- app/Template/project_user/roles.php | 4 +- app/Template/project_view/duplicate.php | 28 +++ app/Template/project_view/integrations.php | 15 ++ app/Template/project_view/notifications.php | 20 +++ app/Template/project_view/share.php | 18 ++ app/Template/project_view/show.php | 85 +++++++++ 35 files changed, 638 insertions(+), 576 deletions(-) delete mode 100644 app/Controller/Project.php create mode 100644 app/Controller/ProjectListController.php create mode 100644 app/Controller/ProjectStatusController.php create mode 100644 app/Controller/ProjectViewController.php delete mode 100644 app/Template/project/disable.php delete mode 100644 app/Template/project/duplicate.php delete mode 100644 app/Template/project/enable.php delete mode 100644 app/Template/project/index.php delete mode 100644 app/Template/project/integrations.php delete mode 100644 app/Template/project/notifications.php delete mode 100644 app/Template/project/remove.php delete mode 100644 app/Template/project/share.php delete mode 100644 app/Template/project/show.php create mode 100644 app/Template/project_list/show.php create mode 100644 app/Template/project_status/disable.php create mode 100644 app/Template/project_status/enable.php create mode 100644 app/Template/project_status/remove.php create mode 100644 app/Template/project_view/duplicate.php create mode 100644 app/Template/project_view/integrations.php create mode 100644 app/Template/project_view/notifications.php create mode 100644 app/Template/project_view/share.php create mode 100644 app/Template/project_view/show.php diff --git a/app/Controller/Project.php b/app/Controller/Project.php deleted file mode 100644 index 22a9ad30..00000000 --- a/app/Controller/Project.php +++ /dev/null @@ -1,240 +0,0 @@ -userSession->isAdmin()) { - $project_ids = $this->project->getAllIds(); - } else { - $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); - } - - $nb_projects = count($project_ids); - - $paginator = $this->paginator - ->setUrl('project', 'index') - ->setMax(20) - ->setOrder('name') - ->setQuery($this->project->getQueryColumnStats($project_ids)) - ->calculate(); - - $this->response->html($this->helper->layout->app('project/index', array( - 'paginator' => $paginator, - 'nb_projects' => $nb_projects, - 'title' => t('Projects').' ('.$nb_projects.')' - ))); - } - - /** - * Show the project information page - * - * @access public - */ - public function show() - { - $project = $this->getProject(); - - $this->response->html($this->helper->layout->project('project/show', array( - 'project' => $project, - 'stats' => $this->project->getTaskStats($project['id']), - 'title' => $project['name'], - ))); - } - - /** - * Public access management - * - * @access public - */ - public function share() - { - $project = $this->getProject(); - $switch = $this->request->getStringParam('switch'); - - if ($switch === 'enable' || $switch === 'disable') { - $this->checkCSRFParam(); - - if ($this->project->{$switch.'PublicAccess'}($project['id'])) { - $this->flash->success(t('Project updated successfully.')); - } else { - $this->flash->failure(t('Unable to update this project.')); - } - - $this->response->redirect($this->helper->url->to('project', 'share', array('project_id' => $project['id']))); - } else { - $this->show(); - } - } - - /** - * Integrations page - * - * @access public - */ - public function integrations() - { - $project = $this->getProject(); - - if ($this->request->isPost()) { - $this->projectMetadata->save($project['id'], $this->request->getValues()); - $this->flash->success(t('Project updated successfully.')); - $this->response->redirect($this->helper->url->to('project', 'integrations', array('project_id' => $project['id']))); - } else { - $this->response->html($this->helper->layout->project('project/integrations', array( - 'project' => $project, - 'title' => t('Integrations'), - 'webhook_token' => $this->config->get('webhook_token'), - 'values' => $this->projectMetadata->getAll($project['id']), - 'errors' => array(), - ))); - } - } - - /** - * Display project notifications - * - * @access public - */ - public function notifications() - { - $project = $this->getProject(); - - if ($this->request->isPost()) { - $values = $this->request->getValues(); - $this->projectNotification->saveSettings($project['id'], $values); - $this->flash->success(t('Project updated successfully.')); - return $this->response->redirect($this->helper->url->to('project', 'notifications', array('project_id' => $project['id']))); - } - - return $this->response->html($this->helper->layout->project('project/notifications', array( - 'notifications' => $this->projectNotification->readSettings($project['id']), - 'types' => $this->projectNotificationType->getTypes(), - 'project' => $project, - 'title' => t('Notifications'), - ))); - } - - /** - * Remove a project - * - * @access public - */ - public function remove() - { - $project = $this->getProject(); - - if ($this->request->getStringParam('remove') === 'yes') { - $this->checkCSRFParam(); - - if ($this->project->remove($project['id'])) { - $this->flash->success(t('Project removed successfully.')); - } else { - $this->flash->failure(t('Unable to remove this project.')); - } - - return $this->response->redirect($this->helper->url->to('project', 'index')); - } - - return $this->response->html($this->helper->layout->project('project/remove', array( - 'project' => $project, - 'title' => t('Remove project') - ))); - } - - /** - * Duplicate a project - * - * @author Antonio Rabelo - * @author Michael Lüpkes - * @access public - */ - public function duplicate() - { - $project = $this->getProject(); - - if ($this->request->getStringParam('duplicate') === 'yes') { - $project_id = $this->projectDuplication->duplicate($project['id'], array_keys($this->request->getValues()), $this->userSession->getId()); - - if ($project_id !== false) { - $this->flash->success(t('Project cloned successfully.')); - } else { - $this->flash->failure(t('Unable to clone this project.')); - } - - return $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project_id))); - } - - return $this->response->html($this->helper->layout->project('project/duplicate', array( - 'project' => $project, - 'title' => t('Clone this project') - ))); - } - - /** - * Disable a project - * - * @access public - */ - public function disable() - { - $project = $this->getProject(); - - if ($this->request->getStringParam('disable') === 'yes') { - $this->checkCSRFParam(); - - if ($this->project->disable($project['id'])) { - $this->flash->success(t('Project disabled successfully.')); - } else { - $this->flash->failure(t('Unable to disable this project.')); - } - - return $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project['id']))); - } - - return $this->response->html($this->helper->layout->project('project/disable', array( - 'project' => $project, - 'title' => t('Project activation') - ))); - } - - /** - * Enable a project - * - * @access public - */ - public function enable() - { - $project = $this->getProject(); - - if ($this->request->getStringParam('enable') === 'yes') { - $this->checkCSRFParam(); - - if ($this->project->enable($project['id'])) { - $this->flash->success(t('Project activated successfully.')); - } else { - $this->flash->failure(t('Unable to activate this project.')); - } - - return $this->response->redirect($this->helper->url->to('project', 'show', array('project_id' => $project['id']))); - } - - return $this->response->html($this->helper->layout->project('project/enable', array( - 'project' => $project, - 'title' => t('Project activation') - ))); - } -} diff --git a/app/Controller/ProjectCreation.php b/app/Controller/ProjectCreation.php index ed997fea..0ffa2174 100644 --- a/app/Controller/ProjectCreation.php +++ b/app/Controller/ProjectCreation.php @@ -59,7 +59,7 @@ class ProjectCreation extends BaseController 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))); + return $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project_id))); } $this->flash->failure(t('Unable to create your project.')); diff --git a/app/Controller/ProjectListController.php b/app/Controller/ProjectListController.php new file mode 100644 index 00000000..5571b3c9 --- /dev/null +++ b/app/Controller/ProjectListController.php @@ -0,0 +1,41 @@ +userSession->isAdmin()) { + $project_ids = $this->project->getAllIds(); + } else { + $project_ids = $this->projectPermission->getActiveProjectIds($this->userSession->getId()); + } + + $nb_projects = count($project_ids); + + $paginator = $this->paginator + ->setUrl('ProjectListController', 'show') + ->setMax(20) + ->setOrder('name') + ->setQuery($this->project->getQueryColumnStats($project_ids)) + ->calculate(); + + $this->response->html($this->helper->layout->app('project_list/show', array( + 'paginator' => $paginator, + 'nb_projects' => $nb_projects, + 'title' => t('Projects').' ('.$nb_projects.')' + ))); + } +} diff --git a/app/Controller/ProjectStatusController.php b/app/Controller/ProjectStatusController.php new file mode 100644 index 00000000..16ac32b8 --- /dev/null +++ b/app/Controller/ProjectStatusController.php @@ -0,0 +1,102 @@ +getProject(); + + $this->response->html($this->template->render('project_status/enable', array( + 'project' => $project, + 'title' => t('Project activation') + ))); + } + + /** + * Enable the project + */ + public function enable() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + + if ($this->project->enable($project['id'])) { + $this->flash->success(t('Project activated successfully.')); + } else { + $this->flash->failure(t('Unable to activate this project.')); + } + + $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project['id'])), true); + } + + /** + * Disable a project (confirmation dialog box) + */ + public function confirmDisable() + { + $project = $this->getProject(); + + $this->response->html($this->template->render('project_status/disable', array( + 'project' => $project, + 'title' => t('Project activation') + ))); + } + + /** + * Disable a project + */ + public function disable() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + + if ($this->project->disable($project['id'])) { + $this->flash->success(t('Project disabled successfully.')); + } else { + $this->flash->failure(t('Unable to disable this project.')); + } + + $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project['id'])), true); + } + + /** + * Remove a project (confirmation dialog box) + */ + public function confirmRemove() + { + $project = $this->getProject(); + + $this->response->html($this->template->render('project_status/remove', array( + 'project' => $project, + 'title' => t('Remove project') + ))); + } + + /** + * Remove a project + */ + public function remove() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + + if ($this->project->remove($project['id'])) { + $this->flash->success(t('Project removed successfully.')); + } else { + $this->flash->failure(t('Unable to remove this project.')); + } + + $this->response->redirect($this->helper->url->to('ProjectListController', 'show'), true); + } +} diff --git a/app/Controller/ProjectViewController.php b/app/Controller/ProjectViewController.php new file mode 100644 index 00000000..ca112a41 --- /dev/null +++ b/app/Controller/ProjectViewController.php @@ -0,0 +1,162 @@ +getProject(); + + $this->response->html($this->helper->layout->project('project_view/show', array( + 'project' => $project, + 'stats' => $this->project->getTaskStats($project['id']), + 'title' => $project['name'], + ))); + } + + /** + * Public access management + * + * @access public + */ + public function share() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('project_view/share', array( + 'project' => $project, + 'title' => t('Public access'), + ))); + } + + /** + * Change project sharing + * + * @throws \Kanboard\Core\Controller\AccessForbiddenException + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function updateSharing() + { + $project = $this->getProject(); + $this->checkCSRFParam(); + $switch = $this->request->getStringParam('switch'); + + if ($this->project->{$switch.'PublicAccess'}($project['id'])) { + $this->flash->success(t('Project updated successfully.')); + } else { + $this->flash->failure(t('Unable to update this project.')); + } + + $this->response->redirect($this->helper->url->to('ProjectViewController', 'share', array('project_id' => $project['id']))); + } + + /** + * Integrations page + * + * @access public + */ + public function integrations() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('project_view/integrations', array( + 'project' => $project, + 'title' => t('Integrations'), + 'webhook_token' => $this->config->get('webhook_token'), + 'values' => $this->projectMetadata->getAll($project['id']), + 'errors' => array(), + ))); + } + + /** + * Update integrations + * + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function updateIntegrations() + { + $project = $this->getProject(); + + $this->projectMetadata->save($project['id'], $this->request->getValues()); + $this->flash->success(t('Project updated successfully.')); + $this->response->redirect($this->helper->url->to('ProjectViewController', 'integrations', array('project_id' => $project['id']))); + } + + /** + * Display project notifications + * + * @access public + */ + public function notifications() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('project_view/notifications', array( + 'notifications' => $this->projectNotification->readSettings($project['id']), + 'types' => $this->projectNotificationType->getTypes(), + 'project' => $project, + 'title' => t('Notifications'), + ))); + } + + /** + * Update notifications + * + * @throws \Kanboard\Core\Controller\PageNotFoundException + */ + public function updateNotifications() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + $this->projectNotification->saveSettings($project['id'], $values); + $this->flash->success(t('Project updated successfully.')); + $this->response->redirect($this->helper->url->to('ProjectViewController', 'notifications', array('project_id' => $project['id']))); + } + + /** + * Duplicate a project + * + * @author Antonio Rabelo + * @author Michael Lüpkes + * @access public + */ + public function duplicate() + { + $project = $this->getProject(); + + $this->response->html($this->helper->layout->project('project_view/duplicate', array( + 'project' => $project, + 'title' => t('Clone this project') + ))); + } + + /** + * Do project duplication + */ + public function doDuplication() + { + $project = $this->getProject(); + $project_id = $this->projectDuplication->duplicate($project['id'], array_keys($this->request->getValues()), $this->userSession->getId()); + + if ($project_id !== false) { + $this->flash->success(t('Project cloned successfully.')); + } else { + $this->flash->failure(t('Unable to clone this project.')); + } + + $this->response->redirect($this->helper->url->to('ProjectViewController', 'show', array('project_id' => $project_id))); + } +} diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php index aee1f27f..532e6822 100644 --- a/app/Formatter/ProjectGanttFormatter.php +++ b/app/Formatter/ProjectGanttFormatter.php @@ -43,7 +43,7 @@ class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface (int) date('n', $end), (int) date('j', $end), ), - 'link' => $this->helper->url->href('project', 'show', array('project_id' => $project['id'])), + 'link' => $this->helper->url->href('ProjectViewController', 'show', array('project_id' => $project['id'])), 'board_link' => $this->helper->url->href('board', 'show', array('project_id' => $project['id'])), 'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])), 'color' => $color, diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index d4f130e2..fd61c1f6 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -81,11 +81,12 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('Export', '*', Role::PROJECT_MANAGER); $acl->add('TaskFile', array('screenshot', 'create', 'save', 'remove', 'confirm'), Role::PROJECT_MEMBER); $acl->add('Gantt', '*', Role::PROJECT_MANAGER); - $acl->add('Project', array('share', 'integrations', 'notifications', 'duplicate', 'disable', 'enable', 'remove'), Role::PROJECT_MANAGER); + $acl->add('ProjectViewController', array('share', 'updateSharing', 'integrations', 'updateIntegrations', 'notifications', 'updateNotifications', 'duplicate', 'doDuplication'), Role::PROJECT_MANAGER); $acl->add('ProjectPermission', '*', Role::PROJECT_MANAGER); $acl->add('ProjectEdit', '*', Role::PROJECT_MANAGER); $acl->add('ProjectFile', '*', Role::PROJECT_MEMBER); $acl->add('Projectuser', '*', Role::PROJECT_MANAGER); + $acl->add('ProjectStatusController', '*', Role::PROJECT_MANAGER); $acl->add('SubtaskController', '*', Role::PROJECT_MEMBER); $acl->add('SubtaskRestrictionController', '*', Role::PROJECT_MEMBER); $acl->add('SubtaskStatusController', '*', Role::PROJECT_MEMBER); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index 4a126b58..86e00cbd 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -49,17 +49,14 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('project/create/private', 'ProjectCreation', 'createPrivate'); // Project routes - $container['route']->addRoute('projects', 'project', 'index'); - $container['route']->addRoute('project/:project_id', 'project', 'show'); - $container['route']->addRoute('p/:project_id', 'project', 'show'); + $container['route']->addRoute('projects', 'ProjectListController', 'show'); + $container['route']->addRoute('project/:project_id', 'ProjectViewController', 'show'); + $container['route']->addRoute('p/:project_id', 'ProjectViewController', 'show'); $container['route']->addRoute('project/:project_id/customer-filters', 'customfilter', 'index'); - $container['route']->addRoute('project/:project_id/share', 'project', 'share'); - $container['route']->addRoute('project/:project_id/notifications', 'project', 'notifications'); - $container['route']->addRoute('project/:project_id/integrations', 'project', 'integrations'); - $container['route']->addRoute('project/:project_id/duplicate', 'project', 'duplicate'); - $container['route']->addRoute('project/:project_id/remove', 'project', 'remove'); - $container['route']->addRoute('project/:project_id/disable', 'project', 'disable'); - $container['route']->addRoute('project/:project_id/enable', 'project', 'enable'); + $container['route']->addRoute('project/:project_id/share', 'ProjectViewController', 'share'); + $container['route']->addRoute('project/:project_id/notifications', 'ProjectViewController', 'notifications'); + $container['route']->addRoute('project/:project_id/integrations', 'ProjectViewController', 'integrations'); + $container['route']->addRoute('project/:project_id/duplicate', 'ProjectViewController', 'duplicate'); $container['route']->addRoute('project/:project_id/permissions', 'ProjectPermission', 'index'); $container['route']->addRoute('project/:project_id/import', 'taskImport', 'step1'); $container['route']->addRoute('project/:project_id/activity', 'activity', 'project'); diff --git a/app/Template/dashboard/layout.php b/app/Template/dashboard/layout.php index 2a32ac02..187f7f42 100644 --- a/app/Template/dashboard/layout.php +++ b/app/Template/dashboard/layout.php @@ -19,7 +19,7 @@
  • - url->link(t('Project management'), 'project', 'index') ?> + url->link(t('Project management'), 'ProjectListController', 'show') ?>
  • @@ -29,4 +29,4 @@ - \ No newline at end of file + diff --git a/app/Template/gantt/projects.php b/app/Template/gantt/projects.php index a072452d..b8431d03 100644 --- a/app/Template/gantt/projects.php +++ b/app/Template/gantt/projects.php @@ -2,7 +2,7 @@ diff --git a/app/Template/project_list/show.php b/app/Template/project_list/show.php new file mode 100644 index 00000000..06e4a626 --- /dev/null +++ b/app/Template/project_list/show.php @@ -0,0 +1,85 @@ +
    + + isEmpty()): ?> +

    + + + + + + + + + + user->hasAccess('projectuser', 'managers')): ?> + + + + + getCollection() as $project): ?> + + + + + + + + user->hasAccess('projectuser', 'managers')): ?> + + + + + +
    order(t('Id'), 'id') ?>order(t('Status'), 'is_active') ?>order(t('Project'), 'name') ?>order(t('Start date'), 'start_date') ?>order(t('End date'), 'end_date') ?>order(t('Owner'), 'owner_id') ?>
    + render('project/dropdown', array('project' => $project)) ?> + + + + + + + + url->link($this->text->e($project['name']), 'board', 'show', array('project_id' => $project['id'])) ?> + + + + + + + + + + + + + + + dt->date($project['start_date']) ?> + + dt->date($project['end_date']) ?> + + 0): ?> + text->e($project['owner_name'] ?: $project['owner_username']) ?> + + + + + + + + text->e($column['title']) ?> + +
    + + + +
    diff --git a/app/Template/project_status/disable.php b/app/Template/project_status/disable.php new file mode 100644 index 00000000..d8145d3c --- /dev/null +++ b/app/Template/project_status/disable.php @@ -0,0 +1,14 @@ + + +
    +

    + +

    + +
    + url->link(t('Yes'), 'ProjectStatusController', 'disable', array('project_id' => $project['id']), true, 'btn btn-red') ?> + url->link(t('cancel'), 'ProjectViewController', 'show', array('project_id' => $project['id']), false, 'close-popover') ?> +
    +
    diff --git a/app/Template/project_status/enable.php b/app/Template/project_status/enable.php new file mode 100644 index 00000000..1f76d093 --- /dev/null +++ b/app/Template/project_status/enable.php @@ -0,0 +1,14 @@ + + +
    +

    + +

    + +
    + url->link(t('Yes'), 'ProjectStatusController', 'enable', array('project_id' => $project['id']), true, 'btn btn-red') ?> + url->link(t('cancel'), 'ProjectViewController', 'show', array('project_id' => $project['id']), false, 'close-popover') ?> +
    +
    diff --git a/app/Template/project_status/remove.php b/app/Template/project_status/remove.php new file mode 100644 index 00000000..8959ef75 --- /dev/null +++ b/app/Template/project_status/remove.php @@ -0,0 +1,14 @@ + + +
    +

    + +

    + +
    + url->link(t('Yes'), 'ProjectStatusController', 'remove', array('project_id' => $project['id']), true, 'btn btn-red') ?> + url->link(t('cancel'), 'ProjectViewController', 'show', array('project_id' => $project['id']), false, 'close-popover') ?> +
    +
    diff --git a/app/Template/project_user/layout.php b/app/Template/project_user/layout.php index 7a7c1a50..ab4326f6 100644 --- a/app/Template/project_user/layout.php +++ b/app/Template/project_user/layout.php @@ -3,7 +3,7 @@