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

@ -11,9 +11,9 @@ section[role="den-login"] div[role="system-notice"] {
color: var(--primary);
}
section[role="den-index"],
section[role="loc-index"] {
section[role="den-index"] {
padding: 20px;
color: var(--white);
}
section a {

View file

@ -0,0 +1,27 @@
section[role="loc-index"] {
padding: 20px;
}
section[role="loc-index"] img {
width: 150px;
vertical-align: top;
border-radius: 3px;
}
section[role="loc-index"] label {
color: var(--white);
}
section[role="loc-index"] input {
width: 290px;
}
section[role="loc-index"] textarea {
width: 290px;
padding: 5px;
height: 100px;
}
section[role="loc-index"] select {
width: 150px;
}

View file

@ -0,0 +1,7 @@
@import "../global/colors.css";
@import "../global/forms.css";
@import "../global/typography.css";
@import "../global/frame.css";
@import "../global/icons.css";
@import "locations.css";
@import "index.css";

View file

@ -1,6 +1,7 @@
@import url("colors.css");
@import url("forms.css");
@import url("typography.css");
@import url("frame.css");
@import url("index.css");
@import url("index-den.css");
@import "../global/colors.css";
@import "../global/forms.css";
@import "../global/typography.css";
@import "../global/frame.css";
@import "../global/icons.css";
@import "index.css";

View file

@ -28,6 +28,10 @@ header > nav {
padding: 10px;
}
header > nav i {
font-size: 1.3em;
}
header > nav > div[role="nav-right"] {
text-align: right;
}

File diff suppressed because it is too large Load diff

Binary file not shown.

Binary file not shown.

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();
$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"
]);
} else {
return $this->render("back/locations.twig", [
$options = [];
if ($mode == 'add') {
$options = [
"title" => "Bad Space | Locations | Add",
"notice" => $response["message"],
"mode" => "add"
"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 | Error",
"notice" => $response["message"],
"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;
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->setUpdatedAt(new \DateTimeImmutable());
if ($action == "add") {
$location->setUuid(Uuid::v4());
$location->setActive(false);
$location->setCreatedAt(new \DateTimeImmutable());
$location->setUpdatedAt(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,
]);
}
}

View file

@ -1,9 +1,20 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=dfadf">
<link rel="stylesheet" type="text/css" href="/assets/css/back/start.css?=qwert">
{% endblock %}
{% block main %}
{% if loggedIn %}
<section role="den-index">
<h1>
Welcome to the Den,
{{ handle }}
</h1>
Remember to pace yourself because you're working with some of the worse places on the web. Drink water, takes lot of breaks and remember you are the reason the interent is becoming safer.
</section>
{% else %}
<section role="den-login">
<h1>This is the Den</h1><br/>
{% if notice is defined %}
@ -13,4 +24,7 @@
{% endif %}
{{ include("forms/login-form.twig") }}
</section>
{% endif %}
{% endblock %}

View file

@ -1,6 +1,6 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=sdfsdf">
<link rel="stylesheet" type="text/css" href="/assets/css/back/start.css?=qwert">
{% endblock %}
{% block main %}
@ -14,26 +14,31 @@
</div>
{% endif %}
{% if mode == "add" %}
{% if options.mode == "add" %}
<h2>Add New Location</h2>
{{ include("forms/add-location.twig") }}
{% elseif mode =='bulk-add' %}
{% elseif options.mode =='bulk-add' %}
<h2>Add Multiple Locations</h2>
{{ include("forms/bulk-add-location.twig") }}
{% elseif mode == "edit" %}
{% elseif options.mode == "edit" %}
<h2>Editing
{{ location.name }}</h2>
{{ options.location.name }}</h2>
{% for image in options.location.images %}
<a target="_blank" href="/assets/images/examples/{{ image.path }}">
<img src="/assets/images/examples/{{ image.path }}"/>
</a>
{% endfor %}
{{ include("forms/edit-location.twig") }}
{% else %}
<h2>Take care. These are bad places.</h2>
<a href="/den/locations/add">Add Location</a>
<a href="/den/locations/modify/add">Add Location</a>
|
<a href="/den/locations/bulk-add">Add Multiple Locations</a>
<br>
<h3>Bad Spaces</h3>
{% for location in list.locations %}
{% for location in options.list.locations %}
<sup>ID:{{ location.id }}</sup>
<a href="/den/locations/edit/{{ location.uuid }}">
<a href="/den/locations/modify/edit/{{ location.uuid }}">
{{ location.name }}</a><br/>
{% endfor %}

View file

@ -1,6 +1,6 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=sdfsdf">
<link rel="stylesheet" type="text/css" href="/assets/css/back/start.css?=qwert">
{% endblock %}
{% block main %}

View file

@ -1,14 +0,0 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=dfdferer">
{% endblock %}
{% block main %}
<section role="den-index">
<h1>
Welcome to the Den.
</h1>
Remember to pace yourself because you're working with some of the worse places on the web. Drink water, takes lot of breaks and remember you are the reason the interent is becoming safer.
</section>
{% endblock %}

View file

@ -13,28 +13,33 @@
<header>
<nav>
<div role="nav-left">
<a href="/den">The Bad Space</a>
<i class="ti ti-biohazard-off"></i>
<a href="/">The Bad Space</a>
</div>
<div role="nav-right">
<div role="nav-right"></a>
{% if handle is defined %}
<strong>Hey
{{ handle }}
</strong>
{% if loggedIn == true %}
<a href="/den" title="den index">
<i class="ti ti-door" title="den index"></i>
</a>
<a href="/den/members" title="members">
<i class="ti ti-users" title="members"></i>
</a>
<a href="/den/locations/page/1" title="locations">
<i class="ti ti-list-details" title="locations"></i>
</a>
<a href="/logout" title="logout">
<i class="ti ti-door-exit" title="logout"></i>
</a>
{% else %}
<a href="/den" title="login">
<i class="ti ti-door-enter" title="login"></i>
</a>
{% endif %}
<a href="/den/members">Members
</a>
<a href="/den/locations/page/1">Locations
</a>
<a href="/logout">Bye</a>
</div>
</nav>
</header>
<main>
{% block main %}{% endblock %}
</main>
{% block javascripts %}{% endblock %}
</body>
</html>
</html></header><main>
{% block main %}{% endblock %}</main>{% block javascripts %}{% endblock %}</body></html>

View file

@ -1,4 +1,4 @@
<form action="{{ path('location-add') }}" method="post" enctype="multipart/form-data">
<form action="{{ path('location-modify') }}" method="post" enctype="multipart/form-data">
<div>
<label>Name</label><br/>
<input type="text" name="loc_name" value=""/>
@ -24,4 +24,5 @@
<input type="file" id="loc_examples" name="loc_examples[]" multiple/>
</div>
<input type="hidden" name="token" value="{{ csrf_token('upload') }}"/>
<input type="hidden" name="mode" value="add"/>
<input type="submit" value="Edit Location" name="submit_button"></form>

View file

@ -1,20 +1,20 @@
<form action="{{ path('location-edit') }}" method="post" enctype="multipart/form-data">
<form name="edit" action="{{ path('location-modify') }}" method="post" enctype="multipart/form-data">
<div>
<label>Name</label><br/>
<input type="text" name="loc_name" value="{{ location.name }}"/>
<input type="text" name="loc_name" value="{{ options.location.name }}"/>
<br/>
<label>URL</label><br/>
<input type="text" name="loc_url" value="{{ location.url }}"/>
<input type="text" name="loc_url" value="{{ options.location.url }}"/>
<br/>
<label>Tags</label><br/>
<input type="text" name="loc_tags" value="{{ location.tags }}"/>
<input type="text" name="loc_tags" value="{{ options.location.tags }}"/>
<br/>
<label>Description</label><br/>
<textarea name="loc_desc">{{ location.description }}</textarea>
<textarea name="loc_desc">{{ options.location.description }}</textarea>
<br/>
<label>Rating</label><br/>
<select name="rating">
{% if location.rating == "silence" %}
{% if options.location.rating == "silence" %}
<option value="silence" selected>Silence</option>
<option value="defederate">Defederate</option>
{% else %}
@ -24,7 +24,7 @@
</select><br/>
<label>Include in search results</label><br/>
<select name="active">
{% if location.active %}
{% if options.location.active %}
<option value="false">No</option>
<option value="true" selected>Yes</option>
{% else %}
@ -37,4 +37,6 @@
<input type="file" id="loc_examples" name="loc_examples[]" multiple/>
</div>
<input type="hidden" name="token" value="{{ csrf_token('upload') }}"/>
<input type="hidden" name="mode" value="edit"/>
<input type="hidden" name="uuid" value="{{ options.location.uuid }}"/>
<input type="submit" value="Edit Location" name="submit_button"></form>

View file

@ -9,5 +9,6 @@
Because some people are just awful humans.
<p>Coming Soonish...
</p>
</section>
{% endblock %}

View file

@ -1,10 +0,0 @@
{% extends "base/frame.twig" %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/front/start.css?=sdfsdf">
{% endblock %}
{% block main %}
<section role="intro">
This is where you login
</section>
{% endblock %}