diff --git a/assets/css/app.css b/assets/css/app.css index 9ffc6be9..774c6fb8 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -134,7 +134,15 @@ body { line-height: 1.1; } - +/******************************** +* Toasts + ********************************/ +.toast-container { + position: fixed; + top: auto; + z-index: 1; + right: 25px; +} /********************************** * Helper classes diff --git a/src/Controller/DebugController.php b/src/Controller/DebugController.php new file mode 100644 index 00000000..c7f69d5f --- /dev/null +++ b/src/Controller/DebugController.php @@ -0,0 +1,58 @@ +addFlash('success', 'Success Flash Message!'); + $this->addFlash('error', 'Error Flash Message!'); + $this->addFlash('warning', 'Warning Flash Message!'); + $this->addFlash('notice', 'Notice Flash Message!'); + $this->addFlash('info', 'Info Flash Message! Test'); + + $this->addFlash('testkjfd', 'Blabla. This message type should be not know to template!'); + + return $this->render("base.html.twig"); + } +} \ No newline at end of file diff --git a/src/Controller/PartController.php b/src/Controller/PartController.php index 15dcbcc6..926d3722 100644 --- a/src/Controller/PartController.php +++ b/src/Controller/PartController.php @@ -42,6 +42,7 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; +use Symfony\Contracts\Translation\TranslatorInterface; class PartController extends AbstractController { @@ -89,14 +90,12 @@ class PartController extends AbstractController * * @return \Symfony\Component\HttpFoundation\Response */ - public function new(Request $request, EntityManagerInterface $em) + public function new(Request $request, EntityManagerInterface $em, TranslatorInterface $translator) { $new_part = new Part(); $category = $em->find(Category::class, 1); $new_part->setCategory($category); - $this->addFlash('success', 'Article Created!'); - $form = $this->createForm(PartType::class, $new_part); $form->handleRequest($request); @@ -106,7 +105,7 @@ class PartController extends AbstractController //$part = $form->getData(); $em->persist($new_part); $em->flush(); - $this->addFlash('success', 'Article Created! Knowledge is power!'); + $this->addFlash('success', $translator->trans('part.created_flash')); return $this->redirectToRoute('part_edit',['id' => $new_part->getID()]); } diff --git a/templates/base.html.twig b/templates/base.html.twig index 02cdbdb0..d9baa0b9 100644 --- a/templates/base.html.twig +++ b/templates/base.html.twig @@ -101,11 +101,42 @@ + + +
+ {% for label, messages in app.flashes() %} + {% for message in messages %} + {% set flash_title = label|replace({'success': 'flash.success', 'error': 'flash.error' + , 'warning': 'flash.warning', 'notice': 'flash.notice', 'info': 'flash.info'}) %} + {% set flash_symbol = label|replace({'success': 'fa-check-circle', 'error': 'fa-exclamation-triangle' + , 'warning': 'fa-exclamation-circle', 'notice': 'fa-flag', 'info': 'fa-flag'}) %} + + {% set flash_bg = label|replace({'success': 'bg-success text-white', + 'error': 'bg-danger text-white', 'warning': 'bg-warning text-white', + 'notice': 'bg-info text-white', 'info': 'bg'})%} + + + {% endfor %} + {% endfor %} +
+
-