added navigation editor template and methods, moved markdown converstion to DocTools class
This commit is contained in:
parent
594df048cf
commit
39809a60ec
8 changed files with 207 additions and 79 deletions
|
@ -51,6 +51,13 @@ class SettingsAPI
|
|||
"type" => "settingsUpdated",
|
||||
];
|
||||
|
||||
break;
|
||||
case "nav-sync":
|
||||
Settings::navSync($body);
|
||||
$result = [
|
||||
"message" => "Navigation updated. Very slick!",
|
||||
"type" => "menuUpdated",
|
||||
];
|
||||
break;
|
||||
default:
|
||||
$result = [
|
||||
|
|
|
@ -43,6 +43,21 @@ class DashControl
|
|||
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;
|
||||
case "pages":
|
||||
if (Session::active()) {
|
||||
|
|
|
@ -114,54 +114,18 @@ class Book
|
|||
//grab current index from settings and update
|
||||
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex();
|
||||
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
||||
$write =
|
||||
"---\n" .
|
||||
"id: " .
|
||||
$id .
|
||||
"\n" .
|
||||
"uuid: " .
|
||||
$uuid .
|
||||
"\n" .
|
||||
"title: " .
|
||||
$body["title"] .
|
||||
"\n" .
|
||||
"feature: " .
|
||||
$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"];
|
||||
// now that variables are done, set to body object and then convert to markdown to save
|
||||
|
||||
$body["id"] = $id;
|
||||
$body["uuid"] = $uuid;
|
||||
$body["feature"] = $feature;
|
||||
$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
|
||||
|
||||
|
@ -270,6 +234,7 @@ class Book
|
|||
}
|
||||
public function getContents()
|
||||
{
|
||||
//move page collection to utiltiy class
|
||||
$parser = new Parser();
|
||||
$contents = [];
|
||||
foreach ($this->files as $file) {
|
||||
|
|
|
@ -49,6 +49,56 @@ class 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()
|
||||
{
|
||||
return $this->themes;
|
||||
|
|
|
@ -33,4 +33,58 @@ class DocTools
|
|||
fwrite($new, json_encode($fileContents));
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
35
brain/views/dash/navigation.twig
Normal file
35
brain/views/dash/navigation.twig
Normal file
|
@ -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() {
|
||||
let navData = [];
|
||||
let items = document.getElementById('nav-pages').children;
|
||||
let items = document.getElementById("nav-pages").children;
|
||||
for (let index = 0; index < items.length; index++) {
|
||||
navData.push({
|
||||
title: items[index].getElementsByTagName('label')[0].innerHTML,
|
||||
title: items[index].getElementsByTagName("label")[0].innerHTML,
|
||||
id: items[index].id,
|
||||
slug: items[index].getAttribute('data-slug'),
|
||||
uuid: items[index].getAttribute('data-uuid'),
|
||||
path: items[index].getAttribute('data-path')
|
||||
slug: items[index].getAttribute("data-slug"),
|
||||
uuid: items[index].getAttribute("data-uuid"),
|
||||
path: items[index].getAttribute("data-path"),
|
||||
});
|
||||
}
|
||||
|
||||
let data = { nav: navData, remove: null };
|
||||
let data = { menu: navData, remove: null };
|
||||
return new Promise(function (resolve) {
|
||||
resolve(data);
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
case "edit-item":
|
||||
window.location =
|
||||
"/@/dashboard/page/edit/" + e.target.getAttribute("data-id");
|
||||
"/dashboard/page/edit/" + e.target.getAttribute("data-id");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue