added navigation editor template and methods, moved markdown converstion to DocTools class

beta
Ro 4 years ago
parent 594df048cf
commit 39809a60ec

@ -51,6 +51,13 @@ class SettingsAPI
"type" => "settingsUpdated", "type" => "settingsUpdated",
]; ];
break;
case "nav-sync":
Settings::navSync($body);
$result = [
"message" => "Navigation updated. Very slick!",
"type" => "menuUpdated",
];
break; break;
default: default:
$result = [ $result = [

@ -43,6 +43,21 @@ class DashControl
die(); die();
} }
break;
case "navigation":
if (Session::active()) {
$config = new Settings();
$settings = $config->getSettings();
$template = "dash/navigation.twig";
$pageOptions = [
"title" => "Edit Dash Navigation",
"status" => Session::active(),
"menu" => $settings["menu"],
];
} else {
header("Location: /dashboard");
die();
}
break; break;
case "pages": case "pages":
if (Session::active()) { if (Session::active()) {

@ -114,54 +114,18 @@ class Book
//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();
$write = // now that variables are done, set to body object and then convert to markdown to save
"---\n" .
"id: " . $body["id"] = $id;
$id . $body["uuid"] = $uuid;
"\n" . $body["feature"] = $feature;
"uuid: " . $body["path"] = $path;
$uuid . $body["author"] = $member["handle"];
"\n" . $body["created"] = $created->format("Y-m-d\TH:i:sP");
"title: " . $body["updated"] = $updated->format("Y-m-d\TH:i:sP");
$body["title"] . $body["deleted"] = $deleted;
"\n" .
"feature: " . $write = DocTools::objectToMD($body);
$feature .
"\n" .
"path: " .
$path .
"\n" .
"layout: " .
$body["layout"] .
"\n" .
"tags: " .
$body["tags"] .
"\n" .
"author: " .
$member["handle"] .
"\n" .
"created: " .
$created->format("Y-m-d\TH:i:sP") .
"\n" .
"updated: " .
$updated->format("Y-m-d\TH:i:sP") .
"\n" .
"deleted: " .
$deleted .
"\n" .
"slug: " .
$body["slug"] .
"\n" .
"menu: " .
$body["menu"] .
"\n" .
"published: " .
$body["published"] .
"\n" .
"featured: " .
$body["featured"] .
"\n---\n" .
$body["content"];
// if layout is index, change path to file // if layout is index, change path to file
@ -270,6 +234,7 @@ class Book
} }
public function getContents() public function getContents()
{ {
//move page collection to utiltiy class
$parser = new Parser(); $parser = new Parser();
$contents = []; $contents = [];
foreach ($this->files as $file) { foreach ($this->files as $file) {

@ -49,6 +49,56 @@ class Settings
DocTools::writeSettings("../config/settings.json", $settings); DocTools::writeSettings("../config/settings.json", $settings);
} }
public static function navSync($data)
{
$settings = self::$settings;
$remove = $data["remove"];
//if remove contains id, find nav item page and set menu to false
if ($remove != null || $remove != "") {
$page = (new Book("../content/pages"))->findPageById($remove);
$page["menu"] = "false";
$page["published"]
? ($page["published"] = "true")
: ($page["published"] = "false");
$page["featured"]
? ($page["featured"] = "true")
: ($page["featured"] = "false");
$page["deleted"]
? ($page["deleted"] = "true")
: ($page["deleted"] = "false");
$updated = new \Moment\Moment();
$created = new \Moment\Moment($page["rawCreated"]);
$page["created"] = $created->format("Y-m-d\TH:i:sP");
$page["updated"] = $updated->format("Y-m-d\TH:i:sP");
$md = DocTools::objectToMD($page);
if ($page["layout"] == "index") {
$writePath = "../content/pages/start/index.md";
} else {
$writePath =
"../content/pages/" . $page["path"] . "/" . $page["slug"] . ".md";
}
DocTools::writePages("write", $page["path"], $writePath, $md);
}
$settings["menu"] = [];
$items = $data["menu"];
foreach ($items as $item) {
array_push($settings["menu"], [
"title" => $item["title"],
"id" => $item["id"],
"uuid" => $item["uuid"],
"slug" => $item["slug"],
"path" => $item["path"],
]);
}
DocTools::writeSettings("../config/settings.json", $settings);
}
public function getThemes() public function getThemes()
{ {
return $this->themes; return $this->themes;

@ -33,4 +33,58 @@ class DocTools
fwrite($new, json_encode($fileContents)); fwrite($new, json_encode($fileContents));
fclose($new); fclose($new);
} }
public static function objectToMD($object)
{
$markdown =
"---\n" .
"id: " .
$object["id"] .
"\n" .
"uuid: " .
$object["uuid"] .
"\n" .
"title: " .
$object["title"] .
"\n" .
"feature: " .
$object["feature"] .
"\n" .
"path: " .
$object["path"] .
"\n" .
"layout: " .
$object["layout"] .
"\n" .
"tags: " .
$object["tags"] .
"\n" .
"author: " .
$object["author"] .
"\n" .
"created: " .
$object["created"] .
"\n" .
"updated: " .
$object["updated"] .
"\n" .
"deleted: " .
$object["deleted"] .
"\n" .
"slug: " .
$object["slug"] .
"\n" .
"menu: " .
$object["menu"] .
"\n" .
"published: " .
$object["published"] .
"\n" .
"featured: " .
$object["featured"] .
"\n---\n" .
$object["content"];
return $markdown;
}
} }

@ -0,0 +1,35 @@
{% extends "dash/_frame.twig" %}
{% block title %}
{{ title }}
{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=adfafd">
{% endblock %}
{% block mainContent %}
<div id="nav-index">
<div id="nav-index-wrapper">
<div id="nav-pages">
{% for item in menu %}
<div id="{{item.id}}" class="nav-item" data-slug="{{item.slug}}" data-uuid="{{item.uuid}}" data-path="{{item.path}}">
<svg id="item-arrows" viewbox="0 0 20 20" class="icons">
<use xlink:href="/assets/images/global/sprite.svg#entypo-select-arrows"/>
</svg>
<label>{{item.title}}</label>
<div id="nav-btns">
<button id="edit-item" class="nav-btn" data-id="{{item.uuid}}">EDIT</button>
<button id="remove-item" class="nav-btn" data-uuid="{{item.uuid}}" data-id="{{item.id}}">REMOVE</button>
</div>
</div>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="/assets/scripts/dash.min.js" type="text/javascript"></script>
{% endblock %}

@ -8,25 +8,27 @@ export default class NavActions {
//-------------------------- //--------------------------
syncMenu() { syncMenu() {
let navData = []; let navData = [];
let items = document.getElementById('nav-pages').children; let items = document.getElementById("nav-pages").children;
for (let index = 0; index < items.length; index++) { for (let index = 0; index < items.length; index++) {
navData.push({ navData.push({
title: items[index].getElementsByTagName('label')[0].innerHTML, title: items[index].getElementsByTagName("label")[0].innerHTML,
id: items[index].id, id: items[index].id,
slug: items[index].getAttribute('data-slug'), slug: items[index].getAttribute("data-slug"),
uuid: items[index].getAttribute('data-uuid'), uuid: items[index].getAttribute("data-uuid"),
path: items[index].getAttribute('data-path') path: items[index].getAttribute("data-path"),
}); });
} }
let data = { nav: navData, remove: null }; let data = { menu: navData, remove: null };
return new Promise(function (resolve) { return new Promise(function (resolve) {
resolve(data); resolve(data);
}); });
} }
removeItem(id) { removeItem(id) {
document.getElementById('nav-pages').removeChild(document.getElementById(id)); document
.getElementById("nav-pages")
.removeChild(document.getElementById(id));
} }
//-------------------------- //--------------------------

@ -61,7 +61,7 @@ export default class NavIndex {
break; break;
case "edit-item": case "edit-item":
window.location = window.location =
"/@/dashboard/page/edit/" + e.target.getAttribute("data-id"); "/dashboard/page/edit/" + e.target.getAttribute("data-id");
break; break;
} }
} }

Loading…
Cancel
Save