From ee1cef71b7c16309fb04c7eaee59e21a3ae9cc07 Mon Sep 17 00:00:00 2001 From: Kevin Frantz Date: Thu, 20 Sep 2018 16:03:00 +0200 Subject: [PATCH] Implemented view for node --- application/src/Controller/NodeController.php | 43 +++++++++++++++++++ .../src/Controller/SourceController.php | 11 +++++ application/src/Entity/Node.php | 2 +- .../src/Subscriber/SourceMenuSubscriber.php | 9 ++++ application/templates/node/node.html.twig | 6 +++ .../templates/node/structure/_list.html.twig | 13 ++++++ .../templates/node/view/standard.html.twig | 34 +++++++++++++++ 7 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 application/src/Controller/NodeController.php create mode 100644 application/templates/node/node.html.twig create mode 100644 application/templates/node/structure/_list.html.twig create mode 100644 application/templates/node/view/standard.html.twig diff --git a/application/src/Controller/NodeController.php b/application/src/Controller/NodeController.php new file mode 100644 index 0000000..2a5b634 --- /dev/null +++ b/application/src/Controller/NodeController.php @@ -0,0 +1,43 @@ +loadSource($request, $id); + $view = $this->view($node, 200) + ->setTemplate('node/view/standard.html.twig') + ->setTemplateVar('node'); + + return $this->handleView($view); + } + + private function loadSource(Request $request, int $id): NodeInterface + { + $node = $this->getDoctrine() + ->getRepository(Node::class) + ->find($id); + if (!$node) { + throw $this->createNotFoundException('No node found for id '.$id); + } + + return $node; + } +} diff --git a/application/src/Controller/SourceController.php b/application/src/Controller/SourceController.php index e0477c9..86e265a 100644 --- a/application/src/Controller/SourceController.php +++ b/application/src/Controller/SourceController.php @@ -11,6 +11,7 @@ use FOS\RestBundle\Controller\FOSRestController; use App\Entity\SourceInterface; use App\Creator\Factory\Template\Source\SourceTemplateFormFactory; use App\Creator\Factory\Form\Source\SourceFormFactory; +use Symfony\Component\HttpFoundation\RedirectResponse; /** * @todo IMPLEMENT SECURITY! @@ -50,6 +51,16 @@ class SourceController extends FOSRestController ]); } + /** + * @Route("/source/{id}/node.{_format}", defaults={"_format"="html"}) + */ + public function node(Request $request, int $id): RedirectResponse + { + $source = $this->loadSource($request, $id); + + return $this->redirectToRoute('app_node_show', ['id' => $source->getNode()->getId()]); + } + private function loadSource(Request $request, int $id): SourceInterface { $source = $this->getDoctrine() diff --git a/application/src/Entity/Node.php b/application/src/Entity/Node.php index 44b215a..d755a38 100644 --- a/application/src/Entity/Node.php +++ b/application/src/Entity/Node.php @@ -12,7 +12,7 @@ use App\Entity\Attribut\LawAttribut; /** * @author kevinfrantz * @ORM\Table(name="node") - * @ORM\Entity(repositoryClass="App\Repository\NodeRepository") + * @ORM\Entity() */ class Node extends AbstractEntity implements NodeInterface { diff --git a/application/src/Subscriber/SourceMenuSubscriber.php b/application/src/Subscriber/SourceMenuSubscriber.php index 345e654..40466b5 100644 --- a/application/src/Subscriber/SourceMenuSubscriber.php +++ b/application/src/Subscriber/SourceMenuSubscriber.php @@ -39,6 +39,15 @@ class SourceMenuSubscriber implements EventSubscriberInterface ], ]); $this->generateSourceFormatDropdown($menu, $event); + $menu->addChild($this->translator->trans('node'), [ + 'route' => 'app_source_node', + 'routeParameters' => [ + 'id' => $event->getRequest()->getCurrentRequest()->attributes->get('id'), + ], + 'attributes' => [ + 'icon' => 'fas fa-globe', + ], + ]); } private function generateSourceFormatDropdown(ItemInterface $menu, SourceMenuEvent $event): void diff --git a/application/templates/node/node.html.twig b/application/templates/node/node.html.twig new file mode 100644 index 0000000..e1d49a7 --- /dev/null +++ b/application/templates/node/node.html.twig @@ -0,0 +1,6 @@ +{% extends "frames/default.html.twig" %} +{% block title %} + {% trans %} + Node + {% endtrans %} +{% endblock %} \ No newline at end of file diff --git a/application/templates/node/structure/_list.html.twig b/application/templates/node/structure/_list.html.twig new file mode 100644 index 0000000..8f75ea5 --- /dev/null +++ b/application/templates/node/structure/_list.html.twig @@ -0,0 +1,13 @@ +{% if nodeList.isEmpty %} +{% trans %} +This list doesn't contain elements. +{% endtrans %} +{% else %} + +{% endif %} \ No newline at end of file diff --git a/application/templates/node/view/standard.html.twig b/application/templates/node/view/standard.html.twig new file mode 100644 index 0000000..a8d440d --- /dev/null +++ b/application/templates/node/view/standard.html.twig @@ -0,0 +1,34 @@ +{% extends "node/node.html.twig" %} +{% block content %} +

+ {% trans %} + Node + {% endtrans %} + # + {{ node.id }} +

+{% trans %} +Manages +{% endtrans %} + {% trans with {'%node.source.id%':node.source.id}%} + source #%node.source.id% {% endtrans %} + +. +

+ {% trans %} + Relatives + {% endtrans %} +

+

+ {% trans %} + First Generation Parents + {% endtrans %} +

+{% include "node/structure/_list.html.twig" with {'nodeList':node.parents}%} +

+ {% trans %} + First Generation Childs + {% endtrans %} +

+{% include "node/structure/_list.html.twig" with {'nodeList':node.childs}%} +{% endblock %}