pre-populate tags for new timesheet records via request params (#930)
This commit is contained in:
@@ -165,7 +165,7 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
* @param ActivityRepository $activityRepository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
protected function create(Request $request, string $renderTemplate, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository)
|
||||
{
|
||||
$entry = new Timesheet();
|
||||
$entry->setUser($this->getUser());
|
||||
@@ -181,6 +181,18 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
$entry->setActivity($activity);
|
||||
}
|
||||
|
||||
if ($request->query->get('tags')) {
|
||||
$tagNames = explode(',', $request->query->get('tags'));
|
||||
foreach ($tagNames as $tagName) {
|
||||
$tag = $tagRepository->findOneByName($tagName);
|
||||
if (!$tag) {
|
||||
$tag = new Tag();
|
||||
$tag->setName($tagName);
|
||||
}
|
||||
$entry->addTag($tag);
|
||||
}
|
||||
}
|
||||
|
||||
$event = new TimesheetMetaDefinitionEvent($entry);
|
||||
$this->dispatcher->dispatch(TimesheetMetaDefinitionEvent::class, $event);
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ namespace App\Controller;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TagRepository;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -70,9 +71,9 @@ class TimesheetController extends TimesheetAbstractController
|
||||
* @param ActivityRepository $activityRepository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository)
|
||||
{
|
||||
return $this->create($request, 'timesheet/edit.html.twig', $projectRepository, $activityRepository);
|
||||
return $this->create($request, 'timesheet/edit.html.twig', $projectRepository, $activityRepository, $tagRepository);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\Entity\Timesheet;
|
||||
use App\Form\TimesheetAdminEditForm;
|
||||
use App\Repository\ActivityRepository;
|
||||
use App\Repository\ProjectRepository;
|
||||
use App\Repository\TagRepository;
|
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\Routing\Annotation\Route;
|
||||
@@ -70,9 +71,9 @@ class TimesheetTeamController extends TimesheetAbstractController
|
||||
* @param ActivityRepository $activityRepository
|
||||
* @return \Symfony\Component\HttpFoundation\RedirectResponse|\Symfony\Component\HttpFoundation\Response
|
||||
*/
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository)
|
||||
public function createAction(Request $request, ProjectRepository $projectRepository, ActivityRepository $activityRepository, TagRepository $tagRepository)
|
||||
{
|
||||
return $this->create($request, 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository);
|
||||
return $this->create($request, 'timesheet-team/edit.html.twig', $projectRepository, $activityRepository, $tagRepository);
|
||||
}
|
||||
|
||||
protected function getCreateFormClassName(): string
|
||||
|
||||
@@ -591,6 +591,9 @@
|
||||
"ref": "cda8b550123383d25827705d05a42acf6819fe4e"
|
||||
}
|
||||
},
|
||||
"symfony/security": {
|
||||
"version": "v4.2.8"
|
||||
},
|
||||
"symfony/security-bundle": {
|
||||
"version": "3.3",
|
||||
"recipe": {
|
||||
|
||||
@@ -202,10 +202,10 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getEnd()->format(\DateTime::ATOM));
|
||||
}
|
||||
|
||||
public function testCreateActionWithBeginAndEndValues()
|
||||
public function testCreateActionWithBeginAndEndAndTagValues()
|
||||
{
|
||||
$client = $this->getClientForAuthenticatedUser(User::ROLE_ADMIN);
|
||||
$this->request($client, '/timesheet/create?begin=2018-08-02&end=2018-08-02');
|
||||
$this->request($client, '/timesheet/create?begin=2018-08-02&end=2018-08-02&tags=one,two,three');
|
||||
$this->assertTrue($client->getResponse()->isSuccessful());
|
||||
|
||||
$form = $client->getCrawler()->filter('form[name=timesheet_edit_form]')->form();
|
||||
@@ -234,6 +234,8 @@ class TimesheetControllerTest extends ControllerBaseTest
|
||||
|
||||
$expected = new \DateTime('2018-08-02T18:00:00');
|
||||
$this->assertEquals($expected->format(\DateTime::ATOM), $timesheet->getEnd()->format(\DateTime::ATOM));
|
||||
|
||||
$this->assertEquals(['one', 'two', 'three'], $timesheet->getTagsAsArray());
|
||||
}
|
||||
|
||||
public function testEditAction()
|
||||
|
||||
Reference in New Issue
Block a user