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);
$pageOptions = Sorting::page($page);
$preview =
$settings['global']['theme'] .
'/' .
$page['layout'] .
$settings['global']['theme'].
'/'.
$page['layout'].
'.twig';
$html = $display->render($preview, $pageOptions);
$response->getBody()->write($html);
@ -192,7 +192,6 @@ class DashControl
'title' => 'Reset Password',
];
break;
default:
$template = 'dash/start.twig';
if (Session::active()) {

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

@ -1,10 +1,7 @@
<?php
namespace brain\utility
namespace brain\utility;
use Psr\Http\Message\UploadedFileInterface;
//define("MAXIMUM_FILESIZE", "10485760"); //10 MB
class FileUploader
{
public static function uploadFile(string $directory, $file)
@ -12,24 +9,24 @@ class FileUploader
$response = [];
try {
if (!is_dir($directory)) {
//Directory does not exist, so lets create it.
// Directory does not exist, so lets create it.
mkdir($directory, 0755, true);
}
//$upload = move_uploaded_file($file->getClientFileName(), $directory);
//$extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
// $upload = move_uploaded_file($file->getClientFileName(), $directory);
// $extension = pathinfo($file->getClientFilename(), PATHINFO_EXTENSION);
// see http://php.net/manual/en/function.random-bytes.php
//$basename = bin2hex(random_bytes(8));
//$filename = sprintf("%s.%0.8s", $basename, $extension);
// see http://php.net/manual/en/function.random-bytes.php
// $basename = bin2hex(random_bytes(8));
// $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) {
echo "ERROR " . $e->getMessage();
echo 'ERROR '.$e->getMessage();
//echo "failed to upload image: " . $e->getMessage();
//throw new Error("Failed to upload image file");
// echo "failed to upload image: " . $e->getMessage();
// throw new Error("Failed to upload image file");
}
}
}

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

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

File diff suppressed because it is too large Load Diff

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

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

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

Loading…
Cancel
Save