Start on the fridge frontend

Create list overview without styling
Start on editer of fridge
This commit is contained in:
Tim 2022-01-02 01:01:00 +01:00
parent 60577f15fe
commit 725fa47c6d
5 changed files with 85 additions and 2 deletions

View File

@ -0,0 +1,34 @@
<?php
namespace App\Controller;
use App\Entity\Fridge;
use App\Form\FridgeType;
use App\Repository\FridgeRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
#[Route('/fridge', name: 'fridge')]
class FridgeController extends AbstractController
{
#[Route('/list', name: '_list')]
public function list(FridgeRepository $repo)
{
$fridges = $repo->findAll();
return $this->render('fridge/list.html.twig', [
'fridges' => $fridges,
]);
}
#[Route('/single/{fridge}', name: '_single')]
public function single(Fridge $fridge, Request $request)
{
$form = $this->createForm(FridgeType::class, $fridge);
return $this->render('fridge/single.html.twig', [
'form' => $form->createView(),
]);
}
}

29
src/Form/FridgeType.php Normal file
View File

@ -0,0 +1,29 @@
<?php
namespace App\Form;
use App\Entity\Fridge;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class FridgeType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('name')
->add('description')
->add('productLines')
->add('save', SubmitType::class)
;
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => Fridge::class,
]);
}
}

View File

@ -2,7 +2,8 @@
<div class="container-fluid"> <div class="container-fluid">
<i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i> <i class="bi-shop" style="font-size: 2rem; padding-right: 0.5rem; color: white;"></i>
<a class="navbar-brand" href="#">IceCold</a> <a class="navbar-brand" href="#">IceCold</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse" aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation"> <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarCollapse"
aria-controls="navbarCollapse" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span> <span class="navbar-toggler-icon"></span>
</button> </button>
<div class="collapse navbar-collapse" id="navbarCollapse"> <div class="collapse navbar-collapse" id="navbarCollapse">
@ -10,9 +11,15 @@
<li class="nav-item"> <li class="nav-item">
<a class="nav-link active" href="{{ path('home') }}">Home</a> <a class="nav-link active" href="{{ path('home') }}">Home</a>
</li> </li>
<li class="nav-item">
<a class="nav-link" href="{{ path('fridge_list') }}">Fridges</a>
</li>
{% if is_granted('ROLE_ADMIN') %}
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ path('admin') }}">Admin</a> <a class="nav-link" href="{{ path('admin') }}">Admin</a>
</li> </li>
{% endif %}
</ul> </ul>
<ul class="navbar-nav ms-auto mb-2 mb-md-0"> <ul class="navbar-nav ms-auto mb-2 mb-md-0">
{% if is_granted('ROLE_USER') %} {% if is_granted('ROLE_USER') %}

View File

@ -0,0 +1,8 @@
{% extends "base/base.html.twig" %}
{% block body %}
Fridges: <br>
{% for fridge in fridges %}
<a href="{{ path('fridge_single', {'fridge': fridge.id}) }}">{{ fridge.name }}</a> <br>
{% endfor %}
{% endblock %}

View File

@ -0,0 +1,5 @@
{% extends "base/base.html.twig" %}
{% block body %}
{{ form(form) }}
{% endblock %}