From 9e218032c485b7ab6ef8e00f45890151988b0f90 Mon Sep 17 00:00:00 2001 From: Frederic Guillot Date: Sat, 28 May 2016 14:29:07 -0400 Subject: [PATCH] Split Gantt controller --- app/Controller/Gantt.php | 165 ------------------ app/Controller/ProjectGanttController.php | 57 ++++++ app/Controller/TaskGanttController.php | 62 +++++++ .../TaskGanttCreationController.php | 71 ++++++++ app/Formatter/ProjectGanttFormatter.php | 2 +- .../AuthenticationProvider.php | 5 +- app/ServiceProvider/RouteProvider.php | 4 +- app/Template/dashboard/projects.php | 4 +- app/Template/project/dropdown.php | 4 +- .../projects.php => project_gantt/show.php} | 2 +- app/Template/project_header/views.php | 6 +- app/Template/project_list/show.php | 4 +- app/Template/project_user_overview/layout.php | 4 +- app/Template/project_user_overview/roles.php | 2 +- .../project.php => task_gantt/show.php} | 12 +- .../show.php} | 4 +- 16 files changed, 217 insertions(+), 191 deletions(-) delete mode 100644 app/Controller/Gantt.php create mode 100644 app/Controller/ProjectGanttController.php create mode 100644 app/Controller/TaskGanttController.php create mode 100644 app/Controller/TaskGanttCreationController.php rename app/Template/{gantt/projects.php => project_gantt/show.php} (93%) rename app/Template/{gantt/project.php => task_gantt/show.php} (62%) rename app/Template/{gantt/task_creation.php => task_gantt_creation/show.php} (87%) diff --git a/app/Controller/Gantt.php b/app/Controller/Gantt.php deleted file mode 100644 index d062b2fe2..000000000 --- a/app/Controller/Gantt.php +++ /dev/null @@ -1,165 +0,0 @@ -projectPermission->getActiveProjectIds($this->userSession->getId()); - $filter = $this->projectQuery - ->withFilter(new ProjectTypeFilter(ProjectModel::TYPE_TEAM)) - ->withFilter(new ProjectStatusFilter(ProjectModel::ACTIVE)) - ->withFilter(new ProjectIdsFilter($project_ids)); - - $filter->getQuery()->asc(ProjectModel::TABLE.'.start_date'); - - $this->response->html($this->helper->layout->app('gantt/projects', array( - 'projects' => $filter->format(new ProjectGanttFormatter($this->container)), - 'title' => t('Gantt chart for all projects'), - ))); - } - - /** - * Save new project start date and end date - */ - public function saveProjectDate() - { - $values = $this->request->getJson(); - - $result = $this->project->update(array( - 'id' => $values['id'], - 'start_date' => $this->dateParser->getIsoDate(strtotime($values['start'])), - 'end_date' => $this->dateParser->getIsoDate(strtotime($values['end'])), - )); - - if (! $result) { - $this->response->json(array('message' => 'Unable to save project'), 400); - } else { - $this->response->json(array('message' => 'OK'), 201); - } - } - - /** - * Show Gantt chart for one project - */ - public function project() - { - $project = $this->getProject(); - $search = $this->helper->projectHeader->getSearchQuery($project); - $sorting = $this->request->getStringParam('sorting', 'board'); - $filter = $this->taskLexer->build($search)->withFilter(new TaskProjectFilter($project['id'])); - - if ($sorting === 'date') { - $filter->getQuery()->asc(TaskModel::TABLE.'.date_started')->asc(TaskModel::TABLE.'.date_creation'); - } else { - $filter->getQuery()->asc('column_position')->asc(TaskModel::TABLE.'.position'); - } - - $this->response->html($this->helper->layout->app('gantt/project', array( - 'project' => $project, - 'title' => $project['name'], - 'description' => $this->helper->projectHeader->getDescription($project), - 'sorting' => $sorting, - 'tasks' => $filter->format(new TaskGanttFormatter($this->container)), - ))); - } - - /** - * Save new task start date and due date - */ - public function saveTaskDate() - { - $this->getProject(); - $values = $this->request->getJson(); - - $result = $this->taskModification->update(array( - 'id' => $values['id'], - 'date_started' => strtotime($values['start']), - 'date_due' => strtotime($values['end']), - )); - - if (! $result) { - $this->response->json(array('message' => 'Unable to save task'), 400); - } else { - $this->response->json(array('message' => 'OK'), 201); - } - } - - /** - * Simplified form to create a new task - * - * @access public - * @param array $values - * @param array $errors - * @throws \Kanboard\Core\Controller\PageNotFoundException - */ - public function task(array $values = array(), array $errors = array()) - { - $project = $this->getProject(); - - $values = $values + array( - 'project_id' => $project['id'], - 'column_id' => $this->column->getFirstColumnId($project['id']), - 'position' => 1 - ); - - $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); - $values = $this->hook->merge('controller:gantt:task:form:default', $values, array('default_values' => $values)); - - $this->response->html($this->template->render('gantt/task_creation', array( - 'project' => $project, - 'errors' => $errors, - 'values' => $values, - 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), - 'colors_list' => $this->color->getList(), - 'categories_list' => $this->category->getList($project['id']), - 'swimlanes_list' => $this->swimlane->getList($project['id'], false, true), - 'title' => $project['name'].' > '.t('New task') - ))); - } - - /** - * Validate and save a new task - * - * @access public - */ - public function saveTask() - { - $project = $this->getProject(); - $values = $this->request->getValues(); - - list($valid, $errors) = $this->taskValidator->validateCreation($values); - - if ($valid) { - $task_id = $this->taskCreation->create($values); - - if ($task_id !== false) { - $this->flash->success(t('Task created successfully.')); - return $this->response->redirect($this->helper->url->to('gantt', 'project', array('project_id' => $project['id']))); - } else { - $this->flash->failure(t('Unable to create your task.')); - } - } - - return $this->task($values, $errors); - } -} diff --git a/app/Controller/ProjectGanttController.php b/app/Controller/ProjectGanttController.php new file mode 100644 index 000000000..1c6ace582 --- /dev/null +++ b/app/Controller/ProjectGanttController.php @@ -0,0 +1,57 @@ +projectPermission->getActiveProjectIds($this->userSession->getId()); + $filter = $this->projectQuery + ->withFilter(new ProjectTypeFilter(Project::TYPE_TEAM)) + ->withFilter(new ProjectStatusFilter(Project::ACTIVE)) + ->withFilter(new ProjectIdsFilter($project_ids)); + + $filter->getQuery()->asc(Project::TABLE.'.start_date'); + + $this->response->html($this->helper->layout->app('project_gantt/show', array( + 'projects' => $filter->format(new ProjectGanttFormatter($this->container)), + 'title' => t('Gantt chart for all projects'), + ))); + } + + /** + * Save new project start date and end date + */ + public function save() + { + $values = $this->request->getJson(); + + $result = $this->project->update(array( + 'id' => $values['id'], + 'start_date' => $this->dateParser->getIsoDate(strtotime($values['start'])), + 'end_date' => $this->dateParser->getIsoDate(strtotime($values['end'])), + )); + + if (! $result) { + $this->response->json(array('message' => 'Unable to save project'), 400); + } else { + $this->response->json(array('message' => 'OK'), 201); + } + } +} diff --git a/app/Controller/TaskGanttController.php b/app/Controller/TaskGanttController.php new file mode 100644 index 000000000..3d0c5f50e --- /dev/null +++ b/app/Controller/TaskGanttController.php @@ -0,0 +1,62 @@ +getProject(); + $search = $this->helper->projectHeader->getSearchQuery($project); + $sorting = $this->request->getStringParam('sorting', 'board'); + $filter = $this->taskLexer->build($search)->withFilter(new TaskProjectFilter($project['id'])); + + if ($sorting === 'date') { + $filter->getQuery()->asc(TaskModel::TABLE.'.date_started')->asc(TaskModel::TABLE.'.date_creation'); + } else { + $filter->getQuery()->asc('column_position')->asc(TaskModel::TABLE.'.position'); + } + + $this->response->html($this->helper->layout->app('task_gantt/show', array( + 'project' => $project, + 'title' => $project['name'], + 'description' => $this->helper->projectHeader->getDescription($project), + 'sorting' => $sorting, + 'tasks' => $filter->format(new TaskGanttFormatter($this->container)), + ))); + } + + /** + * Save new task start date and due date + */ + public function save() + { + $this->getProject(); + $values = $this->request->getJson(); + + $result = $this->taskModification->update(array( + 'id' => $values['id'], + 'date_started' => strtotime($values['start']), + 'date_due' => strtotime($values['end']), + )); + + if (! $result) { + $this->response->json(array('message' => 'Unable to save task'), 400); + } else { + $this->response->json(array('message' => 'OK'), 201); + } + } +} diff --git a/app/Controller/TaskGanttCreationController.php b/app/Controller/TaskGanttCreationController.php new file mode 100644 index 000000000..0ae4ab3ba --- /dev/null +++ b/app/Controller/TaskGanttCreationController.php @@ -0,0 +1,71 @@ +getProject(); + + $values = $values + array( + 'project_id' => $project['id'], + 'column_id' => $this->column->getFirstColumnId($project['id']), + 'position' => 1 + ); + + $values = $this->hook->merge('controller:task:form:default', $values, array('default_values' => $values)); + $values = $this->hook->merge('controller:gantt:task:form:default', $values, array('default_values' => $values)); + + $this->response->html($this->template->render('task_gantt_creation/show', array( + 'project' => $project, + 'errors' => $errors, + 'values' => $values, + 'users_list' => $this->projectUserRole->getAssignableUsersList($project['id'], true, false, true), + 'colors_list' => $this->color->getList(), + 'categories_list' => $this->category->getList($project['id']), + 'swimlanes_list' => $this->swimlane->getList($project['id'], false, true), + 'title' => $project['name'].' > '.t('New task') + ))); + } + + /** + * Validate and save a new task + * + * @access public + */ + public function save() + { + $project = $this->getProject(); + $values = $this->request->getValues(); + + list($valid, $errors) = $this->taskValidator->validateCreation($values); + + if ($valid) { + $task_id = $this->taskCreation->create($values); + + if ($task_id !== false) { + $this->flash->success(t('Task created successfully.')); + return $this->response->redirect($this->helper->url->to('TaskGanttController', 'show', array('project_id' => $project['id']))); + } else { + $this->flash->failure(t('Unable to create your task.')); + } + } + + return $this->show($values, $errors); + } +} diff --git a/app/Formatter/ProjectGanttFormatter.php b/app/Formatter/ProjectGanttFormatter.php index 6c533b8c2..2400ed708 100644 --- a/app/Formatter/ProjectGanttFormatter.php +++ b/app/Formatter/ProjectGanttFormatter.php @@ -45,7 +45,7 @@ class ProjectGanttFormatter extends BaseFormatter implements FormatterInterface ), 'link' => $this->helper->url->href('ProjectViewController', 'show', array('project_id' => $project['id'])), 'board_link' => $this->helper->url->href('BoardViewController', 'show', array('project_id' => $project['id'])), - 'gantt_link' => $this->helper->url->href('gantt', 'project', array('project_id' => $project['id'])), + 'gantt_link' => $this->helper->url->href('TaskGanttController', 'show', array('project_id' => $project['id'])), 'color' => $color, 'not_defined' => empty($project['start_date']) || empty($project['end_date']), 'users' => $this->projectUserRole->getAllUsersGroupedByRole($project['id']), diff --git a/app/ServiceProvider/AuthenticationProvider.php b/app/ServiceProvider/AuthenticationProvider.php index 609b0c9f9..f8ea9b19b 100644 --- a/app/ServiceProvider/AuthenticationProvider.php +++ b/app/ServiceProvider/AuthenticationProvider.php @@ -80,7 +80,8 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('CustomFilterController', '*', Role::PROJECT_MEMBER); $acl->add('ExportController', '*', Role::PROJECT_MANAGER); $acl->add('TaskFileController', array('screenshot', 'create', 'save', 'remove', 'confirm'), Role::PROJECT_MEMBER); - $acl->add('Gantt', '*', Role::PROJECT_MANAGER); + $acl->add('TaskGanttController', '*', Role::PROJECT_MANAGER); + $acl->add('TaskGanttCreationController', '*', Role::PROJECT_MANAGER); $acl->add('ProjectViewController', array('share', 'updateSharing', 'integrations', 'updateIntegrations', 'notifications', 'updateNotifications', 'duplicate', 'doDuplication'), Role::PROJECT_MANAGER); $acl->add('ProjectPermissionController', '*', Role::PROJECT_MANAGER); $acl->add('ProjectEditController', '*', Role::PROJECT_MANAGER); @@ -132,7 +133,7 @@ class AuthenticationProvider implements ServiceProviderInterface $acl->add('ConfigController', '*', Role::APP_ADMIN); $acl->add('PluginController', '*', Role::APP_ADMIN); $acl->add('CurrencyController', '*', Role::APP_ADMIN); - $acl->add('Gantt', array('projects', 'saveProjectDate'), Role::APP_MANAGER); + $acl->add('ProjectGanttController', '*', Role::APP_MANAGER); $acl->add('GroupListController', '*', Role::APP_ADMIN); $acl->add('GroupCreationController', '*', Role::APP_ADMIN); $acl->add('GroupModificationController', '*', Role::APP_ADMIN); diff --git a/app/ServiceProvider/RouteProvider.php b/app/ServiceProvider/RouteProvider.php index f176e4c04..2e36e4257 100644 --- a/app/ServiceProvider/RouteProvider.php +++ b/app/ServiceProvider/RouteProvider.php @@ -128,8 +128,8 @@ class RouteProvider implements ServiceProviderInterface $container['route']->addRoute('l/:project_id', 'TaskListController', 'show'); // Gantt routes - $container['route']->addRoute('gantt/:project_id', 'gantt', 'project'); - $container['route']->addRoute('gantt/:project_id/sort/:sorting', 'gantt', 'project'); + $container['route']->addRoute('gantt/:project_id', 'TaskGanttController', 'show'); + $container['route']->addRoute('gantt/:project_id/sort/:sorting', 'TaskGanttController', 'show'); // Feed routes $container['route']->addRoute('feed/project/:token', 'FeedController', 'project'); diff --git a/app/Template/dashboard/projects.php b/app/Template/dashboard/projects.php index 4d33519a8..4aa406216 100644 --- a/app/Template/dashboard/projects.php +++ b/app/Template/dashboard/projects.php @@ -22,8 +22,8 @@ - user->hasProjectAccess('gantt', 'project', $project['id'])): ?> - url->link('', 'gantt', 'project', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?> + user->hasProjectAccess('TaskGanttController', 'show', $project['id'])): ?> + url->link('', 'TaskGanttController', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?> url->link('', 'TaskListController', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('List')) ?>  diff --git a/app/Template/project/dropdown.php b/app/Template/project/dropdown.php index c803384a4..90dccf212 100644 --- a/app/Template/project/dropdown.php +++ b/app/Template/project/dropdown.php @@ -13,10 +13,10 @@ url->link(t('Listing'), 'TaskListController', 'show', array('project_id' => $project['id'])) ?> - user->hasProjectAccess('Gantt', 'project', $project['id'])): ?> + user->hasProjectAccess('TaskGanttController', 'show', $project['id'])): ?>
  • - url->link(t('Gantt'), 'gantt', 'project', array('project_id' => $project['id'])) ?> + url->link(t('Gantt'), 'TaskGanttController', 'show', array('project_id' => $project['id'])) ?>
  • diff --git a/app/Template/gantt/projects.php b/app/Template/project_gantt/show.php similarity index 93% rename from app/Template/gantt/projects.php rename to app/Template/project_gantt/show.php index 9241e3725..af22a6ed5 100644 --- a/app/Template/gantt/projects.php +++ b/app/Template/project_gantt/show.php @@ -16,7 +16,7 @@
    url->link(t('List'), 'TaskListController', 'show', array('project_id' => $project['id'], 'search' => $filters['search']), false, 'view-listing', t('Keyboard shortcut: "%s"', 'v l')) ?> - user->hasProjectAccess('gantt', 'project', $project['id'])): ?> -
  • app->checkMenuSelection('Gantt') ?>> + user->hasProjectAccess('TaskGanttController', 'show', $project['id'])): ?> +
  • app->checkMenuSelection('TaskGanttController') ?>> - url->link(t('Gantt'), 'gantt', 'project', array('project_id' => $project['id'], 'search' => $filters['search']), false, 'view-gantt', t('Keyboard shortcut: "%s"', 'v g')) ?> + url->link(t('Gantt'), 'TaskGanttController', 'show', array('project_id' => $project['id'], 'search' => $filters['search']), false, 'view-gantt', t('Keyboard shortcut: "%s"', 'v g')) ?>
  • diff --git a/app/Template/project_list/show.php b/app/Template/project_list/show.php index 75b5495fd..8b9f13967 100644 --- a/app/Template/project_list/show.php +++ b/app/Template/project_list/show.php @@ -4,8 +4,8 @@ user->hasAccess('ProjectUserOverviewController', 'managers')): ?>
  • url->link(t('Users overview'), 'ProjectUserOverviewController', 'managers') ?>
  • - user->hasAccess('gantt', 'projects')): ?> -
  • url->link(t('Projects Gantt chart'), 'gantt', 'projects') ?>
  • + user->hasAccess('ProjectGanttController', 'show')): ?> +
  • url->link(t('Projects Gantt chart'), 'ProjectGanttController', 'show') ?>
  • diff --git a/app/Template/project_user_overview/layout.php b/app/Template/project_user_overview/layout.php index ab4326f6a..19b83436a 100644 --- a/app/Template/project_user_overview/layout.php +++ b/app/Template/project_user_overview/layout.php @@ -5,10 +5,10 @@ url->link(t('Projects list'), 'ProjectListController', 'show') ?> - user->hasAccess('gantt', 'projects')): ?> + user->hasAccess('ProjectGanttController', 'show')): ?>
  • - url->link(t('Projects Gantt chart'), 'gantt', 'projects') ?> + url->link(t('Projects Gantt chart'), 'ProjectGanttController', 'show') ?>
  • diff --git a/app/Template/project_user_overview/roles.php b/app/Template/project_user_overview/roles.php index 39412aabc..87c8df85a 100644 --- a/app/Template/project_user_overview/roles.php +++ b/app/Template/project_user_overview/roles.php @@ -14,7 +14,7 @@ url->link('', 'BoardViewController', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Board')) ?> - url->link('', 'gantt', 'project', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?> + url->link('', 'TaskGanttController', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Gantt chart')) ?> url->link('', 'ProjectViewController', 'show', array('project_id' => $project['id']), false, 'dashboard-table-link', t('Project settings')) ?> text->e($project['project_name']) ?> diff --git a/app/Template/gantt/project.php b/app/Template/task_gantt/show.php similarity index 62% rename from app/Template/gantt/project.php rename to app/Template/task_gantt/show.php index e6c8592f6..c5d338fb0 100644 --- a/app/Template/gantt/project.php +++ b/app/Template/task_gantt/show.php @@ -1,18 +1,18 @@
    - projectHeader->render($project, 'Gantt', 'project') ?> + projectHeader->render($project, 'TaskGanttController', 'show') ?> @@ -21,7 +21,7 @@

    -
    \ No newline at end of file + diff --git a/app/Template/gantt/task_creation.php b/app/Template/task_gantt_creation/show.php similarity index 87% rename from app/Template/gantt/task_creation.php rename to app/Template/task_gantt_creation/show.php index 673bd019b..683bc8c88 100644 --- a/app/Template/gantt/task_creation.php +++ b/app/Template/task_gantt_creation/show.php @@ -1,7 +1,7 @@ -
    + form->csrf() ?> form->hidden('project_id', $values) ?> form->hidden('column_id', $values) ?> @@ -30,6 +30,6 @@
    - url->link(t('cancel'), 'BoardViewController', 'show', array('project_id' => $values['project_id']), false, 'close-popover') ?> + url->link(t('cancel'), 'TaskGanttController', 'show', array('project_id' => $values['project_id']), false, 'close-popover') ?>