Skip to content

Commit

Permalink
UI improvement, smoke tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SergioMendolia committed Dec 3, 2024
1 parent 7a65dfe commit 0f25c49
Show file tree
Hide file tree
Showing 22 changed files with 631 additions and 419 deletions.
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
"@php bin/console doctrine:schema:update --complete --force --env=test -n",
"@php bin/console typesense:create --env=test",
"@php bin/console doctrine:fixtures:load --env=test --append -n",
"npm i",
"npm run build",
"@test-phpunit"
]
},
Expand Down
730 changes: 367 additions & 363 deletions composer.lock

Large diffs are not rendered by default.

8 changes: 8 additions & 0 deletions config/packages/csrf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Enable stateless CSRF protection for forms and logins/logouts
framework:
form:
csrf_protection:
enabled: true

csrf_protection:
enabled: true
24 changes: 23 additions & 1 deletion src/Controller/DefaultController.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function index(BookRepository $bookRepository, BookInteractionRepository
$types = $bookRepository->countBooks(true);

$books = $bookInteractionRepository->getStartedBooks();
$readList = $bookInteractionRepository->getFavourite();
$readList = $bookInteractionRepository->getFavourite(6);

$series = $bookRepository->getStartedSeries()->getResult();

Expand Down Expand Up @@ -54,6 +54,28 @@ public function index(BookRepository $bookRepository, BookInteractionRepository
]);
}

#[Route('/reading-list', name: 'app_readinglist')]
public function readingList(BookRepository $bookRepository, BookInteractionRepository $bookInteractionRepository): Response
{
$readList = $bookInteractionRepository->getFavourite(hideFinished: false);

$statuses = [
'unread' => [],
'finished' => [],
];
foreach ($readList as $bookInteraction) {
if ($bookInteraction->isFinished()) {
$statuses['finished'][] = $bookInteraction->getBook();
} else {
$statuses['unread'][] = $bookInteraction->getBook();
}
}

return $this->render('default/readingList.html.twig', [
'readlist' => $statuses,
]);
}

#[Route('/all/{page}', name: 'app_allbooks', requirements: ['page' => '\d+'])]
public function allbooks(Request $request, BookRepository $bookRepository, FilteredBookUrlGenerator $filteredBookUrlGenerator, PaginatorInterface $paginator, int $page = 1): Response
{
Expand Down
3 changes: 1 addition & 2 deletions src/DataFixtures/KoboFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public function load(ObjectManager $manager): void

protected function getUser(): User
{
// @phpstan-ignore-next-line
return $this->getReference(UserFixture::USER_REFERENCE);
return $this->getReference(UserFixture::USER_REFERENCE, User::class);
}

public function getDependencies(): array
Expand Down
6 changes: 2 additions & 4 deletions src/DataFixtures/ShelfFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,12 @@ public function load(ObjectManager $manager): void

protected function getUser(): User
{
// @phpstan-ignore-next-line
return $this->getReference(UserFixture::USER_REFERENCE);
return $this->getReference(UserFixture::USER_REFERENCE, User::class);
}

protected function getBook(): Book
{
// @phpstan-ignore-next-line
return $this->getReference(BookFixture::BOOK_REFERENCE);
return $this->getReference(BookFixture::BOOK_REFERENCE, Book::class);
}

public function getDependencies(): array
Expand Down
8 changes: 5 additions & 3 deletions src/DataFixtures/ShelfKoboFixture.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace App\DataFixtures;

use App\Entity\KoboDevice;
use App\Entity\Shelf;
use Doctrine\Bundle\FixturesBundle\Fixture;
use Doctrine\Common\DataFixtures\DependentFixtureInterface;
use Doctrine\Persistence\ObjectManager;
Expand All @@ -10,9 +12,9 @@ class ShelfKoboFixture extends Fixture implements DependentFixtureInterface
{
public function load(ObjectManager $manager): void
{
$kobo = $this->getReference(KoboFixture::KOBO_REFERENCE);
// @phpstan-ignore-next-line
$kobo->addShelf($this->getReference(ShelfFixture::SHELF_REFERENCE));
$kobo = $this->getReference(KoboFixture::KOBO_REFERENCE, KoboDevice::class);

$kobo->addShelf($this->getReference(ShelfFixture::SHELF_REFERENCE, Shelf::class));

$manager->flush();
}
Expand Down
23 changes: 12 additions & 11 deletions src/Menu/MenuBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,18 @@ public function createMainMenu(): ItemInterface
if ($user->isDisplayPublishers()) {
$books->addChild('menu.publishers', ['route' => 'app_groups', 'routeParameters' => ['type' => 'publisher'], ...$this->defaultAttr])->setExtra('icon', 'tags-fill');
}
$profile = $menu->addChild('profile_divider', ['label' => $user->getUsername()])->setExtra('divider', true);
$profile->addChild('menu.readinglist', ['route' => 'app_readinglist', ...$this->defaultAttr])->setExtra('icon', 'list-task');
if ($user->isDisplayTimeline()) {
$profile->addChild('menu.timeline', ['route' => 'app_timeline', ...$this->defaultAttr])->setExtra('icon', 'calendar2-week');
}
if ($user->isUseKoboDevices()) {
$profile->addChild('menu.kobodevices', ['route' => 'app_kobodevice_user_index', ...$this->defaultAttr])->setExtra('icon', 'gear-fill');
}

$profile->addChild('menu.profile', ['route' => 'app_user_profile', ...$this->defaultAttr])->setExtra('icon', 'person-circle');
$profile->addChild('menu.logout', ['route' => 'app_logout', ...$this->defaultAttr])->setExtra('icon', 'door-closed');

$shelves = $menu->addChild('shelves_divider', ['label' => 'menu.shelves'])->setExtra('divider', true);
if ($user->getShelves()->count() > 0) {
foreach ($user->getShelves() as $shelf) {
Expand All @@ -90,18 +102,7 @@ public function createMainMenu(): ItemInterface
}
}
}
$profile = $menu->addChild('profile_divider', ['label' => $user->getUsername()])->setExtra('divider', true);

if ($user->isUseKoboDevices()) {
$profile->addChild('menu.kobodevices', ['route' => 'app_kobodevice_user_index', ...$this->defaultAttr])->setExtra('icon', 'gear-fill');
}

$profile->addChild('menu.profile', ['route' => 'app_user_profile', ...$this->defaultAttr])->setExtra('icon', 'person-circle');
$shelves->addChild('menu.editshelves', ['route' => 'app_shelf_crud_index', ...$this->defaultAttr])->setExtra('icon', 'building-fill-gear');
if ($user->isDisplayTimeline()) {
$profile->addChild('menu.timeline', ['route' => 'app_timeline', ...$this->defaultAttr])->setExtra('icon', 'calendar2-week');
}
$profile->addChild('menu.logout', ['route' => 'app_logout', ...$this->defaultAttr])->setExtra('icon', 'door-closed');

if ($this->security->isGranted('ROLE_ADMIN')) {
$admin = $menu->addChild('admin_divider', ['label' => 'menu.admin'])->setExtra('divider', true);
Expand Down
22 changes: 14 additions & 8 deletions src/Repository/BookInteractionRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,24 @@ public function getStartedBooks(): array
return $results;
}

public function getFavourite(): array
/**
* @return array<BookInteraction>
*/
public function getFavourite(?int $max = null, bool $hideFinished = true): array
{
$results = $this->createQueryBuilder('b')
->andWhere('b.favorite = true')
->andWhere('b.hidden = false')
->andWhere('b.finished = false')
$qb = $this->createQueryBuilder('b')
->andWhere('b.favorite = true');
if ($hideFinished) {
$qb->andWhere('b.finished = false');
}

$qb->andWhere('b.hidden = false')
->andWhere('b.user = :val')
->setParameter('val', $this->security->getUser())
->orderBy('b.created', 'ASC')
->getQuery()
->getResult()
;
->setMaxResults($max);

$results = $qb->getQuery()->getResult();
if (!is_array($results)) {
return [];
}
Expand Down
23 changes: 15 additions & 8 deletions src/Repository/BookRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,24 @@ public function countBooks(bool $group = false): array
*/
public function getWithSameAuthors(Book $book, int $maxResults = 6): array
{
$qb = $this->getAllBooksQueryBuilder();
try {
$qb = $this->getAllBooksQueryBuilder();

$orModule = $qb->expr()->orX();
$orModule = $qb->expr()->orX();

foreach ($book->getAuthors() as $key => $author) {
$orModule->add('JSON_CONTAINS(lower(book.authors), :author'.$key.')=1');
$qb->setParameter('author'.$key, json_encode([strtolower($author)]));
}
$qb->andWhere($orModule);
foreach ($book->getAuthors() as $key => $author) {
$orModule->add('JSON_CONTAINS(lower(book.authors), :author'.$key.')=1');
$qb->setParameter('author'.$key, json_encode([strtolower($author)]));
}
$qb->andWhere($orModule);

$results = $qb->getQuery()->getResult();
$results = $qb->getQuery()->getResult();
} catch (\Exception $e) {
if ($e->getMessage() === "Operation 'JSON_CONTAINS' is not supported by platform.") {
return [];
}
throw $e;
}

if (!is_array($results)) {
return [];
Expand Down
12 changes: 12 additions & 0 deletions src/Twig/Components/SearchModal.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace App\Twig\Components;

use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\DefaultActionTrait;

#[AsLiveComponent(method: 'get')]
class SearchModal
{
use DefaultActionTrait;
}
12 changes: 12 additions & 0 deletions symfony.lock
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,18 @@
".env"
]
},
"symfony/form": {
"version": "7.2",
"recipe": {
"repo": "github.com/symfony/recipes",
"branch": "main",
"version": "7.2",
"ref": "7d86a6723f4a623f59e2bf966b6aad2fc461d36b"
},
"files": [
"config/packages/csrf.yaml"
]
},
"symfony/framework-bundle": {
"version": "6.2",
"recipe": {
Expand Down
4 changes: 3 additions & 1 deletion templates/base.html.twig
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{% extends themedTemplate('bare.html.twig') %}
{% block content %}
<header class="navbar sticky-top bg-dark flex-md-nowrap p-0 shadow" data-bs-theme="dark">
<div class="navbar-brand col-12 me-0 px-3 fs-6 text-white">
<div class="navbar-brand col-12 me-0 px-3 fs-6 text-white overflow-auto">
<i class="bi bi-house-fill"></i> <a class="text-white d-inline-block mx-2" href="{{ path('app_dashboard') }}">Biblioteca</a>
<i class="bi bi-chevron-right"></i><h1 class="h6 m-2 d-inline-block">{% block title %}{{ 'page'|trans }}{% endblock %}</h1>
</div>
Expand All @@ -24,6 +24,8 @@
aria-labelledby="sidebarMenuLabel">
<div class="offcanvas-body d-md-flex flex-column p-0 pt-lg-3 overflow-y-auto">

{{ component('SearchModal') }}

{{ knp_menu_render('main',{'currentClass':'active','ancestorClass':'active'}) }}

</div>
Expand Down
8 changes: 6 additions & 2 deletions templates/components/BootstrapModal.html.twig
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<div {{ attributes.defaults({
class: 'modal fade text-start modal-lg',
class: 'modal fade text-start modal-xl',
tabindex: '-1',
'aria-hidden': 'true',
id: id ? id : false,
}).defaults(stimulus_controller('bootstrap-modal')) }}>
<div class="modal-dialog">
<div class="modal-dialog modal-dialog-scrollable">
<div class="modal-content">
{% block modal_full_content %}
{% if block('modal_header') %}
Expand All @@ -23,6 +23,10 @@
</div>
{% endif %}
{% endblock %}
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Close</button>
</div>

</div>
</div>
</div>
2 changes: 1 addition & 1 deletion templates/components/InlineEditBook.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
</a>
{% endfor %}
{% elseif field=='serie' and book.serie is not null %}
<a href="{{ filter_book_url({'serie':[book.serie]}) }}" class="text-decoration-none p-1">
<a href="{{ filter_book_url({'serie':[book.serie], 'orderBy':'serieIndex-asc'}) }}" class="text-decoration-none p-1">
<i class="bi bi-list-ol"></i>&nbsp;{{ book.serie }}
</a>
{% elseif field=='ageCategory' %}
Expand Down
13 changes: 3 additions & 10 deletions templates/components/Search.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,16 @@
<div class="col-md-3 col-12">
{% for facet in computed.results.facets|default([]) %}
{% if facet.counts|length>0 %}
<h5 class="m-0 mb-2">{{ facet.field_name|capitalize }}</h5>
<h5 class="m-0 mb-2 fs-6">{{ facet.field_name|capitalize }}</h5>
<ul class="list-group mb-4">
{% for count in facet.counts %}
<li class="list-group-item {{ count.value in query?'active' }}">
<button type="button" class="btn btn-sm btn-bare position-relative"

data-action="live#action"
data-live-action-param="addToQuery(value={{ count.value|e('html') }})"
data-live-action-param="addToQuery"
data-live-value-param="{{ count.value }}"
>
<small>
{{ count.value }}
<span class="badge rounded-pill bg-primary">
{{ count.count }}
<span class="visually-hidden">records</span>
<span class="visually-hidden">records</span></small>
</span>
</button>
</li>
{% endfor %}
</ul>
Expand Down
27 changes: 27 additions & 0 deletions templates/components/SearchModal.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<div {{ attributes.defaults(stimulus_controller('inline-edit')) }}>

<div class="px-2 w-100">
<div class="card">

<div class="card-body p-1">
<button class="btn btn-sm w-100" data-bs-toggle="modal" data-bs-target="#searchmodal" type="button"
data-toggle="tooltip" data-placement="bottom" >
<i class="bi bi-search"></i> Search
</button>
</div>
</div>
</div>



{% component BootstrapModal with {id: 'searchmodal'} %}
{% block modal_header %}
<h5>{{ 'search'|trans }}</h5>
{% endblock %}
{% block modal_body %}

{{ component('Search') }}
{% endblock %}

{% endcomponent %}
</div>
8 changes: 3 additions & 5 deletions templates/default/dashboard.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,6 @@
{% endblock %}

{% block body %}
<div class="row ">
<div class="col-md-12">
{{ component('Search') }}
</div>
</div>

{% if books|length>0 %}
<div class="row mt-4">
Expand Down Expand Up @@ -54,6 +49,9 @@
{{ 'add_to_favorites'|trans }}
</div>
{% endif %}
<div class="col-12 mt-0">
<a class="btn btn-bare btn-sm" href="{{ path('app_readinglist') }}" >{{ 'reading.list.showall'|trans }} <i class="bi bi-caret-right-fill"></i></a>
</div>
</div>

{% if series|length >0 %}
Expand Down
Loading

0 comments on commit 0f25c49

Please sign in to comment.