use dialog to duplicate timesheet (#2567)
* fix: display time budget in customer listing if set * updated api methods with annotations * do not require checkboxes for system configurations * open dialog for duplicated timesheets
This commit is contained in:
@@ -13,6 +13,8 @@ use App\Configuration\SystemConfiguration;
|
||||
use App\Entity\MetaTableTypeInterface;
|
||||
use App\Entity\Tag;
|
||||
use App\Entity\Timesheet;
|
||||
use App\Event\TimesheetDuplicatePostEvent;
|
||||
use App\Event\TimesheetDuplicatePreEvent;
|
||||
use App\Event\TimesheetMetaDefinitionEvent;
|
||||
use App\Event\TimesheetMetaDisplayEvent;
|
||||
use App\Export\ServiceExport;
|
||||
@@ -208,6 +210,32 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function duplicate(Timesheet $timesheet, Request $request, string $renderTemplate): Response
|
||||
{
|
||||
$copyTimesheet = clone $timesheet;
|
||||
|
||||
$form = $this->getDuplicateForm($timesheet);
|
||||
$form->handleRequest($request);
|
||||
|
||||
if ($form->isSubmitted() && $form->isValid()) {
|
||||
try {
|
||||
$this->dispatcher->dispatch(new TimesheetDuplicatePreEvent($copyTimesheet, $timesheet));
|
||||
$this->service->saveNewTimesheet($copyTimesheet);
|
||||
$this->dispatcher->dispatch(new TimesheetDuplicatePostEvent($copyTimesheet, $timesheet));
|
||||
$this->flashSuccess('action.update.success');
|
||||
|
||||
return $this->redirectToRoute($this->getTimesheetRoute());
|
||||
} catch (\Exception $ex) {
|
||||
$this->flashUpdateException($ex);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->render($renderTemplate, [
|
||||
'timesheet' => $copyTimesheet,
|
||||
'form' => $form->createView(),
|
||||
]);
|
||||
}
|
||||
|
||||
protected function export(Request $request, string $exporterId): Response
|
||||
{
|
||||
$query = new TimesheetQuery();
|
||||
@@ -425,12 +453,12 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
]);
|
||||
}
|
||||
|
||||
protected function getCreateForm(Timesheet $entry): FormInterface
|
||||
protected function generateCreateForm(Timesheet $entry, string $formClass, string $action): FormInterface
|
||||
{
|
||||
$mode = $this->getTrackingMode();
|
||||
|
||||
return $this->createForm($this->getCreateFormClassName(), $entry, [
|
||||
'action' => $this->generateUrl($this->getCreateRoute()),
|
||||
return $this->createForm($formClass, $entry, [
|
||||
'action' => $action,
|
||||
'include_rate' => $this->isGranted('edit_rate', $entry),
|
||||
'include_exported' => $this->isGranted('edit_export', $entry),
|
||||
'include_user' => $this->includeUserInForms('create'),
|
||||
@@ -495,11 +523,6 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return 'edit_rate_own_timesheet';
|
||||
}
|
||||
|
||||
protected function getCreateFormClassName(): string
|
||||
{
|
||||
return TimesheetEditForm::class;
|
||||
}
|
||||
|
||||
protected function getEditFormClassName(): string
|
||||
{
|
||||
return TimesheetEditForm::class;
|
||||
@@ -525,11 +548,6 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
return 'timesheet_edit';
|
||||
}
|
||||
|
||||
protected function getCreateRoute(): string
|
||||
{
|
||||
return 'timesheet_create';
|
||||
}
|
||||
|
||||
protected function getMultiUpdateRoute(): string
|
||||
{
|
||||
return 'timesheet_multi_update';
|
||||
@@ -544,4 +562,8 @@ abstract class TimesheetAbstractController extends AbstractController
|
||||
{
|
||||
return $this->getTrackingMode()->canSeeBeginAndEndTimes();
|
||||
}
|
||||
|
||||
abstract protected function getDuplicateForm(Timesheet $entry): FormInterface;
|
||||
|
||||
abstract protected function getCreateForm(Timesheet $entry): FormInterface;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user