change homepage route

This commit is contained in:
Jannis Portmann 2021-05-09 11:20:45 +02:00
parent 19d2bfbcc3
commit d10ef764bc
7 changed files with 80 additions and 64 deletions

View file

@ -29,7 +29,7 @@ class DashboardController extends AbstractDashboardController
public function configureMenuItems(): iterable public function configureMenuItems(): iterable
{ {
yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'homepage'); yield MenuItem::linktoRoute('Back to the website', 'fas fa-arrow-left', 'offers');
yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home'); yield MenuItem::linktoDashboard('Dashboard', 'fa fa-home');
yield MenuItem::linkToCrud('User', 'fas fa-user', User::class); yield MenuItem::linkToCrud('User', 'fas fa-user', User::class);
yield MenuItem::linkToCrud('Offering', 'fas fa-seedling', Offering::class); yield MenuItem::linkToCrud('Offering', 'fas fa-seedling', Offering::class);

View file

@ -19,4 +19,10 @@ class AppController extends AbstractController
{ {
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
} }
#[Route('/', name: 'homepage')]
public function index(Environment $twig, OfferingRepository $offerRepository): Response
{
return new Response($twig->render('app/index.html.twig'));
}
} }

View file

@ -25,7 +25,7 @@ class OfferController extends AbstractController
$this->entityManager = $entityManager; $this->entityManager = $entityManager;
} }
#[Route('/', name: 'homepage')] #[Route('/offers', name: 'offers')]
public function index(Environment $twig, OfferingRepository $offerRepository): Response public function index(Environment $twig, OfferingRepository $offerRepository): Response
{ {
return new Response($twig->render('app/index.html.twig', [ return new Response($twig->render('app/index.html.twig', [
@ -62,7 +62,7 @@ class OfferController extends AbstractController
$this->entityManager->flush(); $this->entityManager->flush();
$this->addFlash("success", "Successfully added the new offer!"); $this->addFlash("success", "Successfully added the new offer!");
return $this->redirectToRoute('homepage'); return $this->redirectToRoute('offers');
} }
return $this->render('app/new_offer.html.twig', [ return $this->render('app/new_offer.html.twig', [
@ -75,6 +75,7 @@ class OfferController extends AbstractController
public function show_offer(Offering $offer, WishRepository $wishRepository): Response public function show_offer(Offering $offer, WishRepository $wishRepository): Response
{ {
return $this->render('app/offer.html.twig', [ return $this->render('app/offer.html.twig', [
'user' => $this->getUser(),
'offer' => $offer, 'offer' => $offer,
'wishes' => $wishRepository->findByUser($offer->getByUser()), 'wishes' => $wishRepository->findByUser($offer->getByUser()),
]); ]);

View file

@ -1,35 +1,20 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}Hello OfferController!{% endblock %}
{% block body %} {% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
{% for message in app.flashes('success') %} <div class="example-wrapper">
<div class="alert alert-success" role="alert"> <h1>Hello! ✅</h1>
{{ message }}
</div>
{% endfor %}
<h1>Offers</h1> This friendly message is coming from:
{% if offers|length > 0 %} <ul>
<div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap"> <li>Your controller at <code><a href="{{ '/home/thisfro/repos/plant-exchange/src/Controller/OfferController.php'|file_link(0) }}">src/Controller/OfferController.php</a></code></li>
{% for offer in offers %} <li>Your template at <code><a href="{{ '/home/thisfro/repos/plant-exchange/templates/offer/index.html.twig'|file_link(0) }}">templates/offer/index.html.twig</a></code></li>
<a href="./offer/{{ offer.id }}" class="mb-5"> </ul>
<div class="card offer h-100"> </div>
{% if offer.photoFilename %}
<img class="card-img-top" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
{% endif %}
<div class="card-body">
<h5 class="card-title">{{ offer.title }}</h5>
<p class="card-text">{{ offer.description }}</p>
</div>
<div class="card-footer offer-footer">
<p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
<p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
</div>
</div>
</a>
{% endfor %}
</div>
{% else %}
<div class="alert alert-warning" role="alert">There are currently no active offers.</div>
{% endif %}
{% endblock %} {% endblock %}

View file

@ -1,6 +1,10 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block body %} {% block body %}
{% if offer.byUser == user %}
<div class="alert alert-info" role="alert">This is your offer!</div>
{% endif %}
<h1 class="mb-3">{{ offer.title }}</h1> <h1 class="mb-3">{{ offer.title }}</h1>
<div class="offer d-flex flex-wrap justify-content-around"> <div class="offer d-flex flex-wrap justify-content-around">
@ -11,24 +15,29 @@
<h3>Description</h3> <h3>Description</h3>
<p>{{ offer.description }}</p> <p>{{ offer.description }}</p>
<h3>From</h3> <h3>From</h3>
<p>{{ offer.byUser }} in {{ offer.zipCode }}</p> <p>{% if offer.byUser == user %}Me{% else %}{{ offer.byUser }}{% endif %} in {{ offer.zipCode }}</p>
</div> </div>
</div> </div>
<h3>Wishes</h3> {% if offer.byUser == user %}
<p>{{ offer.byUser }} would like some of the following in return:</p> <a href="#" class="btn btn-info"><i class="fas fa-pen"></i></a>
<div class="mb-3"> <a href="#" class="btn btn-danger"><i class="fas fa-trash-alt"></i></a>
{% if wishes == [] %} {% else %}
<div class="alert alert-warning" role="alert"> <h3>Wishes</h3>
There are currently no wishes! <p>{{ offer.byUser }} would like some of the following in return:</p>
<div class="mb-3">
{% if wishes == [] %}
<div class="alert alert-warning" role="alert">
There are currently no wishes!
</div>
{% else %}
<ul class="list-group">
{% for wish in wishes %}
<li class="list-group-item"> {{ wish.title }}</li>
{% endfor %}
</ul>
{% endif %}
</div> </div>
{% else %} <button class="btn btn-primary">Offer trade</button>
<ul class="list-group">
{% for wish in wishes %}
<li class="list-group-item"> {{ wish.title }}</li>
{% endfor %}
</ul>
{% endif %} {% endif %}
</div>
<button class="btn btn-primary">Offer trade</button>
{% endblock %} {% endblock %}

View file

@ -40,7 +40,7 @@
<div class="collapse navbar-collapse" id="navbarSupportedContent"> <div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto"> <ul class="navbar-nav mr-auto">
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href=" {{ path('homepage') }} "><i class="fas fa-seedling"></i> Offers</a> <a class="nav-link" href=" {{ path('offers') }} "><i class="fas fa-seedling"></i> Offers</a>
</li> </li>
<li class="nav-item dropdown"> <li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" data-toggle="dropdown"role="button" aria-haspopup="true" aria-expanded="false"><i class="fas fa-user"></i> User</a> <a class="nav-link dropdown-toggle" data-toggle="dropdown"role="button" aria-haspopup="true" aria-expanded="false"><i class="fas fa-user"></i> User</a>

View file

@ -1,20 +1,35 @@
{% extends 'base.html.twig' %} {% extends 'base.html.twig' %}
{% block title %}Hello OfferController!{% endblock %}
{% block body %} {% block body %}
<style>
.example-wrapper { margin: 1em auto; max-width: 800px; width: 95%; font: 18px/1.5 sans-serif; }
.example-wrapper code { background: #F5F5F5; padding: 2px 6px; }
</style>
<div class="example-wrapper"> {% for message in app.flashes('success') %}
<h1>Hello {{ controller_name }}! ✅</h1> <div class="alert alert-success" role="alert">
{{ message }}
</div>
{% endfor %}
This friendly message is coming from: <h1>Offers</h1>
<ul> {% if offers|length > 0 %}
<li>Your controller at <code><a href="{{ '/home/thisfro/repos/plant-exchange/src/Controller/OfferController.php'|file_link(0) }}">src/Controller/OfferController.php</a></code></li> <div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap">
<li>Your template at <code><a href="{{ '/home/thisfro/repos/plant-exchange/templates/offer/index.html.twig'|file_link(0) }}">templates/offer/index.html.twig</a></code></li> {% for offer in offers %}
</ul> <a href="{{ path('show_offer', {'id': offer.id}) }}" class="mb-5">
</div> <div class="card offer h-100">
{% if offer.photoFilename %}
<img class="card-img-top" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
{% endif %}
<div class="card-body">
<h5 class="card-title">{{ offer.title }}</h5>
<p class="card-text">{{ offer.description }}</p>
</div>
<div class="card-footer offer-footer">
<p class="username"><i class="fas fa-user mt-3"></i> {{ offer.byUser }}</p>
<p class="zip"><i class="fas fa-map-marker-alt mt-3"></i> {{ offer.zipCode }}</p>
</div>
</div>
</a>
{% endfor %}
</div>
{% else %}
<div class="alert alert-warning" role="alert">There are currently no active offers.</div>
{% endif %}
{% endblock %} {% endblock %}