fixes for nav editing

pull/84/head
are0h 3 years ago
parent d7c5fb7a70
commit b230f3f15d

@ -158,9 +158,9 @@ class DashControl
$page = $book->findPageById($uuid); $page = $book->findPageById($uuid);
$pageOptions = Sorting::page($page); $pageOptions = Sorting::page($page);
$preview = $preview =
$settings['global']['theme'] . $settings['global']['theme'].
'/' . '/'.
$page['layout'] . $page['layout'].
'.twig'; '.twig';
$html = $display->render($preview, $pageOptions); $html = $display->render($preview, $pageOptions);
$response->getBody()->write($html); $response->getBody()->write($html);
@ -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()) {

@ -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,78 +37,78 @@ 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();
} else { } else {
$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;
@ -117,49 +117,49 @@ class Book
$page_feature = $imageList; $page_feature = $imageList;
$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,45 +167,45 @@ 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
//Session token doesn't reset on the front end, so turning this off for now // Session token doesn't reset on the front end, so turning this off for now
//$form_token = md5(uniqid(microtime(), true)); // $form_token = md5(uniqid(microtime(), true));
//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,11 +251,11 @@ 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 {
//chill out // chill out
} }
} }
} }
@ -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;
} }
} }

@ -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)
@ -12,24 +9,24 @@ class FileUploader
$response = []; $response = [];
try { try {
if (!is_dir($directory)) { if (!is_dir($directory)) {
//Directory does not exist, so lets create it. // Directory does not exist, so lets create it.
mkdir($directory, 0755, true); mkdir($directory, 0755, true);
} }
//$upload = move_uploaded_file($file->getClientFileName(), $directory); // $upload = move_uploaded_file($file->getClientFileName(), $directory);
//$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION); // $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
// see http://php.net/manual/en/function.random-bytes.php // see http://php.net/manual/en/function.random-bytes.php
//$basename = bin2hex(random_bytes(8)); // $basename = bin2hex(random_bytes(8));
//$filename = sprintf("%s.%0.8s", $basename, $extension); // $filename = sprintf("%s.%0.8s", $basename, $extension);
//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");
} }
} }
} }

@ -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 %}

@ -1954,21 +1954,8 @@ 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% { transform: rotate(360deg);
-webkit-transform: rotate(360deg);
transform: rotate(360deg);
}
} }
#notifications #notifyMessage .notify-icon { #notifications #notifyMessage .notify-icon {
background: #32302f; background: #32302f;

File diff suppressed because it is too large Load Diff

@ -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);

@ -1,73 +1,74 @@
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 {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.processing = false; this.processing = false;
this.admin = new FipamoAdminAPI(null); this.admin = new FipamoAdminAPI(null);
this.start(); this.start();
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() { start() {
let self = this; //grabs elements and makes them sortables
Sortable.create(document.getElementById("nav-pages"), { let self = this;
onUpdate: () => { Sortable.create(document.getElementById('nav-pages'), {
new NavActions().syncMenu().then((data) => { onUpdate: () => {
notify.alert("Updating Menu", null); new NavActions().syncMenu().then(data => {
self.admin.sync(TASK_SYNC_NAV, data).then((r) => { notify.alert('Updating Menu', null);
if (r.type == DataEvent.MENU_UPDATED) { self.admin.sync(TASK_SYNC_NAV, data).then(r => {
notify.alert(r.message, true); if (r.type == DataEvent.MENU_UPDATED) {
} else { notify.alert(r.message, true);
notify.alert(r.message, true); } else {
} notify.alert(r.message, true);
}); }
}); });
} });
}); }
var nav = document.querySelectorAll(".nav-btn"); });
for (var i = 0, length = nav.length; i < length; i++) { var nav = document.querySelectorAll('.nav-btn');
nav[i].addEventListener("click", (e) => this.handleNavButton(e), false); for (var i = 0, length = nav.length; i < length; i++) {
} nav[i].addEventListener('click', e => this.handleNavButton(e), false);
} }
//-------------------------- }
// event handlers //--------------------------
//-------------------------- // event handlers
handleNavButton(e) { //--------------------------
if (this.processing) return; handleNavButton(e) {
let id = ""; if (this.processing) return;
let self = this; let id = '';
switch (e.target.id) { let self = this;
case "remove-item": switch (e.target.id) {
id = e.target.getAttribute("data-id"); case 'remove-item':
new NavActions().removeItem(id); id = e.target.getAttribute('data-id');
new NavActions().syncMenu().then((data) => { new NavActions().removeItem(id);
data.remove = e.target.getAttribute("data-uuid"); new NavActions().syncMenu().then(data => {
notify.alert("Editing Menu", null); data.remove = e.target.getAttribute('data-uuid');
self.processing = true; notify.alert('Editing Menu', null);
self.admin.syncNav(data).then((r) => { self.processing = true;
self.processing = false; self.admin.sync(TASK_SYNC_NAV, data).then(r => {
if (r.type == DataEvent.MENU_UPDATED) { self.processing = false;
notify.alert(r.message, true); if (r.type == DataEvent.MENU_UPDATED) {
} else { notify.alert(r.message, true);
notify.alert(r.message, true); } else {
} notify.alert(r.message, true);
}); }
}); });
break; });
case "edit-item": break;
self.processing = false; case 'edit-item':
window.location = self.processing = false;
"/dashboard/page/edit/" + e.target.getAttribute("data-id"); window.location =
break; '/dashboard/page/edit/' + e.target.getAttribute('data-id');
} break;
} }
}
} }

@ -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 @keyframes spin
100%
-moz-transform: rotate(360deg)
@-webkit-keyframes spin
100%
-webkit-transform: rotate(360deg)
@keyframes spin
100%
-webkit-transform: rotate(360deg)
transform: rotate(360deg) transform: rotate(360deg)
.notify-icon .notify-icon

Loading…
Cancel
Save