fixes for nav editing

This commit is contained in:
are0h 2022-03-19 19:36:15 -07:00
parent d7c5fb7a70
commit b230f3f15d
9 changed files with 199 additions and 8751 deletions

View file

@ -192,7 +192,6 @@ class DashControl
'title' => 'Reset Password', 'title' => 'Reset Password',
]; ];
break; break;
default: default:
$template = 'dash/start.twig'; $template = 'dash/start.twig';
if (Session::active()) { if (Session::active()) {

View file

@ -2,12 +2,11 @@
namespace brain\data; namespace brain\data;
use brain\data\Contents;
use brain\data\Settings;
use brain\utility\DocTools;
use function _\filter; use function _\filter;
use function _\find; use function _\find;
use brain\utility\DocTools;
use brain\utility\FileUploader;
use brain\utility\StringTools;
class Book class Book
{ {
@ -18,7 +17,8 @@ class Book
public function findPageById(string $uuid) public function findPageById(string $uuid)
{ {
$content = $this->getContents(); $content = $this->getContents();
$page = find($content, ["uuid" => $uuid]); $page = find($content, ['uuid' => $uuid]);
return $page; return $page;
} }
@ -26,9 +26,9 @@ class Book
{ {
$content = $this->getContents(); $content = $this->getContents();
if (isset($slug)) { if (isset($slug)) {
$page = find($content, ["slug" => $slug]); $page = find($content, ['slug' => $slug]);
} else { } else {
$page = find($content, ["layout" => "index"]); $page = find($content, ['layout' => 'index']);
} }
return $page; return $page;
@ -37,7 +37,7 @@ class Book
public function editPage($task, $request) public function editPage($task, $request)
{ {
$content = $this->getContents(); $content = $this->getContents();
if ($task == "delete") { if ($task == 'delete') {
// $parsed = json_decode(file_get_contents("php://input"), true); // $parsed = json_decode(file_get_contents("php://input"), true);
// $body = find($content, ["uuid" => $parsed["id"]]); // $body = find($content, ["uuid" => $parsed["id"]]);
$body = $request->getParsedBody(); $body = $request->getParsedBody();
@ -45,70 +45,70 @@ class Book
$body = $request->getParsedBody(); $body = $request->getParsedBody();
} }
$page = find($content, ["uuid" => $body["uuid"]]); $page = find($content, ['uuid' => $body['uuid']]);
$files = $request->getUploadedFiles(); $files = $request->getUploadedFiles();
$member = Session::get("member"); $member = Session::get('member');
if ($task != "create") { if ($task != 'create') {
$path = $path =
date("Y", date($page["rawCreated"])) . date('Y', date($page['rawCreated'])).
"/" . '/'.
date("m", date($page["rawCreated"])); date('m', date($page['rawCreated']));
} else { } else {
$path = date("Y") . "/" . date("m"); $path = date('Y').'/'.date('m');
} }
$page_feature = ''; $page_feature = '';
$page_files = ''; $page_files = '';
if (isset($files["page_files"])) { if (isset($files['page_files'])) {
$imageList = ""; $imageList = '';
$fileList = ""; $fileList = '';
// var_dump($files["page_files"] ); // var_dump($files["page_files"] );
foreach ($files["page_files"] as $file) { foreach ($files['page_files'] as $file) {
$type = $file->getClientMediaType(); $type = $file->getClientMediaType();
switch ($type) { switch ($type) {
case "image/jpeg": case 'image/jpeg':
case "image/png": case 'image/png':
case "image/gif": case 'image/gif':
case "image/svg": case 'image/svg':
$imagesPath = "/assets/images/blog/" . $path . "/"; $imagesPath = '/assets/images/blog/'.$path.'/';
$imageList = $imageList =
$imageList . $imagesPath . urlencode($file->getClientFileName()) . ", "; $imageList.$imagesPath.urlencode($file->getClientFileName()).', ';
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/images/blog/" . $path . "/", '../public/assets/images/blog/'.$path.'/',
$file $file
); );
break; break;
case "video/mp4": case 'video/mp4':
$videosPath = "/assets/video/blog/" . $path . "/"; $videosPath = '/assets/video/blog/'.$path.'/';
$imageList = $imageList =
$imageList . $videosPath . urlencode($file->getClientFileName()) . ", "; $imageList.$videosPath.urlencode($file->getClientFileName()).', ';
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/video/blog/" . $path . "/", '../public/assets/video/blog/'.$path.'/',
$file $file
); );
break; break;
case "audio/mpeg": case 'audio/mpeg':
$soundPath = "/assets/sound/blog/" . $path . "/"; $soundPath = '/assets/sound/blog/'.$path.'/';
$fileList = $fileList . $soundPath . urlencode($file->getClientFileName()) . ", "; $fileList = $fileList.$soundPath.urlencode($file->getClientFileName()).', ';
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/sound/blog/" . $path . "/", '../public/assets/sound/blog/'.$path.'/',
$file $file
); );
break; break;
case 'application/pdf': case 'application/pdf':
case 'text/plain': case 'text/plain':
case 'text/rtf': case 'text/rtf':
$docPath = "/assets/docs/blog/" . $path . "/"; $docPath = '/assets/docs/blog/'.$path.'/';
$fileList = $fileList . $docPath . urlencode($file->getClientFileName()) . ", "; $fileList = $fileList.$docPath.urlencode($file->getClientFileName()).', ';
FileUploader::uploadFile( FileUploader::uploadFile(
"../public/assets/docs/blog/" . $path . "/", '../public/assets/docs/blog/'.$path.'/',
$file $file
); );
break; break;
@ -118,48 +118,48 @@ class Book
$page_files = $fileList; $page_files = $fileList;
} else { } else {
// if no files, just reset string from page object // if no files, just reset string from page object
$page_feature = $page["feature"]; $page_feature = $page['feature'];
$page_files = $page["files"]; $page_files = $page['files'];
} }
if ($task == "delete") { if ($task == 'delete') {
$deleted = "true"; $deleted = 'true';
$body["menu"] = "false"; $body['menu'] = 'false';
$body["published"] = "false"; $body['published'] = 'false';
$body["featured"] = "false"; $body['featured'] = 'false';
} else { } else {
$deleted = isset($page["deleted"]) ? $page["deleted"] : "false"; $deleted = isset($page['deleted']) ? $page['deleted'] : 'false';
} }
$created = $created =
$task != "create" $task != 'create'
? new \Moment\Moment($page["rawCreated"]) ? new \Moment\Moment($page['rawCreated'])
: new \Moment\Moment(); : new \Moment\Moment();
$updated = new \Moment\Moment(); $updated = new \Moment\Moment();
// grab current index from settings and update // grab current index from settings and update
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex(); $id = $task != 'create' ? $body['id'] : Settings::getCurrentIndex();
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID(); $uuid = $task != 'create' ? $body['uuid'] : StringTools::createUUID();
// now that variables are done, set to body object and then convert to markdown to save // now that variables are done, set to body object and then convert to markdown to save
$body["id"] = $id; $body['id'] = $id;
$body["uuid"] = $uuid; $body['uuid'] = $uuid;
$body["feature"] = $page_feature; $body['feature'] = $page_feature;
$body["files"] = $page_files; $body['files'] = $page_files;
$body["path"] = $path; $body['path'] = $path;
$body["author"] = $member["handle"]; $body['author'] = $member['handle'];
$body["created"] = $created->format("Y-m-d\TH:i:sP"); $body['created'] = $created->format("Y-m-d\TH:i:sP");
$body["updated"] = $updated->format("Y-m-d\TH:i:sP"); $body['updated'] = $updated->format("Y-m-d\TH:i:sP");
$body["deleted"] = $deleted; $body['deleted'] = $deleted;
$write = DocTools::objectToMD($body); $write = DocTools::objectToMD($body);
// if layout is index, change path to file // if layout is index, change path to file
if ($body["layout"] == "index") { if ($body['layout'] == 'index') {
$writePath = "../content/pages/start/index.md"; $writePath = '../content/pages/start/index.md';
} else { } else {
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md"; $writePath = '../content/pages/'.$path.'/'.$body['slug'].'.md';
} }
$status = DocTools::writePages($task, $path, $writePath, $write); $status = DocTools::writePages($task, $path, $writePath, $write);
@ -167,25 +167,25 @@ class Book
if ($status) { if ($status) {
$config = new Settings(); $config = new Settings();
$settings = $config->getSettings(); $settings = $config->getSettings();
$message = ""; $message = '';
if ( if (
$settings["global"]["renderOnSave"] == "true" && $settings['global']['renderOnSave'] == 'true' &&
$settings["global"]["dynamicRender"] == "false" $settings['global']['dynamicRender'] == 'false'
) { ) {
$render = new Render(); $render = new Render();
$render->renderTags(); $render->renderTags();
$render->renderArchive(); $render->renderArchive();
$render->renderPages(); $render->renderPages();
$message = "Filed edited and rendered. NOICE."; $message = 'Filed edited and rendered. NOICE.';
} else { } else {
$message = "File edited. Nice work"; $message = 'File edited. Nice work';
} }
$response = [ $response = [
"message" => $message, 'message' => $message,
"type" => $task == "write" ? "postUpdated" : "postAdded", 'type' => $task == 'write' ? 'postUpdated' : 'postAdded',
"id" => $uuid, 'id' => $uuid,
]; ];
// TODO: When form submission is successful, make new form token // TODO: When form submission is successful, make new form token
@ -194,18 +194,18 @@ class Book
// Session::set("form_token", $form_token); // Session::set("form_token", $form_token);
// once saved, update menu // once saved, update menu
$body["path"] = $path; $body['path'] = $path;
Settings::updateMenu($body); Settings::updateMenu($body);
Settings::updateTags(); Settings::updateTags();
// if new page added, update current index in Settings file // if new page added, update current index in Settings file
if ($task == "create") { if ($task == 'create') {
Settings::updateIndex(); Settings::updateIndex();
} }
} else { } else {
$response = [ $response = [
"message" => "Uh oh. File save problem. Don't panic", 'message' => "Uh oh. File save problem. Don't panic",
"type" => "postError", 'type' => 'postError',
"id" => $uuid, 'id' => $uuid,
]; ];
} }
@ -217,22 +217,22 @@ class Book
$content = $this->getContents(); $content = $this->getContents();
$published = filter($content, function ($item) { $published = filter($content, function ($item) {
return $item["published"] == true && $item["deleted"] == false; return $item['published'] == true && $item['deleted'] == false;
}); });
$deleted = filter($content, function ($item) { $deleted = filter($content, function ($item) {
return $item["deleted"] == true; return $item['deleted'] == true;
}); });
// $all = $content; // $all = $content;
$all = filter($content, function ($item) { $all = filter($content, function ($item) {
return $item["deleted"] == false; return $item['deleted'] == false;
}); });
$filter = isset($sort) ? $sort : "all"; $filter = isset($sort) ? $sort : 'all';
switch ($filter) { switch ($filter) {
case "published": case 'published':
$filtered = $published; $filtered = $published;
break; break;
case "deleted": case 'deleted':
$filtered = $deleted; $filtered = $deleted;
break; break;
default: default:
@ -251,7 +251,7 @@ class Book
if ($range != 0) { if ($range != 0) {
$range = $range + 1; $range = $range + 1;
} }
for ($i = 0; $i <= $limit; $i++) { for ($i = 0; $i <= $limit; ++$i) {
if (isset($filtered[$i + $range])) { if (isset($filtered[$i + $range])) {
array_push($folder, $filtered[$i + $range]); array_push($folder, $filtered[$i + $range]);
} else { } else {
@ -271,26 +271,28 @@ class Book
} }
return [ return [
"pages" => $folder, 'pages' => $folder,
"numOfPages" => $numOfPages, 'numOfPages' => $numOfPages,
"entryCount" => count($filtered), 'entryCount' => count($filtered),
"paginate" => [ 'paginate' => [
"sort" => $sort, 'sort' => $sort,
"nextPage" => $next, 'nextPage' => $next,
"prevPage" => $prev, 'prevPage' => $prev,
], ],
"stats" => [ 'stats' => [
"all" => count($all), 'all' => count($all),
"published" => count($published), 'published' => count($published),
"deleted" => count($deleted), 'deleted' => count($deleted),
], ],
]; ];
} }
public function getContents() public function getContents()
{ {
// test new contents data class // test new contents data class
// $new = (new Contents("../content/pages"))->getAll(); // $new = (new Contents("../content/pages"))->getAll();
$contents = (new Contents("../content/pages"))->getAll(); $contents = (new Contents('../content/pages'))->getAll();
return $contents; return $contents;
} }
} }

View file

@ -1,10 +1,7 @@
<?php <?php
namespace brain\utility namespace brain\utility;
use Psr\Http\Message\UploadedFileInterface;
//define("MAXIMUM_FILESIZE", "10485760"); //10 MB
class FileUploader class FileUploader
{ {
public static function uploadFile(string $directory, $file) public static function uploadFile(string $directory, $file)
@ -24,9 +21,9 @@ class FileUploader
// echo "**FILE** " . $file->getClientFileName(); // echo "**FILE** " . $file->getClientFileName();
$file->moveTo($directory . "/" . urlencode($file->getClientFileName())); $file->moveTo($directory.'/'.urlencode($file->getClientFileName()));
} catch (RuntimeException $e) { } catch (RuntimeException $e) {
echo "ERROR " . $e->getMessage(); echo 'ERROR '.$e->getMessage();
// echo "failed to upload image: " . $e->getMessage(); // echo "failed to upload image: " . $e->getMessage();
// throw new Error("Failed to upload image file"); // throw new Error("Failed to upload image file");

View file

@ -39,5 +39,5 @@
{% endblock %} {% endblock %}
{% block javascripts %} {% block javascripts %}
<script src="/assets/scripts/Start.js" type="text/javascript"></script> <script src="/assets/scripts/Start.js?=cvfggt" type="text/javascript"></script>
{% endblock %} {% endblock %}

View file

@ -1954,22 +1954,9 @@ svg.icons {
-moz-animation: spin 2s linear infinite; -moz-animation: spin 2s linear infinite;
animation: spin 2s linear infinite; animation: spin 2s linear infinite;
} }
@-moz-keyframes spin {
100% {
-moz-transform: rotate(360deg);
}
}
@-webkit-keyframes spin {
100% {
-webkit-transform: rotate(360deg);
}
}
@keyframes spin { @keyframes spin {
100% {
-webkit-transform: rotate(360deg);
transform: rotate(360deg); transform: rotate(360deg);
} }
}
#notifications #notifyMessage .notify-icon { #notifications #notifyMessage .notify-icon {
background: #32302f; background: #32302f;
padding: 8px 5px 5px 5px; padding: 8px 5px 5px 5px;

File diff suppressed because it is too large Load diff

View file

@ -58,7 +58,6 @@ export default class Base {
handleLogin(e) { handleLogin(e) {
if (this.processing) return; if (this.processing) return;
let self = this; let self = this;
e.stopPropagation();
e.preventDefault(); e.preventDefault();
let authForm = data.formDataToJSON(document.getElementById('login')); let authForm = data.formDataToJSON(document.getElementById('login'));
notify.alert('Looking, hold up', null); notify.alert('Looking, hold up', null);

View file

@ -1,8 +1,8 @@
import FipamoAdminAPI, { TASK_SYNC_NAV } from "../../libraries/FipamoAdminAPI"; import FipamoAdminAPI, { TASK_SYNC_NAV } from '../../libraries/FipamoAdminAPI';
import NavActions from "../actions/NavActions"; import NavActions from '../actions/NavActions';
import * as DataEvent from "../events/DataEvent"; import * as DataEvent from '../events/DataEvent';
import Notifications from "../ui/Notifications"; import Notifications from '../ui/Notifications';
import Sortable from "sortablejs"; import Sortable from 'sortablejs';
const notify = new Notifications(); const notify = new Notifications();
export default class NavIndex { export default class NavIndex {
@ -18,12 +18,13 @@ export default class NavIndex {
// methods // methods
//-------------------------- //--------------------------
start() { start() {
//grabs elements and makes them sortables
let self = this; let self = this;
Sortable.create(document.getElementById("nav-pages"), { Sortable.create(document.getElementById('nav-pages'), {
onUpdate: () => { onUpdate: () => {
new NavActions().syncMenu().then((data) => { new NavActions().syncMenu().then(data => {
notify.alert("Updating Menu", null); notify.alert('Updating Menu', null);
self.admin.sync(TASK_SYNC_NAV, data).then((r) => { self.admin.sync(TASK_SYNC_NAV, data).then(r => {
if (r.type == DataEvent.MENU_UPDATED) { if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true); notify.alert(r.message, true);
} else { } else {
@ -33,9 +34,9 @@ export default class NavIndex {
}); });
} }
}); });
var nav = document.querySelectorAll(".nav-btn"); var nav = document.querySelectorAll('.nav-btn');
for (var i = 0, length = nav.length; i < length; i++) { for (var i = 0, length = nav.length; i < length; i++) {
nav[i].addEventListener("click", (e) => this.handleNavButton(e), false); nav[i].addEventListener('click', e => this.handleNavButton(e), false);
} }
} }
//-------------------------- //--------------------------
@ -43,17 +44,17 @@ export default class NavIndex {
//-------------------------- //--------------------------
handleNavButton(e) { handleNavButton(e) {
if (this.processing) return; if (this.processing) return;
let id = ""; let id = '';
let self = this; let self = this;
switch (e.target.id) { switch (e.target.id) {
case "remove-item": case 'remove-item':
id = e.target.getAttribute("data-id"); id = e.target.getAttribute('data-id');
new NavActions().removeItem(id); new NavActions().removeItem(id);
new NavActions().syncMenu().then((data) => { new NavActions().syncMenu().then(data => {
data.remove = e.target.getAttribute("data-uuid"); data.remove = e.target.getAttribute('data-uuid');
notify.alert("Editing Menu", null); notify.alert('Editing Menu', null);
self.processing = true; self.processing = true;
self.admin.syncNav(data).then((r) => { self.admin.sync(TASK_SYNC_NAV, data).then(r => {
self.processing = false; self.processing = false;
if (r.type == DataEvent.MENU_UPDATED) { if (r.type == DataEvent.MENU_UPDATED) {
notify.alert(r.message, true); notify.alert(r.message, true);
@ -63,10 +64,10 @@ export default class NavIndex {
}); });
}); });
break; break;
case "edit-item": case 'edit-item':
self.processing = false; self.processing = false;
window.location = window.location =
"/dashboard/page/edit/" + e.target.getAttribute("data-id"); '/dashboard/page/edit/' + e.target.getAttribute('data-id');
break; break;
} }
} }

View file

@ -45,15 +45,7 @@ svg.icons
-webkit-animation: spin 2s linear infinite -webkit-animation: spin 2s linear infinite
-moz-animation: spin 2s linear infinite -moz-animation: spin 2s linear infinite
animation: spin 2s linear infinite animation: spin 2s linear infinite
@-moz-keyframes spin
100%
-moz-transform: rotate(360deg)
@-webkit-keyframes spin
100%
-webkit-transform: rotate(360deg)
@keyframes spin @keyframes spin
100%
-webkit-transform: rotate(360deg)
transform: rotate(360deg) transform: rotate(360deg)
.notify-icon .notify-icon