change offering to offer in frontend

This commit is contained in:
Jannis Portmann 2021-05-05 22:11:24 +02:00
parent 845c3880f4
commit c3e56756cb
8 changed files with 55 additions and 55 deletions

View file

@ -22,4 +22,4 @@ Searching with filters such as:
| Name | `string` | textfield | | Name | `string` | textfield |
| Category | `Category` | dropdown | | Category | `Category` | dropdown |
Distance from entered ZIP to the offering ZIP. Distance from entered ZIP to the offer ZIP.

View file

@ -22,7 +22,7 @@ import "friendly-challenge/widget";
// Dsiplay Filename when uploading // Dsiplay Filename when uploading
document.querySelector('.custom-file-input').addEventListener('change',function(e){ document.querySelector('.custom-file-input').addEventListener('change',function(e){
var fileName = document.getElementById("offering_form_photo").files[0].name; var fileName = document.getElementById("offer_form_photo").files[0].name;
var nextSibling = e.target.nextElementSibling var nextSibling = e.target.nextElementSibling
nextSibling.innerText = fileName nextSibling.innerText = fileName
}) })

View file

@ -6,12 +6,12 @@ $primary: darken(#005035, 20%);
// the ~ allows you to reference things in node_modules // the ~ allows you to reference things in node_modules
@import "~bootstrap/scss/bootstrap"; @import "~bootstrap/scss/bootstrap";
.offering > img { .offer > img {
height: 15rem; height: 15rem;
object-fit: cover; object-fit: cover;
} }
.offering { .offer {
$card-height: 100%; $card-height: 100%;
width: 20rem; width: 20rem;
} }
@ -24,7 +24,7 @@ $primary: darken(#005035, 20%);
float: right; float: right;
} }
.listings-container { .offer-container {
padding-top: 2rem; padding-top: 2rem;
} }

View file

@ -26,25 +26,25 @@ class OfferController extends AbstractController
} }
#[Route('/', name: 'homepage')] #[Route('/', name: 'homepage')]
public function index(Environment $twig, OfferingRepository $offeringRepository): 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', [
'offerings' => $offeringRepository->findAll(), 'offers' => $offerRepository->findAll(),
])); ]));
} }
#[Route('/new', name: 'new_listing')] #[Route('/new', name: 'new_offer')]
public function new_listing(Request $request, string $photoDir): Response public function newOffer(Request $request, string $photoDir): Response
{ {
$offering = new Offering(); $offer = new Offering();
$form = $this->createForm(OfferingFormType::class, $offering); $form = $this->createForm(OfferingFormType::class, $offer);
$user = $this->getUser(); $user = $this->getUser();
$form->handleRequest($request); $form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) { if ($form->isSubmitted() && $form->isValid()) {
$offering->setByUser($user); $offer->setByUser($user);
$offering->setCreatedAt(new \DateTime()); $offer->setCreatedAt(new \DateTime());
if ($photo = $form['photo']->getData()) { if ($photo = $form['photo']->getData()) {
$filename = bin2hex(random_bytes(6)).'.'.$photo->guessExtension(); $filename = bin2hex(random_bytes(6)).'.'.$photo->guessExtension();
@ -53,30 +53,30 @@ class OfferController extends AbstractController
} catch (FileException $e) { } catch (FileException $e) {
// unable to upload the photo, give up // unable to upload the photo, give up
$this->addFlash("error", "There was an error uploading the photo: ".$e); $this->addFlash("error", "There was an error uploading the photo: ".$e);
return $this->redirectToRoute('new_listing'); return $this->redirectToRoute('new_offer');
} }
$offering->setPhotoFilename($filename); $offer->setPhotoFilename($filename);
} }
$this->entityManager->persist($offering); $this->entityManager->persist($offer);
$this->entityManager->flush(); $this->entityManager->flush();
$this->addFlash("success", "Successfully added the new offering!"); $this->addFlash("success", "Successfully added the new offer!");
return $this->redirectToRoute('homepage'); return $this->redirectToRoute('homepage');
} }
return $this->render('app/new_listing.html.twig', [ return $this->render('app/new_offer.html.twig', [
'user' => $this->getUser(), 'user' => $this->getUser(),
'offering_form' => $form->createView(), 'offer_form' => $form->createView(),
]); ]);
} }
#[Route('/offer/{id}', name: 'show_offer')] #[Route('/offer/{id}', name: 'show_offer')]
public function show_offer(Offering $offering, 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', [
'offer' => $offering, 'offer' => $offer,
'wishes' => $wishRepository->findByUser($offering->getByUser()), 'wishes' => $wishRepository->findByUser($offer->getByUser()),
]); ]);
} }
} }

View file

@ -9,27 +9,27 @@
{% endfor %} {% endfor %}
<h1>Offers</h1> <h1>Offers</h1>
{% if offerings|length > 0 %} {% if offers|length > 0 %}
<div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap"> <div class="card-deck d-flex justify-content-around justify-content-sm-around justify-content-md-between flex-wrap">
{% for offering in offerings %} {% for offer in offers %}
<a href="./offer/{{ offering.id }}" class="mb-5"> <a href="./offer/{{ offer.id }}" class="mb-5">
<div class="card offering h-100"> <div class="card offer h-100">
{% if offering.photoFilename %} {% if offer.photoFilename %}
<img class="card-img-top" src="{{ asset('uploads/photos/' ~ offering.photofilename) }}" /> <img class="card-img-top" src="{{ asset('uploads/photos/' ~ offer.photofilename) }}" />
{% endif %} {% endif %}
<div class="card-body"> <div class="card-body">
<h5 class="card-title">{{ offering.title }}</h5> <h5 class="card-title">{{ offer.title }}</h5>
<p class="card-text">{{ offering.description }}</p> <p class="card-text">{{ offer.description }}</p>
</div> </div>
<div class="card-footer"> <div class="card-footer">
<p class="username">{{ offering.byUser }}</p> <p class="username">{{ offer.byUser }}</p>
<p class="zip">{{ offering.zipCode }}</p> <p class="zip">{{ offer.zipCode }}</p>
</div> </div>
</div> </div>
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
{% else %} {% else %}
<div class="alert alert-warning" role="alert">There are currently no active listings.</div> <div class="alert alert-warning" role="alert">There are currently no active offers.</div>
{% endif %} {% endif %}
{% endblock %} {% endblock %}

View file

@ -1,19 +0,0 @@
{% extends 'base.html.twig' %}
{% block body %}
{% for message in app.flashes('error') %}
<div class="alert alert-error" role="alert">
{{ message }}
</div>
{% endfor %}
<h1 class="mb-3">Add new offering</h1>
{{ form_start(offering_form) }}
{{ form_row(offering_form.title) }}
{{ form_row(offering_form.zipCode) }}
{{ form_row(offering_form.description) }}
{{ form_row(offering_form.photo, {
label: 'Choose file'
}) }}
{{ form_end(offering_form) }}
{% endblock %}

View file

@ -0,0 +1,19 @@
{% extends 'base.html.twig' %}
{% block body %}
{% for message in app.flashes('error') %}
<div class="alert alert-error" role="alert">
{{ message }}
</div>
{% endfor %}
<h1 class="mb-3">Add new offer</h1>
{{ form_start(offer_form) }}
{{ form_row(offer_form.title) }}
{{ form_row(offer_form.zipCode) }}
{{ form_row(offer_form.description) }}
{{ form_row(offer_form.photo, {
label: 'Choose file'
}) }}
{{ form_end(offer_form) }}
{% endblock %}

View file

@ -24,19 +24,19 @@
<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') }} ">Listings</a> <a class="nav-link" href=" {{ path('homepage') }} ">Offers</a>
</li> </li>
<li class="nav-item"> <li class="nav-item">
<a class="nav-link" href="{{ path('user_page') }}">User</a> <a class="nav-link" href="{{ path('user_page') }}">User</a>
</li> </li>
<li> <li>
<a class="nav-link" href="{{ path('new_listing') }}">New Offer</a> <a class="nav-link" href="{{ path('new_offer') }}">New Offer</a>
</li> </li>
</ul> </ul>
</div> </div>
</nav> </nav>
<div class="container listings-container"> <div class="container offer-container">
{% block body %}{% endblock %} {% block body %}{% endblock %}
</div> </div>
</body> </body>