From 477d6727f4a22c8b0799a7ef445589a6ab52f9a2 Mon Sep 17 00:00:00 2001 From: Ro Date: Tue, 17 Jan 2023 15:54:59 -0800 Subject: [PATCH] Turned on Index search Activated the full text search on the index pages as well as plugging in a tempalte to show location information. Still needs to be styled but it's all wired up. Also cleaned some typos in the About description. One day I'll be able to spell. One day. --- public/assets/css/front/index.css | 43 +++++++++++++---------- public/assets/css/global/frame.css | 8 +++-- src/Controller/Routes/Back/Locations.php | 2 -- src/Controller/Routes/Back/Members.php | 2 +- src/Controller/Routes/Front/Index.php | 30 +++++++++++++++- src/Service/HandleLocations.php | 44 ++++++++++++++++++++++++ templates/front/about.twig | 7 ++-- templates/front/index.twig | 29 ++++++++++++---- templates/front/location.twig | 13 +++++++ 9 files changed, 143 insertions(+), 35 deletions(-) create mode 100644 templates/front/location.twig diff --git a/public/assets/css/front/index.css b/public/assets/css/front/index.css index 7fb9463..d22d13d 100644 --- a/public/assets/css/front/index.css +++ b/public/assets/css/front/index.css @@ -4,34 +4,41 @@ section[role="start"] { background-position: center; background-repeat: no-repeat; background-size: cover; - display: flex; align-items: center; justify-content: center; } -section[role="start"] div { +section[role="start"] div[role="index-wrapper"] { + margin: 0 auto; + width: 100%; + max-width: 600px; + padding-top: 30px; +} + +section[role="start"] div[role="index-search"] { background: var(--primary); - width: 400px; - border-radius: 3px; - padding: 5px; + border-radius: 5px; + padding: 15px; } -section[role="start"] span[role="title"] { - font-size: 100px; - line-height: 80px; - font-weight: bold; - color: var(--secondary); +section[role="start"] div input[type="text"] { + font-size: 2em; + width: 87%; } -section[role="start"] p { - color: var(--white); - display: inline-block; +section[role="start"] div button { vertical-align: top; - margin: 6px auto; - font-size: 1.87em; + width: 57px; + height: 57px; } -section[role="start"] p a { - color: var(--highlight); - margin-top: 5px; +section[role="start"] div button i { + font-size: 1.5em; +} + +section[role="start"] a.search-link { + background: var(--secondary); + padding: 5px; + color: var(--primary); + border-radius: 3px; } diff --git a/public/assets/css/global/frame.css b/public/assets/css/global/frame.css index 7127e93..8c17c24 100644 --- a/public/assets/css/global/frame.css +++ b/public/assets/css/global/frame.css @@ -28,6 +28,10 @@ header > nav { padding: 10px; } +header > nav a { + color: var(--primary); +} + header > nav i { font-size: 1.3em; } @@ -49,7 +53,7 @@ main { /* GLOBALS */ a { - color: var(--primary); + color: var(--highlight); text-decoration: none; border-bottom: 1px solid var(--white); transition: all 0.2s linear; @@ -61,7 +65,7 @@ a[role="nav-links"] { } a:hover { - border-bottom: 1px solid var(--primary); + border-bottom: 1px solid var(--secondary); } sup { diff --git a/src/Controller/Routes/Back/Locations.php b/src/Controller/Routes/Back/Locations.php index 880ef7c..1d2fb1b 100644 --- a/src/Controller/Routes/Back/Locations.php +++ b/src/Controller/Routes/Back/Locations.php @@ -12,7 +12,6 @@ use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RequestStack; use Doctrine\Persistence\ManagerRegistry; use App\Service\HandleLocations; -use Doctrine\DBAL\Connection; use App\Service\Auth; use App\Service\FileUploader; use App\Service\Render; @@ -37,7 +36,6 @@ class Locations extends AbstractController Auth $auth, HandleLocations $locations, ManagerRegistry $doctrine, - Connection $connection, Render $render, string $pageNum ): Response { diff --git a/src/Controller/Routes/Back/Members.php b/src/Controller/Routes/Back/Members.php index 19243ae..5568055 100644 --- a/src/Controller/Routes/Back/Members.php +++ b/src/Controller/Routes/Back/Members.php @@ -16,7 +16,7 @@ use App\Service\Auth; class Members extends AbstractController { /** - * @Route("/den/members/page/{pageNum}", name="den-locations") + * @Route("/den/members/page/{pageNum}", name="den-members-index") */ public function showMembers( Request $request, diff --git a/src/Controller/Routes/Front/Index.php b/src/Controller/Routes/Front/Index.php index 788f34b..d3eea1d 100644 --- a/src/Controller/Routes/Front/Index.php +++ b/src/Controller/Routes/Front/Index.php @@ -21,7 +21,35 @@ class Index extends AbstractController public function showIndex(Request $request, Auth $auth, Render $render, HandleLocations $locations): Response { $list = $locations->getActiveLocations(); - return $render->page(["count" => count($list)], "This is The Bad Space", "front/index.twig"); + if ($request->getMethod() == "GET") { + return $render->page(["count" => count($list)], "This is The Bad Space", "front/index.twig"); + } else { + $results = $locations->searchLocations($request->request->get("index_search")); + return $render->page( + ["count" => count($list), + "items" => $results['items'] + ], + "This is The Bad Space", + "front/index.twig" + ); + }; + } + + /** + * @Route("/location/{uuid}", name="front-location") + */ + public function showLocations( + Request $request, + Render $render, + HandleLocations $locations, + string $uuid = "none" + ): Response { + $location = $locations->getLocationbyUUID($uuid); + return $render->page( + ["location" => $location[0]], + "The Bad Space | " . $location[0]->getName(), + "front/location.twig" + ); } /** diff --git a/src/Service/HandleLocations.php b/src/Service/HandleLocations.php index c09ae94..964a647 100644 --- a/src/Service/HandleLocations.php +++ b/src/Service/HandleLocations.php @@ -11,6 +11,7 @@ use Exception; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Component\Uid\Uuid; +use Doctrine\DBAL\Connection; use App\Entity\Location; use League\Csv\Reader; @@ -25,16 +26,59 @@ class HandleLocations { private $session; private $entityManager; + private $conn; private $limit = 4; public function __construct( + Connection $connection, EntityManagerInterface $entityManager, RequestStack $requestStack ) { + $this->connection = $connection; $this->entityManager = $entityManager; $this->session = $requestStack->getSession(); } + public function searchLocations(string $terms) + { + $errorMessage = null; + $response = null; + //$utils = new StringTools(); + //$term = $utils->removeCommonWords($terms); + $terms = str_replace(",", "", $terms); + $terms = str_replace(" ", "|", $terms); + + try { + $search = $this->connection->fetchAllAssociative("SELECT * FROM searchlocations('$terms')"); + } catch (PDOException $error) { + $errorMessage = $error->getMessage(); + } catch (DBALException $error) { + $errorMessage = $error->getMessage(); + } catch (ORMException $error) { + $errorMessage = $error->getMessage(); + } catch (Exception $error) { + $errorMessage = $error->getMessage(); + } catch (SyntaxErrorException $error) { + $errorMessage = $error->getMessage(); + } + + if ($errorMessage != null) { + $response = [ + "status" => false, + "message" => $errorMessage, + ]; + } else { + $response = [ + "status" => true, + "message" => "Good Reqeust", + "items" => $search, + "terms" => $terms, + ]; + } + + return $response; + } + public function getActiveLocations() { $listings = $this->entityManager->getRepository(Location::class); diff --git a/templates/front/about.twig b/templates/front/about.twig index 96cc4f8..08bc052 100644 --- a/templates/front/about.twig +++ b/templates/front/about.twig @@ -16,15 +16,12 @@ Artist Marcia X with additional support from Ginger - to provide a catolog of instances seek to cause harm and reduce the quality of experience in the fediverse. + to provide a catalog of instances that seek to cause harm and reduce the quality of experience in the fediverse.

- - -

- Technial support provided by + Technical support provided by Ro.

diff --git a/templates/front/index.twig b/templates/front/index.twig index 690d5ae..4d04dfe 100644 --- a/templates/front/index.twig +++ b/templates/front/index.twig @@ -5,12 +5,29 @@ {% block main %}
-
- {{ options.count }} -

- Bad Spaces tracked.
- Pace yourself. -

+
+
+
+ + +
+ {{ options.count }} + Bad Spaces tracked. Shot by + Ussama Azam + +
+ {% if options.items is defined %} +
+

Found

+ {% for item in options.items %} + {{ item.name }}
+ {% endfor %} +
+ {% endif %}
+ +
{% endblock %} diff --git a/templates/front/location.twig b/templates/front/location.twig new file mode 100644 index 0000000..86e14d5 --- /dev/null +++ b/templates/front/location.twig @@ -0,0 +1,13 @@ +{% extends "base/frame.twig" %} +{% block stylesheets %} + + {% endblock %} + + {% block main %} +
+

About + {{ options.location.name }}

+ + This is a location +
+ {% endblock %}