Notifications by SweetAlert2 (#1508)

This commit is contained in:
Kevin Papst
2020-10-02 19:37:30 +02:00
committed by GitHub
parent 0aa6baea2f
commit 825e492891
21 changed files with 161 additions and 62 deletions

View File

@@ -41,6 +41,7 @@ class AboutController extends AbstractController
try {
$license = file_get_contents($filename);
} catch (\Exception $ex) {
$this->logException($ex);
$license = false;
}

View File

@@ -79,6 +79,44 @@ abstract class AbstractController extends BaseAbstractController implements Serv
$this->addFlashTranslated('error', $translationKey, $parameter);
}
/**
* Adds an exception flash message for failed update/create actions.
*
* @param \Exception $exception
*/
protected function flashUpdateException(\Exception $exception)
{
$this->flashException($exception, 'action.update.error');
}
/**
* Adds an exception flash message for failed delete actions.
*
* @param \Exception $exception
*/
protected function flashDeleteException(\Exception $exception)
{
$this->flashException($exception, 'action.delete.error');
}
/**
* Adds a "error" flash message and logs the Exception.
*
* @param \Exception $exception
* @param string $translationKey
* @param array $parameter
*/
protected function flashException(\Exception $exception, string $translationKey, array $parameter = [])
{
$this->logException($exception);
if (!\array_key_exists('%reason%', $parameter)) {
$parameter['%reason%'] = $exception->getMessage();
}
$this->addFlashTranslated('error', $translationKey, $parameter);
}
/**
* Adds a fully translated (both $message and all keys in $parameter) flash message to the stack.
*

View File

@@ -170,7 +170,7 @@ final class ActivityController extends AbstractController
return $this->redirectToRoute('activity_details', ['id' => $activity->getId()]);
} catch (Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -215,7 +215,7 @@ final class ActivityController extends AbstractController
return $this->redirectToRoute('admin_activity');
} catch (Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -246,7 +246,7 @@ final class ActivityController extends AbstractController
try {
$teamRepository->saveTeam($defaultTeam);
} catch (Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('activity_details', ['id' => $activity->getId()]);
@@ -298,7 +298,7 @@ final class ActivityController extends AbstractController
$this->repository->deleteActivity($activity, $deleteForm->get('activity')->getData());
$this->flashSuccess('action.delete.success');
} catch (Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_activity');
@@ -370,7 +370,7 @@ final class ActivityController extends AbstractController
return $this->redirectToRoute('admin_activity');
}
} catch (Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}

View File

@@ -144,7 +144,7 @@ final class CustomerController extends AbstractController
return $this->redirectToRoute('admin_customer');
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -165,7 +165,7 @@ final class CustomerController extends AbstractController
try {
$this->repository->deleteComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('customer_details', ['id' => $customerId]);
@@ -186,7 +186,7 @@ final class CustomerController extends AbstractController
try {
$this->repository->saveComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -203,7 +203,7 @@ final class CustomerController extends AbstractController
try {
$this->repository->saveComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('customer_details', ['id' => $comment->getCustomer()->getId()]);
@@ -230,7 +230,7 @@ final class CustomerController extends AbstractController
try {
$teamRepository->saveTeam($defaultTeam);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
@@ -340,7 +340,7 @@ final class CustomerController extends AbstractController
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -396,7 +396,7 @@ final class CustomerController extends AbstractController
$this->repository->deleteCustomer($customer, $deleteForm->get('customer')->getData());
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_customer');
@@ -455,7 +455,7 @@ final class CustomerController extends AbstractController
return $this->redirectToRoute('customer_details', ['id' => $customer->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}

View File

@@ -56,7 +56,8 @@ class HomepageController extends AbstractController
$language = $routeSettings[1];
try {
return $this->redirectToRoute($route, ['_locale' => $language]);
} catch (\Exception $exception) {
} catch (\Exception $ex) {
$this->logException($ex);
// something is wrong with the url parameters ...
}
}

View File

@@ -169,7 +169,7 @@ final class InvoiceController extends AbstractController
return $this->file($file->getRealPath(), $file->getBasename());
} catch (Exception $ex) {
$this->flashError($ex->getMessage());
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('invoice');
@@ -185,7 +185,7 @@ final class InvoiceController extends AbstractController
$this->service->changeInvoiceStatus($invoice, $status);
$this->flashSuccess('action.update.success');
} catch (Exception $ex) {
$this->flashError('action.update.error');
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_invoice_list');
@@ -201,7 +201,7 @@ final class InvoiceController extends AbstractController
$this->service->deleteInvoice($invoice);
$this->flashSuccess('action.delete.success');
} catch (Exception $ex) {
$this->flashError('action.delete.error');
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_invoice_list');
@@ -324,10 +324,8 @@ final class InvoiceController extends AbstractController
$this->flashSuccess('action.update.success');
return $this->redirectToRoute('admin_invoice_document_upload');
} catch (Exception $e) {
$this->flashError(
sprintf('Failed uploading invoice document: %e', $e->getMessage())
);
} catch (Exception $ex) {
$this->flashException($ex, 'action.upload.error');
}
}
}
@@ -370,7 +368,7 @@ final class InvoiceController extends AbstractController
$this->templateRepository->removeTemplate($template);
$this->flashSuccess('action.delete.success');
} catch (Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_invoice_template');
@@ -389,7 +387,7 @@ final class InvoiceController extends AbstractController
return $this->redirectToRoute('admin_invoice_template');
} catch (Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}

View File

@@ -185,7 +185,7 @@ final class PermissionController extends AbstractController
$this->roleRepository->saveRole($role);
$this->flashSuccess('action.update.success');
} catch (\Exception $ex) {
$this->flashSuccess('action.update.error');
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_user_permissions');
@@ -214,7 +214,7 @@ final class PermissionController extends AbstractController
$this->roleRepository->deleteRole($role);
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashError('action.delete.error');
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_user_permissions');
@@ -246,7 +246,7 @@ final class PermissionController extends AbstractController
$rolePermissionRepository->saveRolePermission($permission);
$this->flashSuccess('action.update.success');
} catch (\Exception $ex) {
$this->flashError('action.update.error');
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_user_permissions');

View File

@@ -134,7 +134,7 @@ final class ProjectController extends AbstractController
return $this->redirectToRoute('admin_project');
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -171,7 +171,7 @@ final class ProjectController extends AbstractController
try {
$this->repository->deleteComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('project_details', ['id' => $projectId]);
@@ -192,7 +192,7 @@ final class ProjectController extends AbstractController
try {
$this->repository->saveComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -209,7 +209,7 @@ final class ProjectController extends AbstractController
try {
$this->repository->saveComment($comment);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('project_details', ['id' => $comment->getProject()->getId()]);
@@ -236,7 +236,7 @@ final class ProjectController extends AbstractController
try {
$teamRepository->saveTeam($defaultTeam);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
@@ -340,7 +340,7 @@ final class ProjectController extends AbstractController
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -408,7 +408,7 @@ final class ProjectController extends AbstractController
$this->repository->deleteProject($project, $deleteForm->get('project')->getData());
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
return $this->redirectToRoute('admin_project');
@@ -474,7 +474,7 @@ final class ProjectController extends AbstractController
return $this->redirectToRoute('project_details', ['id' => $project->getId()]);
}
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}

View File

@@ -144,7 +144,7 @@ final class SystemConfigurationController extends AbstractController
$this->repository->saveSystemConfiguration($form->getData());
$this->flashSuccess('action.update.success');
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('system_configuration');

View File

@@ -16,7 +16,6 @@ use App\Form\TagEditForm;
use App\Form\Toolbar\TagToolbarForm;
use App\Repository\Query\TagQuery;
use App\Repository\TagRepository;
use Doctrine\ORM\ORMException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Symfony\Component\Form\FormInterface;
use Symfony\Component\HttpFoundation\Request;
@@ -80,8 +79,8 @@ class TagController extends AbstractController
$this->flashSuccess('action.update.success');
return $this->redirectToRoute('tags');
} catch (ORMException $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
}
@@ -112,8 +111,8 @@ class TagController extends AbstractController
$this->flashSuccess('action.update.success');
return $this->redirectToRoute('tags');
} catch (ORMException $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
} catch (\Exception $ex) {
$this->flashUpdateException($ex);
}
}
@@ -139,7 +138,7 @@ class TagController extends AbstractController
$repository->multiDelete($dto->getEntities());
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
}

View File

@@ -113,7 +113,7 @@ final class TeamController extends AbstractController
return $this->redirectToRoute('admin_team_edit', ['id' => $newTeam->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
return $this->redirectToRoute('admin_team');
@@ -152,7 +152,7 @@ final class TeamController extends AbstractController
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -192,7 +192,7 @@ final class TeamController extends AbstractController
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
}
@@ -212,7 +212,7 @@ final class TeamController extends AbstractController
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
}
@@ -231,7 +231,7 @@ final class TeamController extends AbstractController
return $this->redirectToRoute('admin_team_edit', ['id' => $team->getId()]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
}

View File

@@ -152,7 +152,7 @@ abstract class TimesheetAbstractController extends AbstractController
return $this->redirectToRoute($this->getTimesheetRoute(), ['page' => $request->get('page', 1)]);
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -213,7 +213,7 @@ abstract class TimesheetAbstractController extends AbstractController
return $this->redirectToRoute($this->getTimesheetRoute());
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
@@ -351,7 +351,7 @@ abstract class TimesheetAbstractController extends AbstractController
return $this->redirectToRoute($this->getTimesheetRoute());
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}
}
@@ -383,7 +383,7 @@ abstract class TimesheetAbstractController extends AbstractController
$this->service->deleteMultipleTimesheets($dto->getEntities());
$this->flashSuccess('action.delete.success');
} catch (\Exception $ex) {
$this->flashError('action.delete.error', ['%reason%' => $ex->getMessage()]);
$this->flashDeleteException($ex);
}
}

View File

@@ -140,7 +140,7 @@ class TimesheetTeamController extends TimesheetAbstractController
return $this->redirectToRoute($this->getTimesheetRoute());
} catch (\Exception $ex) {
$this->flashError('action.update.error', ['%reason%' => $ex->getMessage()]);
$this->flashUpdateException($ex);
}
}