change offering to offer in frontend
This commit is contained in:
		
							parent
							
								
									845c3880f4
								
							
						
					
					
						commit
						c3e56756cb
					
				
					 8 changed files with 55 additions and 55 deletions
				
			
		| 
						 | 
				
			
			@ -22,4 +22,4 @@ Searching with filters such as:
 | 
			
		|||
| Name         | `string`      | textfield  |
 | 
			
		||||
| Category     | `Category`    | dropdown   |
 | 
			
		||||
 | 
			
		||||
Distance from entered ZIP to the offering ZIP.
 | 
			
		||||
Distance from entered ZIP to the offer ZIP.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -22,7 +22,7 @@ import "friendly-challenge/widget";
 | 
			
		|||
 | 
			
		||||
// Dsiplay Filename when uploading
 | 
			
		||||
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
 | 
			
		||||
    nextSibling.innerText = fileName
 | 
			
		||||
})
 | 
			
		||||
| 
						 | 
				
			
			@ -6,12 +6,12 @@ $primary: darken(#005035, 20%);
 | 
			
		|||
// the ~ allows you to reference things in node_modules
 | 
			
		||||
@import "~bootstrap/scss/bootstrap";
 | 
			
		||||
 | 
			
		||||
.offering > img {
 | 
			
		||||
.offer > img {
 | 
			
		||||
    height: 15rem;
 | 
			
		||||
    object-fit: cover;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.offering {
 | 
			
		||||
.offer {
 | 
			
		||||
    $card-height: 100%;
 | 
			
		||||
    width: 20rem;
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			@ -24,7 +24,7 @@ $primary: darken(#005035, 20%);
 | 
			
		|||
    float: right;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
.listings-container {
 | 
			
		||||
.offer-container {
 | 
			
		||||
    padding-top: 2rem;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -26,25 +26,25 @@ class OfferController extends AbstractController
 | 
			
		|||
    }
 | 
			
		||||
 | 
			
		||||
    #[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', [
 | 
			
		||||
            'offerings' => $offeringRepository->findAll(),
 | 
			
		||||
            'offers' => $offerRepository->findAll(),
 | 
			
		||||
        ]));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[Route('/new', name: 'new_listing')]
 | 
			
		||||
    public function new_listing(Request $request, string $photoDir): Response
 | 
			
		||||
    #[Route('/new', name: 'new_offer')]
 | 
			
		||||
    public function newOffer(Request $request, string $photoDir): Response
 | 
			
		||||
    {
 | 
			
		||||
        $offering = new Offering();
 | 
			
		||||
        $form = $this->createForm(OfferingFormType::class, $offering);
 | 
			
		||||
        $offer = new Offering();
 | 
			
		||||
        $form = $this->createForm(OfferingFormType::class, $offer);
 | 
			
		||||
        $user = $this->getUser(); 
 | 
			
		||||
 | 
			
		||||
        $form->handleRequest($request);
 | 
			
		||||
 | 
			
		||||
        if ($form->isSubmitted() && $form->isValid()) {
 | 
			
		||||
            $offering->setByUser($user);
 | 
			
		||||
            $offering->setCreatedAt(new \DateTime());
 | 
			
		||||
            $offer->setByUser($user);
 | 
			
		||||
            $offer->setCreatedAt(new \DateTime());
 | 
			
		||||
 | 
			
		||||
            if ($photo = $form['photo']->getData()) {
 | 
			
		||||
                $filename = bin2hex(random_bytes(6)).'.'.$photo->guessExtension();
 | 
			
		||||
| 
						 | 
				
			
			@ -53,30 +53,30 @@ class OfferController extends AbstractController
 | 
			
		|||
                } catch (FileException $e) {
 | 
			
		||||
                    // unable to upload the photo, give up
 | 
			
		||||
                    $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->addFlash("success", "Successfully added the new offering!");
 | 
			
		||||
            $this->addFlash("success", "Successfully added the new offer!");
 | 
			
		||||
            return $this->redirectToRoute('homepage');
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        return $this->render('app/new_listing.html.twig', [
 | 
			
		||||
        return $this->render('app/new_offer.html.twig', [
 | 
			
		||||
            'user' => $this->getUser(),
 | 
			
		||||
            'offering_form' => $form->createView(),
 | 
			
		||||
            'offer_form' => $form->createView(),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    #[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', [
 | 
			
		||||
            'offer' => $offering,
 | 
			
		||||
            'wishes' => $wishRepository->findByUser($offering->getByUser()),
 | 
			
		||||
            'offer' => $offer,
 | 
			
		||||
            'wishes' => $wishRepository->findByUser($offer->getByUser()),
 | 
			
		||||
        ]);
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -9,27 +9,27 @@
 | 
			
		|||
    {% endfor %}
 | 
			
		||||
 | 
			
		||||
    <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">
 | 
			
		||||
            {% for offering in offerings %}
 | 
			
		||||
            <a href="./offer/{{ offering.id }}" class="mb-5">
 | 
			
		||||
                    <div class="card offering h-100">
 | 
			
		||||
                        {% if offering.photoFilename %}
 | 
			
		||||
                            <img class="card-img-top" src="{{ asset('uploads/photos/' ~ offering.photofilename) }}" />
 | 
			
		||||
            {% for offer in offers %}
 | 
			
		||||
            <a href="./offer/{{ offer.id }}" class="mb-5">
 | 
			
		||||
                    <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">{{ offering.title }}</h5>
 | 
			
		||||
                            <p class="card-text">{{ offering.description }}</p>
 | 
			
		||||
                            <h5 class="card-title">{{ offer.title }}</h5>
 | 
			
		||||
                            <p class="card-text">{{ offer.description }}</p>
 | 
			
		||||
                        </div>
 | 
			
		||||
                        <div class="card-footer">
 | 
			
		||||
                            <p class="username">{{ offering.byUser }}</p>
 | 
			
		||||
                            <p class="zip">{{ offering.zipCode }}</p>
 | 
			
		||||
                            <p class="username">{{ offer.byUser }}</p>
 | 
			
		||||
                            <p class="zip">{{ offer.zipCode }}</p>
 | 
			
		||||
                        </div>
 | 
			
		||||
                    </div>
 | 
			
		||||
                </a>
 | 
			
		||||
            {% endfor %}
 | 
			
		||||
        </div>
 | 
			
		||||
    {% 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 %}
 | 
			
		||||
{% endblock %}
 | 
			
		||||
| 
						 | 
				
			
			@ -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 %}
 | 
			
		||||
							
								
								
									
										19
									
								
								templates/app/new_offer.html.twig
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								templates/app/new_offer.html.twig
									
										
									
									
									
										Normal 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 %}
 | 
			
		||||
| 
						 | 
				
			
			@ -24,19 +24,19 @@
 | 
			
		|||
          <div class="collapse navbar-collapse" id="navbarSupportedContent">
 | 
			
		||||
            <ul class="navbar-nav mr-auto">
 | 
			
		||||
              <li class="nav-item">
 | 
			
		||||
                <a class="nav-link" href=" {{ path('homepage') }} ">Listings</a>
 | 
			
		||||
                <a class="nav-link" href=" {{ path('homepage') }} ">Offers</a>
 | 
			
		||||
              </li>
 | 
			
		||||
              <li class="nav-item">
 | 
			
		||||
                <a class="nav-link" href="{{ path('user_page') }}">User</a>
 | 
			
		||||
              </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>
 | 
			
		||||
            </ul>
 | 
			
		||||
          </div>
 | 
			
		||||
        </nav>
 | 
			
		||||
 | 
			
		||||
        <div class="container listings-container">
 | 
			
		||||
        <div class="container offer-container">
 | 
			
		||||
            {% block body %}{% endblock %}
 | 
			
		||||
        </div>
 | 
			
		||||
    </body>
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Reference in a new issue