added more entity actions (#757)

This commit is contained in:
Björn Weinbrenner
2019-05-10 02:10:37 +02:00
committed by Kevin Papst
parent b1855447b8
commit e619b5fd31
8 changed files with 106 additions and 21 deletions

View File

@@ -10,6 +10,7 @@
namespace App\Controller;
use App\Entity\Activity;
use App\Entity\Project;
use App\Form\ActivityEditForm;
use App\Form\Toolbar\ActivityToolbarForm;
use App\Form\Type\ActivityType;
@@ -75,14 +76,21 @@ class ActivityController extends AbstractController
/**
* @Route(path="/create", name="admin_activity_create", methods={"GET", "POST"})
* @Route(path="/create/{project}", name="admin_activity_create_with_project", methods={"GET", "POST"})
* @Security("is_granted('create_activity')")
*
* @param Request $request
* @param Project|null $project
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request)
public function createAction(Request $request, ?Project $project = null)
{
return $this->renderActivityForm(new Activity(), $request);
$activity = new Activity();
if (null !== $project) {
$activity->setProject($project);
}
return $this->renderActivityForm($activity, $request);
}
/**

View File

@@ -76,14 +76,22 @@ class ProjectController extends AbstractController
/**
* @Route(path="/create", name="admin_project_create", methods={"GET", "POST"})
* @Route(path="/create/{customer}", name="admin_project_create_with_customer", methods={"GET", "POST"})
* @Security("is_granted('create_project')")
*
* @param Request $request
* @param Customer|null $customer
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request)
public function createAction(Request $request, ?Customer $customer = null)
{
return $this->renderProjectForm(new Project(), $request);
$project = new Project();
if (null !== $customer) {
$project->setCustomer($customer);
}
return $this->renderProjectForm($project, $request);
}
/**

View File

@@ -12,6 +12,8 @@ namespace App\Controller;
use App\Entity\Timesheet;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use Doctrine\ORM\ORMException;
use Pagerfanta\Pagerfanta;
@@ -210,16 +212,18 @@ class TimesheetController extends AbstractController
* @Security("is_granted('create_own_timesheet')")
*
* @param Request $request
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request)
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
$route = 'timesheet';
if ('calendar' === $request->get('origin')) {
$route = 'calendar';
}
return $this->create($request, $route, 'timesheet/edit.html.twig');
return $this->create($request, $route, 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
}
/**

View File

@@ -12,6 +12,8 @@ namespace App\Controller;
use App\Configuration\TimesheetConfiguration;
use App\Entity\Timesheet;
use App\Entity\User;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\TimesheetRepository;
use App\Timesheet\UserDateTimeFactory;
use Doctrine\Common\Persistence\ManagerRegistry;
@@ -116,9 +118,11 @@ trait TimesheetControllerTrait
* @param Request $request
* @param string $redirectRoute
* @param string $renderTemplate
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
protected function create(Request $request, $redirectRoute, $renderTemplate)
protected function create(Request $request, $redirectRoute, $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
$entry = new Timesheet();
$entry->setUser($this->getUser());
@@ -158,6 +162,16 @@ trait TimesheetControllerTrait
}
}
if ($request->query->get('project')) {
$project = $projectRepository->find($request->query->get('project'));
$entry->setProject($project);
}
if ($request->query->get('activity')) {
$activity = $activityRepository->find($request->query->get('activity'));
$entry->setActivity($activity);
}
$createForm = $this->getCreateForm($entry, $redirectRoute);
$createForm->handleRequest($request);

View File

@@ -12,6 +12,8 @@ namespace App\Controller;
use App\Entity\Timesheet;
use App\Form\TimesheetEditForm;
use App\Form\Toolbar\TimesheetToolbarForm;
use App\Repository\ActivityRepository;
use App\Repository\ProjectRepository;
use App\Repository\Query\TimesheetQuery;
use Doctrine\ORM\ORMException;
use Pagerfanta\Pagerfanta;
@@ -136,11 +138,13 @@ class TimesheetTeamController extends AbstractController
* @Security("is_granted('create_other_timesheet')")
*
* @param Request $request
* @param ProjectRepository $projectRepository
* @param ActivityRepository $activityRepository
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function createAction(Request $request)
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
{
return $this->create($request, 'admin_timesheet', 'timesheet-team/edit.html.twig');
return $this->create($request, 'admin_timesheet', 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository);
}
/**

View File

@@ -23,6 +23,12 @@
{% endif %}
{% set actions = actions|merge({'edit': {'url': path('admin_activity_edit', {'id': activity.id}), 'class': class}}) %}
{% endif %}
{% if is_granted('view_other_timesheet') %}
{% set actions = actions|merge({'timesheet': path('admin_timesheet', {'customer': activity.project ? activity.project.customer.id : null, 'project': activity.project ? activity.project.id : null, 'activity': activity.id})}) %}
{% endif %}
{% if is_granted('create_other_timesheet') %}
{% set actions = actions|merge({'create-timesheet': path('admin_timesheet_create', {'project': activity.project ? activity.project.id : null, 'activity': activity.id})}) %}
{% endif %}
{% if view == 'index' and is_granted('delete', activity) %}
{% set actions = actions|merge({'trash': {'url': path('admin_activity_delete', {'id': activity.id}), 'class': 'modal-ajax-form'}}) %}
{% endif %}
@@ -109,6 +115,12 @@
{% if is_granted('view_activity') %}
{% set actions = actions|merge({'activity': path('admin_activity', {'customer': project.customer.id, 'project': project.id})}) %}
{% endif %}
{% if is_granted('view_other_timesheet') %}
{% set actions = actions|merge({'timesheet': path('admin_timesheet', {'customer': project.customer.id, 'project': project.id})}) %}
{% endif %}
{% if is_granted('create_activity') and project.visible and project.customer.visible %}
{% set actions = actions|merge({'create-activity': path('admin_activity_create_with_project', {'project': project.id})}) %}
{% endif %}
{% if view == 'index' and is_granted('delete', project) %}
{% set actions = actions|merge({'trash': {'url': path('admin_project_delete', {'id': project.id}), 'class': 'modal-ajax-form'}}) %}
{% endif %}
@@ -153,6 +165,15 @@
{% if is_granted('view_project') %}
{% set actions = actions|merge({'project': path('admin_project', {'customer': customer.id})}) %}
{% endif %}
{% if is_granted('view_activity') %}
{% set actions = actions|merge({'activity': path('admin_activity', {'customer': customer.id})}) %}
{% endif %}
{% if is_granted('view_other_timesheet') %}
{% set actions = actions|merge({'timesheet': path('admin_timesheet', {'customer': customer.id})}) %}
{% endif %}
{% if is_granted('create_project') and customer.visible %}
{% set actions = actions|merge({'create-project': path('admin_project_create_with_customer', {'customer': customer.id})}) %}
{% endif %}
{% if view == 'index' and is_granted('delete', customer) %}
{% set actions = actions|merge({'trash': {'url': path('admin_customer_delete', {'id': customer.id}), 'class': 'modal-ajax-form'}}) %}
{% endif %}
@@ -193,14 +214,12 @@
{% set actions = {} %}
{% if timesheet.id is not empty %}
{% if timesheet.end %}
{% if is_granted('start', timesheet) %}
{% set actions = actions|merge({'repeat': path('timesheet_start', {'id' : timesheet.id})}) %}
{% endif %}
{% else %}
{% if is_granted('stop', timesheet) %}
{% if not timesheet.end and is_granted('stop', timesheet) %}
{% set actions = actions|merge({'stop': path('timesheet_stop', {'id' : timesheet.id})}) %}
{% endif %}
{% if timesheet.end and is_granted('start', timesheet) %}
{% set actions = actions|merge({'repeat': path('timesheet_start', {'id' : timesheet.id})}) %}
{% endif %}
{% if is_granted('edit', timesheet) %}
@@ -250,6 +269,14 @@
{% set actions = {} %}
{% if timesheet.id is not empty %}
{% if not timesheet.end and is_granted('stop', timesheet) %}
{% set actions = actions|merge({'stop': path('admin_timesheet_stop', {'id' : timesheet.id})}) %}
{% endif %}
{% if timesheet.end and is_granted('start', timesheet) %}
{% set actions = actions|merge({'repeat': path('timesheet_start', {'id' : timesheet.id})}) %}
{% endif %}
{% if is_granted('edit', timesheet) %}
{% set class = '' %}
{% if view != 'edit' %}
@@ -258,10 +285,6 @@
{% set actions = actions|merge({'edit': {'url': path('admin_timesheet_edit', {'id': timesheet.id}), 'class': class}}) %}
{% endif %}
{% if not timesheet.end and is_granted('stop', timesheet) %}
{% set actions = actions|merge({'stop': path('admin_timesheet_stop', {'id' : timesheet.id})}) %}
{% endif %}
{% if view == 'index' and is_granted('delete', timesheet) %}
{% set actions = actions|merge({'trash': {'url': path('admin_timesheet_delete', {'id' : timesheet.id}), 'class': 'modal-ajax-form'}}) %}
{% endif %}

View File

@@ -46,6 +46,18 @@
<source>home</source>
<target>Homepage</target>
</trans-unit>
<trans-unit id="create-project">
<source>create-project</source>
<target>Projekt erstellen</target>
</trans-unit>
<trans-unit id="create-activity">
<source>create-activity</source>
<target>Tätigkeit erstellen</target>
</trans-unit>
<trans-unit id="create-timesheet">
<source>create-timesheet</source>
<target>Zeit erfassen</target>
</trans-unit>
</body>
</file>
</xliff>

View File

@@ -46,6 +46,18 @@
<source>home</source>
<target>Homepage</target>
</trans-unit>
<trans-unit id="create-project">
<source>create-project</source>
<target>Create project</target>
</trans-unit>
<trans-unit id="create-activity">
<source>create-activity</source>
<target>Create activity</target>
</trans-unit>
<trans-unit id="create-timesheet">
<source>create-timesheet</source>
<target>Create timesheet</target>
</trans-unit>
</body>
</file>
</xliff>