mirror of
				https://github.com/kevinveenbirkenbach/infinito.git
				synced 2025-10-31 09:19:08 +00:00 
			
		
		
		
	Implemented view for node
This commit is contained in:
		
							
								
								
									
										43
									
								
								application/src/Controller/NodeController.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										43
									
								
								application/src/Controller/NodeController.php
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,43 @@ | ||||
| <?php | ||||
|  | ||||
| namespace App\Controller; | ||||
|  | ||||
| use FOS\RestBundle\Controller\FOSRestController; | ||||
| use Symfony\Component\HttpFoundation\Request; | ||||
| use Symfony\Component\HttpFoundation\Response; | ||||
| use Symfony\Component\Routing\Annotation\Route; | ||||
| use App\Entity\NodeInterface; | ||||
| use App\Entity\Node; | ||||
|  | ||||
| /** | ||||
|  * @todo IMPLEMENT SECURITY! | ||||
|  * | ||||
|  * @author kevinfrantz | ||||
|  */ | ||||
| class NodeController extends FOSRestController | ||||
| { | ||||
|     /** | ||||
|      * @Route("/node/{id}.{_format}", defaults={"_format"="html"}) | ||||
|      */ | ||||
|     public function show(Request $request, int $id): Response | ||||
|     { | ||||
|         $node = $this->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; | ||||
|     } | ||||
| } | ||||
| @@ -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() | ||||
|   | ||||
| @@ -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 | ||||
| { | ||||
|   | ||||
| @@ -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 | ||||
|   | ||||
							
								
								
									
										6
									
								
								application/templates/node/node.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								application/templates/node/node.html.twig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,6 @@ | ||||
| {% extends "frames/default.html.twig" %} | ||||
| {% block title %} | ||||
| 	{% trans %} | ||||
| 	Node | ||||
| 	{% endtrans %} | ||||
| {% endblock %} | ||||
							
								
								
									
										13
									
								
								application/templates/node/structure/_list.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								application/templates/node/structure/_list.html.twig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | ||||
| {% if nodeList.isEmpty %} | ||||
| {% trans %} | ||||
| This list doesn't contain elements. | ||||
| {% endtrans %} | ||||
| {% else %} | ||||
| <ul> | ||||
| 	{% for node in nodeList %} | ||||
| 	<li><a href="{{ path('app_node_show',{'id':node.id}) }}" class=" nav-link"> <i | ||||
| 			class="fas fa-globe"></i> {% trans %}Node{% endtrans %} {{ node.id }} | ||||
| 	</a></li> | ||||
| 	{% endfor %} | ||||
| </ul> | ||||
| {% endif %} | ||||
							
								
								
									
										34
									
								
								application/templates/node/view/standard.html.twig
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										34
									
								
								application/templates/node/view/standard.html.twig
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,34 @@ | ||||
| {% extends "node/node.html.twig" %} | ||||
| {% block content %} | ||||
| <h1> | ||||
| 	{% trans %} | ||||
| 	Node | ||||
| 	{% endtrans %} | ||||
| 	# | ||||
| 	{{ node.id }} | ||||
| </h1> | ||||
| {% trans %} | ||||
| Manages | ||||
| {% endtrans %} | ||||
| <a href="{{ path('app_source_show',{'id':node.source.id})}}"> {% trans with {'%node.source.id%':node.source.id}%} | ||||
| 	source #%node.source.id% {% endtrans %} | ||||
| </a> | ||||
| . | ||||
| <h2> | ||||
| 	{% trans %} | ||||
| 	Relatives | ||||
| 	{% endtrans %} | ||||
| </h2> | ||||
| <h3> | ||||
| 	{% trans %} | ||||
| 	First Generation Parents | ||||
| 	{% endtrans %} | ||||
| </h3> | ||||
| {% include "node/structure/_list.html.twig" with {'nodeList':node.parents}%} | ||||
| <h3> | ||||
| 	{% trans %} | ||||
| 	First Generation Childs | ||||
| 	{% endtrans %} | ||||
| </h3> | ||||
| {% include "node/structure/_list.html.twig" with {'nodeList':node.childs}%} | ||||
| {% endblock %} | ||||
		Reference in New Issue
	
	Block a user