1
0
mirror of https://koodu.h-i.works/projects/thebadspace synced 2025-06-25 16:04:37 -05:00

CSS Reshuffle, Added Page Renderer

Reorganized the CSS structure to there is some seperation between front
facing style and the backend den.

Also add the Render class so auth status is included in every template
rendering event so login status and select member data is available if
needed. will expand if needed.
This commit is contained in:
Ro
2023-01-08 14:28:25 -08:00
parent 26f3cbe994
commit 735117fcda
31 changed files with 11403 additions and 199 deletions

View File

@ -10,30 +10,18 @@ use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
//use App\Utils\PageRender;
use App\Service\Auth;
use App\Service\Render;
class Index extends AbstractController
{
/**
* @Route("/den", name="back-index")
*/
public function enterTheDen(Request $request, Auth $auth, RequestStack $requestStack): Response
public function enterTheDen(Request $request, Auth $auth, RequestStack $requestStack, Render $render): Response
{
if ($request->getMethod() == "GET") {
$result = $auth->status();
if ($result["status"]) {
$session = $requestStack->getSession();
$member = $session->get("member");
return $this->render("back/start.twig", [
"title" => "Welcome Back",
"handle" => $member->getHandle()
]);
} else {
return $this->render("back/index.twig", [
"title" => "Close the door behind you",
]);
}
return $render->page([], "This is the Den", "back/index.twig");
} else {
//handles login
$handle = $request->request->get("handle");

View File

@ -13,10 +13,9 @@ use Symfony\Component\HttpFoundation\RequestStack;
use Doctrine\Persistence\ManagerRegistry;
use App\Service\HandleLocations;
use Doctrine\DBAL\Connection;
//use App\Utils\PageRender;
//use App\Utils\StringTools;
use App\Service\Auth;
use App\Service\FileUploader;
use App\Service\Render;
class Locations extends AbstractController
{
@ -39,6 +38,7 @@ class Locations extends AbstractController
HandleLocations $locations,
ManagerRegistry $doctrine,
Connection $connection,
Render $render,
string $pageNum
): Response {
$result = $auth->status();
@ -48,15 +48,7 @@ class Locations extends AbstractController
$list = $locations->getLocationsPage($pageNum);
//$search = $connection->fetchAllAssociative("SELECT * FROM searchlocations('agenda')");
//var_dump($search[0]["name"]);
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations",
"handle" => $member->getHandle(),
"list" => $list,
"mode" => "index"
]);
return $render->page(["list" => $list, "mode" => "index"], "Bad Space | Locations", "back/locations.twig");
} else {
return $this->render("back/index.twig", [
"title" => "Close the door behind you",
@ -65,27 +57,41 @@ class Locations extends AbstractController
}
/**
* @Route("/den/locations/add", name="location-add")
* @Route("/den/locations/modify/{action}/{uuid}", name="location-modify")
*/
public function addLocation(
public function modifyLocation(
Request $request,
Auth $auth,
HandleLocations $locations,
ManagerRegistry $doctrine,
FileUploader $uploader
FileUploader $uploader,
Render $render,
string $action = "add",
string $uuid = "001"
): Response {
$result = $auth->status();
if ($result["status"]) {
if ($request->getMethod() == "GET") {
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations | Add",
"mode" => "add"
]);
$options = [];
if ($action == 'add') {
return $render->page(
["mode" => $action],
"Bad Space | Locations | Add",
"back/locations.twig"
);
} else {
$location = $locations->getLocationbyUUID($uuid);
return $render->page(
["mode" => $action, "location" => $location[0]],
"Bad Space | Locations | Edit",
"back/locations.twig"
);
}
} else {
//add new member
$token = $request->get("token");
$notice = "";
$entityManager = $doctrine->getManager();
$token = $request->get("token");
$notice = "";
$mode = $request->get("mode");
//token check
if (!$this->isCsrfTokenValid("upload", $token)) {
@ -100,16 +106,6 @@ class Locations extends AbstractController
);
}
$examples = [];
$files = $request->files->get("loc_examples");
if (!empty($files)) {
for ($i = 0; $i < count($files); $i++) {
$path = $files[$i]->getClientOriginalName();
array_push($examples, ["image_index" => $i, "path" => urlencode($path)]);
$uploader->uploadExamples("../public/assets/images/examples", $files[$i]);
}
}
if (
$request->request->get("loc_name") == "" ||
$request->request->get("loc_url") == "" ||
@ -124,20 +120,40 @@ class Locations extends AbstractController
]);
}
//check clear, call add method
$response = $locations->addLocation($request, $result["id"]);
//once everything clears, upload images and process request
$examples = [];
$files = $request->files->get("loc_examples");
if (!empty($files)) {
for ($i = 0; $i < count($files); $i++) {
$path = $files[$i]->getClientOriginalName();
array_push($examples, ["image_index" => $i, "path" => urlencode($path)]);
$uploader->uploadExamples("../public/assets/images/examples", $files[$i]);
}
}
$response = $locations->modifyLocation($request, $result["id"], $mode, $request->request->get("uuid"));
if ($response["status"]) {
$notice = "New location added! Take a break.";
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations | Add",
"notice" => $notice,
"mode" => "add"
]);
$options = [];
if ($mode == 'add') {
$options = [
"title" => "Bad Space | Locations | Add",
"notice" => $response["message"],
"mode" => $mode
];
} else {
$location = $locations->getLocationbyUUID($request->request->get("uuid"));
$options = [
"title" => "Bad Space | Locations | Edit",
"mode" => $mode,
"notice" => $response["message"],
"location" => $location[0]
];
}
return $this->render("back/locations.twig", $options);
} else {
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations | Add",
"title" => "Bad Space | Locations | Error",
"notice" => $response["message"],
"mode" => "add"
"mode" => $mode
]);
}
}
@ -156,15 +172,17 @@ class Locations extends AbstractController
Auth $auth,
HandleLocations $locations,
ManagerRegistry $doctrine,
FileUploader $uploader
FileUploader $uploader,
Render $render
): Response {
$result = $auth->status();
if ($result["status"]) {
if ($request->getMethod() == "GET") {
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations | Bulk Add",
"mode" => "bulk-add"
]);
return $render->page(
["mode" => "bulk-add"],
"Bad Space | Locations | Bulk Add",
"back/locations.twig"
);
} else {
// do posting stuff
$token = $request->get("token");
@ -227,29 +245,4 @@ class Locations extends AbstractController
return new Response("<html><body>LOGGED IN</body></html>");
}
}
/**
* @Route("/den/locations/edit/{uuid}", name="location-edit")
*/
public function editLocation(
Request $request,
Auth $auth,
HandleLocations $locations,
ManagerRegistry $doctrine,
FileUploader $uploader,
string $uuid = "1"
): Response {
$result = $auth->status();
if ($result["status"]) {
$location = $locations->getLocationbyUUID($uuid);
return $this->render("back/locations.twig", [
"title" => "Bad Space | Locations | Edit",
"mode" => "edit",
"location" => $location[0]
]);
} else {
header("Location:/den");
return new Response("<html><body>LOGGED IN</body></html>");
}
}
}

View File

@ -9,37 +9,19 @@ use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
//use App\Utils\PageRender;
//use App\Data\Auth;
use App\Service\Auth;
use App\Service\Render;
class Index extends AbstractController
{
/**
* @Route("/", name="index")
*/
public function showIndex(Request $request): Response
public function showIndex(Request $request, Auth $auth, Render $render): Response
{
return $this->render("front/index.twig", [
"title" => "This is The Bad Space",
]);
/*
$result = $auth->status();
if ($result["status"]) {
return $render->renderPage(
[
"bgImage" => "/images/base/tweed-flowers.png",
"role" => $result["role"],
],
"The Nile List | Welcome Back",
"front/index.html.twig"
);
} else {
//back to index to login
header("Location:/login");
return new Response("<html><body>LOGGED IN</body></html>");
}
*/
$check = $auth->status();
return $render->page([], "This is The Bad Space", "front/index.twig");
}
/**

View File

@ -90,6 +90,7 @@ class Auth
"status" => true,
"role" => $this->session->get("member")->getRole(),
"id" => $this->session->get("member")->getId(),
"handle" => $this->session->get("member")->getHandle(),
"token" => $this->session->get("token"),
];
} else {

View File

@ -27,7 +27,7 @@ class FileUploader
public function uploadExamples($examplesDir, $file)
{
try {
$file->move($examplesDir, urldecode($file->getClientOriginalName()));
$file->move($examplesDir, urlencode($file->getClientOriginalName()));
} catch (FileException $e) {
$this->logger->error("failed to upload image: " . $e->getMessage());
throw new FileException("Failed to upload image file");

View File

@ -81,10 +81,14 @@ class HandleLocations
* @param Request $request object containing posted data
* @return JSON
*/
public function addLocation($request, $memberId)
public function modifyLocation($request, $memberId, $action, $uuid = 0)
{
$errorMessage = null;
$location = new Location();
if ($action == "add") {
$location = new Location();
} else {
$location = $this->entityManager->getRepository(Location::class)->findOneBy(["uuid" => $uuid]);
}
//submitted values
$name = $request->request->get("loc_name");
@ -109,13 +113,17 @@ class HandleLocations
}
//set defaults
$location->setUuid(Uuid::v4());
$location->setActive(false);
$location->setCreatedAt(new \DateTimeImmutable());
$location->setUpdatedAt(new \DateTimeImmutable());
$location->setAddedBy($memberId);
$this->entityManager->persist($location);
if ($action == "add") {
$location->setUuid(Uuid::v4());
$location->setActive(false);
$location->setCreatedAt(new \DateTimeImmutable());
$location->setAddedBy($memberId);
$this->entityManager->persist($location);
} else {
$active = ($request->request->get("rating") == "true" ? true : false);
$location->setActive($active);
}
try {
$this->entityManager->flush();
@ -132,9 +140,15 @@ class HandleLocations
}
// return result status
if ($errorMessage == null) {
$message = "";
if ($action == "add") {
$message = "New location added. Woohoo!";
} else {
$message = "Location Updated! Water break!";
}
return $response = [
"status" => true,
"message" => "New member added. Woohoo!",
"message" => $message,
];
} else {
return $response = ["status" => false, "message" => $errorMessage];
@ -185,10 +199,10 @@ class HandleLocations
$location->setRating($ratings);
//grab images, move them to dir and set image array
foreach ($imgs as $img) {
foreach ($imgs as $key => $img) {
$imageName = uniqid() . ".jpg";
$path = "../public/assets/images/examples/" . $imageName;
array_push($examples, $imageName);
array_push($examples, ["image_index" => $key, "path" => urlencode($imageName)]);
file_put_contents($path, file_get_contents(trim($img)));
}
$location->setImages($examples);

35
src/Service/Render.php Normal file
View File

@ -0,0 +1,35 @@
<?php
namespace App\Service;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class Render extends AbstractController
{
private $auth;
public function __construct(Auth $auth)
{
$this->auth = $auth;
}
public function page($options, $title, $template)
{
$loggedIn = false;
$role = 0;
$handle = "Random Person";
$result = $this->auth->status();
if ($result["status"]) {
$loggedIn = $result["status"];
$handle = $result["handle"];
$role = $result["role"];
}
return $this->render($template, [
"title" => $title,
"loggedIn" => $loggedIn,
"handle" => $handle,
"role" => $role,
"options" => $options,
]);
}
}