diff --git a/src/Controller/WishlistController.php b/src/Controller/WishlistController.php index 24a225ff6509c799ca1bd7a442bafd9c99337dde..7e1d571ad2b47914f1667103dbf12cc6a7ec0576 100644 --- a/src/Controller/WishlistController.php +++ b/src/Controller/WishlistController.php @@ -17,8 +17,11 @@ final class WishlistController extends AbstractController #[Route(name: 'app_wishlist_index', methods: ['GET'])] public function getWishLists(WishlistRepository $wishlistRepository): Response { + $user = $this->getUser() ; + + return $this->render('wishlist/index.html.twig', [ - 'wishlists' => $wishlistRepository->findAll(), + 'wishlists' => $user->getWishlists()->toArray() ]); } @@ -26,15 +29,7 @@ final class WishlistController extends AbstractController public function createWishlist(Request $request, EntityManagerInterface $entityManager): Response { $wishlist = new Wishlist(); - $name = $request->get(key: 'name'); - $wishlist->setName(name: $name); - $deadline = $request->get('deadline') ; - $wishlist->setDeadline($deadline); - $entityManager->persist($wishlist); - $entityManager->flush(); - - return new Response('wishlist created successfully', Response::HTTP_CREATED) ; -/* $form = $this->createForm(WishlistType::class, $wishlist); + $form = $this->createForm(WishlistType::class, $wishlist); $form->handleRequest($request); if ($form->isSubmitted() && $form->isValid()) { @@ -47,7 +42,9 @@ final class WishlistController extends AbstractController return $this->render('wishlist/new.html.twig', [ 'wishlist' => $wishlist, 'form' => $form, - ]); */ + ]); + + } #[Route('/{id}', name: 'app_wishlist_show', methods: ['GET'])] @@ -94,3 +91,15 @@ final class WishlistController extends AbstractController } + + +/* + $wishlist = new Wishlist(); + $name = $request->get(key: 'name'); + $wishlist->setName(name: $name); + $deadline = $request->get('deadline') ; + $wishlist->setDeadline($deadline); + $this->getUser()->addToAuthorWhishlists($wishlist); + $entityManager->persist($wishlist); + $entityManager->persist($this->getUser()) ; + $entityManager->flush(); */ \ No newline at end of file diff --git a/src/Entity/User.php b/src/Entity/User.php index cdda1070d188ed0aa7c04e7faf7411790d2c0cba..3b99380de70e1e5d2765ef69d24c94c023e4f3e1 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -164,6 +164,11 @@ class User implements UserInterface, PasswordAuthenticatedUserInterface return $this->wishlists; } + public function addToAuthorWhishlists(Wishlists $wishlist){ + if (!$this->wishlists->contains($wishlist)) { + $this->wishlists[] = $wishlist; + } + } // public function getInvitations(): Collection // { // return $this->invitations; diff --git a/templates/wishlist/index.html.twig b/templates/wishlist/index.html.twig index 54e8db1deb65e42c651f4f04dbc8b8288a69efec..3f6757e13f54603fcee0fce0623c0a6ec7ab01cb 100644 --- a/templates/wishlist/index.html.twig +++ b/templates/wishlist/index.html.twig @@ -1,215 +1,36 @@ -{% extends 'base.html.twig' %} -{% block title %}My Wishlists{% endblock %} +{% extends 'base.html.twig' %} -{% block body %} -<header> - <div class="user-icon"></div> - <h1>My Wishlists</h1> - <input type="text" class="search-bar" placeholder="Search..."> -</header> +{% block title %} My Wishlists {% endblock %} -<div class="navbar"> - <button class="add-wishlist-btn" data-bs-toggle="modal" data-bs-target="#createWishlistModal">Add wishlist</button> -</div> -<!-- Create Wishlist Modal --> -<div class="modal fade" id="createWishlistModal" tabindex="-1" aria-labelledby="createWishlistModalLabel" aria-hidden="true"> - <div class="modal-dialog"> - <div class="modal-content"> - <div class="modal-header"> - <h5 class="modal-title" id="createWishlistModalLabel">Create New Wishlist</h5> - <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> - </div> - <div class="modal-body"> - <form id="createWishlistForm"> - <div class="mb-3"> - <label for="wishlistName" class="form-label">Name*</label> - <input type="text" class="form-control" id="wishlistName" required> - </div> - <div class="mb-3"> - <label for="wishlistDeadline" class="form-label">Deadline</label> - <input type="datetime-local" class="form-control" id="wishlistDeadline"> - </div> - <div class="mb-3 form-check"> - <input type="checkbox" class="form-check-input" id="wishlistIsDisabled"> - <label class="form-check-label" for="wishlistIsDisabled">Disabled</label> - </div> - </form> - </div> - <div class="modal-footer"> - <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> - <button type="button" class="btn btn-primary" id="submitWishlist">Create</button> - </div> - </div> +{% block body %} + <header> + <div class="user-icon"></div> + <h1>My Wishlists</h1> + <input type="text" class="search-bar" placeholder="Search..."> + </header> + + <div class="navbar"> + <button class="add-wishlist-btn">Add wishlist</button> </div> -</div> - -<div class="container"> - {% for wishlist in wishlists %} - <div class="wishlist {% if wishlist.isDisabled %}wishlist-disabled{% endif %}"> - <div class="wishlist-header"> - <h2>{{ wishlist.name }}</h2> - {% if wishlist.deadline %} - <span class="deadline-badge"> - Due: {{ wishlist.deadline|date('Y-m-d H:i') }} - {% if wishlist.deadline|date('U') < 'now'|date('U') %} - <span class="deadline-passed">(Passed)</span> - {% endif %} - </span> - {% endif %} - {% if wishlist.isDisabled %} - <span class="disabled-badge">Disabled</span> - {% endif %} - </div> - <div class="wishlist-items"> + + <div class="container"> + {% for wishlist in wishlists %} + <div class="wishlist"> + <h2>{{ wishlist.title }}</h2> + <div class="wishlist-items"> {% for item in wishlist.items %} <div class="wishlist-item">📷</div> {% endfor %} + </div> + <p class="wishlist-footer">Authors: name1, name2</p> + <div class="wishlist-actions"> + <button title="Share wishlist">↗</button> + <button title="Edit title">✏</button> + <button title="Delete wishlist">🗑</button> + </div> </div> - <p class="wishlist-footer">Authors: name1, name2</p> - <div class="wishlist-actions"> - <button title="Share wishlist">↗</button> - <button title="Edit wishlist">✏</button> - <button title="Delete wishlist">🗑</button> - </div> + {% end for %} </div> - {% endfor %} -</div> -{% endblock %} - -{% block javascripts %} -{{ parent() }} -<script> -document.addEventListener('DOMContentLoaded', function() { - document.getElementById('submitWishlist').addEventListener('click', function() { - const name = document.getElementById('wishlistName').value; - const deadline = document.getElementById('wishlistDeadline').value; - const isDisabled = document.getElementById('wishlistIsDisabled').checked; - - if (!name) { - alert('Please enter a name for your wishlist'); - return; - } - - fetch('/wishlists/create', { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - 'X-Requested-With': 'XMLHttpRequest' - }, - body: JSON.stringify({ - name: name, - deadline: deadline, - isDisabled: isDisabled - }) - }) - .then(response => response.json()) - .then(data => { - if (data.success) { - bootstrap.Modal.getInstance(document.getElementById('createWishlistModal')).hide(); - window.location.reload(); - } else { - alert('Error creating wishlist: ' + data.message); - } - }) - .catch(error => { - console.error('Error:', error); - alert('An error occurred while creating the wishlist'); - }); - }); -}); -</script> -{% endblock %} - -{% block stylesheets %} -{{ parent() }} -<style> - .wishlist { - border: 1px solid #ddd; - border-radius: 8px; - padding: 15px; - margin-bottom: 20px; - box-shadow: 0 2px 4px rgba(0,0,0,0.1); - position: relative; - } - - .wishlist-disabled { - opacity: 0.7; - background-color: #f8f9fa; - } - - .wishlist-header { - display: flex; - justify-content: space-between; - align-items: center; - flex-wrap: wrap; - gap: 10px; - margin-bottom: 10px; - } - - .deadline-badge { - background: #e9ecef; - padding: 3px 8px; - border-radius: 4px; - font-size: 0.9em; - } - - .deadline-passed { - color: #dc3545; - font-weight: bold; - } - - .disabled-badge { - background: #6c757d; - color: white; - padding: 3px 8px; - border-radius: 4px; - font-size: 0.9em; - } - - .wishlist-items { - display: flex; - flex-wrap: wrap; - gap: 10px; - margin: 15px 0; - } - - .wishlist-item { - width: 60px; - height: 60px; - background: #f5f5f5; - border-radius: 4px; - display: flex; - align-items: center; - justify-content: center; - font-size: 24px; - } - - .wishlist-actions { - display: flex; - gap: 10px; - justify-content: flex-end; - } - - .wishlist-actions button { - background: none; - border: none; - cursor: pointer; - font-size: 18px; - } - - .add-wishlist-btn { - background-color: #4CAF50; - color: white; - border: none; - padding: 10px 15px; - border-radius: 4px; - cursor: pointer; - } - - .add-wishlist-btn:hover { - background-color: #45a049; - } -</style> -{% endblock %} \ No newline at end of file + {% endblock %} diff --git a/templates/wishlist/new.html.twig b/templates/wishlist/new.html.twig index 4f115810a00a8d94756aaa7b829cd9596a678d0d..08e16bc8c18a7234df83ea9003ad18954a76ee67 100644 --- a/templates/wishlist/new.html.twig +++ b/templates/wishlist/new.html.twig @@ -1,11 +1,99 @@ +{# templates/wishlist/new.html.twig #} {% extends 'base.html.twig' %} -{% block title %}New Wishlist{% endblock %} +{% block title %}Create New Wishlist{% endblock %} + +{% block stylesheets %} + {{ parent() }} + <style> + .wishlist-form { + max-width: 600px; + margin: 0 auto; + padding: 20px; + background-color: #f8f9fa; + border-radius: 8px; + box-shadow: 0 0 10px rgba(0,0,0,0.1); + } + .form-group { + margin-bottom: 1.5rem; + } + .form-label { + display: block; + margin-bottom: 0.5rem; + font-weight: bold; + } + .form-control { + width: 100%; + padding: 0.5rem; + border: 1px solid #ced4da; + border-radius: 4px; + font-size: 1rem; + } + .form-check { + display: flex; + align-items: center; + margin-top: 1rem; + } + .form-check-input { + margin-right: 0.5rem; + } + .btn { + padding: 0.5rem 1rem; + border-radius: 4px; + cursor: pointer; + font-size: 1rem; + } + .btn-primary { + background-color: #007bff; + color: white; + border: none; + } + .btn-primary:hover { + background-color: #0069d9; + } + .form-help { + font-size: 0.8rem; + color: #6c757d; + margin-top: 0.25rem; + } + .error-message { + color: #dc3545; + font-size: 0.875rem; + margin-top: 0.25rem; + } + </style> +{% endblock %} {% block body %} - <h1>Create new Wishlist</h1> + <div class="container"> + <h1 class="my-4">Create New Wishlist</h1> + + {{ form_start(form, {'attr': {'class': 'wishlist-form'}}) }} + <div class="form-group"> + {{ form_label(form.name) }} + {{ form_widget(form.name, {'attr': {'class': 'form-control'}}) }} + {{ form_errors(form.name) }} + <small class="form-help">Give your wishlist a descriptive name</small> + </div> - {{ include('wishlist/_form.html.twig') }} + <div class="form-group"> + {{ form_label(form.deadline) }} + {{ form_widget(form.deadline, {'attr': {'class': 'form-control'}}) }} + {{ form_errors(form.deadline) }} + <small class="form-help">Optional - set a deadline for this wishlist</small> + </div> - <a href="{{ path('app_wishlist_index') }}">back to list</a> -{% endblock %} + <div class="form-check"> + {{ form_widget(form.isDisabled, {'attr': {'class': 'form-check-input'}}) }} + {{ form_label(form.isDisabled) }} + {{ form_errors(form.isDisabled) }} + </div> + <small class="form-help">Disabled wishlists won't be visible to others</small> + + <div class="form-group mt-4"> + <button type="submit" class="btn btn-primary">Create Wishlist</button> + <a href="{{ path('wishlist_index') }}" class="btn btn-secondary ml-2">Cancel</a> + </div> + {{ form_end(form) }} + </div> +{% endblock %} \ No newline at end of file