page editing cleaned up, fixed date formatting, fixed page filtering, add Image API path

beta
Ro 4 years ago
parent 395850adb8
commit 1b9252fef0

@ -0,0 +1,30 @@
<?php
class ImagesAPI
{
public function __construct()
{
}
public static function uploadImage($request)
{
$image = $request->getUploadedFiles();
$path = date("Y") . "/" . date("m");
$uploadPath = "../public/assets/images/blog/" . $path;
FileUploader::uploadFile($uploadPath, $image["post_image"]);
$response = [
"message" => "Image Added. Very slick",
"type" => "postImageAdded",
"url" =>
"/assets/images/blog/" .
$path .
"/" .
$image["post_image"]->getClientFileName(),
];
return $response;
}
}

@ -2,7 +2,7 @@
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
//include "brain/data/Auth.inc.php"; include "../brain/api/v1/ImagesAPI.inc.php";
class APIControl class APIControl
{ {
@ -18,7 +18,6 @@ class APIControl
default: default:
break; break;
} }
$response->getBody()->write(json_encode($result)); $response->getBody()->write(json_encode($result));
return $response->withHeader("Content-Type", "application/json"); return $response->withHeader("Content-Type", "application/json");
} }
@ -43,6 +42,33 @@ class APIControl
break; break;
case "logout": case "logout":
$result = Auth::logout($body); $result = Auth::logout($body);
break;
case "page":
//move methdology to its own API class
$task = $args["fourth"];
$token = $request->getHeader("fipamo-access-token");
if (Session::verifyToken($token[0])) {
switch ($task) {
case "delete":
case "add":
case "edit":
$result = (new Book("../content/pages"))->editPage(
$task,
$request
);
break;
case "add-entry-image":
$result = ImagesAPI::uploadImage($request);
break;
}
} else {
$result = [
"message" => "API access denied, homie",
"type" => "API_ERROR",
];
}
break; break;
default: default:
$result = [ $result = [

@ -18,7 +18,12 @@ class DashControl
switch (isset($args["second"]) ? $args["second"] : "index") { switch (isset($args["second"]) ? $args["second"] : "index") {
case "pages": case "pages":
$currentPage = isset($args["fourth"]) ? $args["fourth"] : 1; $currentPage = isset($args["fourth"]) ? $args["fourth"] : 1;
$data = (new Book("../content/pages"))->getPages($currentPage, 4); $filter = isset($args["third"]) ? $args["third"] : "all";
$data = (new Book("../content/pages"))->getPages(
$currentPage,
4,
$filter
);
$template = "dash/book.twig"; $template = "dash/book.twig";
$pageOptions = [ $pageOptions = [
"entryCount" => $data["entryCount"], "entryCount" => $data["entryCount"],

@ -33,23 +33,157 @@ class Book
return $page; return $page;
} }
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"]]);
} else {
$body = $request->getParsedBody();
}
$page = find($content, ["uuid" => $body["uuid"]]);
$image = $request->getUploadedFiles();
$member = Session::get("member");
if ($task != "add") {
$path =
date("Y", date($page["rawCreated"])) .
"/" .
date("m", date($page["rawCreated"]));
} else {
$path = date("Y", date()) . "/" . date("m");
}
if (isset($image["feature_image"])) {
$feature = $image["feature_image"]->getClientFileName();
FileUploader::uploadFile(
"../public/assets/images/blog/" . $path . "/",
$image["feature_image"]
);
} else {
if (isset($body["feature_image"])) {
$url = explode("/", $body["feature_image"]);
$feature =
"/" .
$url[3] .
"/" .
$url[4] .
"/" .
$url[5] .
"/" .
$url[6] .
"/" .
$url[7] .
"/" .
$url[8];
} else {
$feature = $body["feature"];
}
}
if ($task == "delete") {
$deleted = "true";
$body["menu"] ? ($body["menu"] = "true") : ($body["menu"] = "false");
$body["published"]
? ($body["published"] = "true")
: ($body["published"] = "false");
$body["featured"]
? ($body["featured"] = "true")
: ($body["featured"] = "false");
} else {
$deleted = !$page["deleted"] ? "false" : $page["deleted"];
}
$created =
$task != "add"
? new \Moment\Moment($page["rawCreated"])
: new \Moment\Moment();
$updated = new \Moment\Moment();
$write =
"---\n" .
"id: " .
$body["id"] .
"\n" .
"uuid: " .
$body["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"];
// if layout is index, change path to file
if ($body["layout"] == "index") {
$writePath = "../content/start/index.md";
} else {
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
}
($new = fopen($writePath, "w")) or die("Unable to open file!");
fwrite($new, $write);
fclose($new);
$response = [
"message" => "File edited. Nice work",
"type" => $task == "write" ? "postUpdated" : "postAdded",
];
return $response;
}
public function getPages(int $page, int $limit, string $sort = null) public function getPages(int $page, int $limit, string $sort = null)
{ {
$content = $this->getContents(); $content = $this->getContents();
$published = filter($content, function ($item) { $published = filter($content, function ($item) {
return $item["published"] == "true"; return $item["published"] == true && $item["deleted"] == false;
}); });
$deleted = filter($content, function ($item) { $deleted = filter($content, function ($item) {
return $item["deleted"]; return $item["deleted"] == true;
}); });
$all = $content; $all = $content;
$filter = isset($sort) ? $sort : "all"; $filter = isset($sort) ? $sort : "all";
//echo $filter;
$filtered = [];
switch ($filter) { switch ($filter) {
case "published": case "published":
$filtered = $published; $filtered = $published;
@ -61,9 +195,7 @@ class Book
$filtered = $content; $filtered = $content;
break; break;
} }
$numOfPages = ceil(count($filtered) / $limit); $numOfPages = ceil(count($filtered) / $limit);
$folder = []; $folder = [];
if (count($filtered) != 0) { if (count($filtered) != 0) {
@ -99,7 +231,7 @@ class Book
"numOfPages" => $numOfPages, "numOfPages" => $numOfPages,
"entryCount" => count($filtered), "entryCount" => count($filtered),
"paginate" => [ "paginate" => [
"sort" => $filter, "sort" => $sort,
"nextPage" => $next, "nextPage" => $next,
"prevPage" => $prev, "prevPage" => $prev,
], ],
@ -116,7 +248,6 @@ class Book
$contents = []; $contents = [];
foreach ($this->files as $file) { foreach ($this->files as $file) {
$doc = $parser->parse(file_get_contents($file), false); $doc = $parser->parse(file_get_contents($file), false);
$meta = $doc->getYAML(); $meta = $doc->getYAML();
$page = [ $page = [
"id" => $meta["id"], "id" => $meta["id"],
@ -129,6 +260,8 @@ class Book
"author" => $meta["author"], "author" => $meta["author"],
"created" => date("Y M D d", $meta["created"]), "created" => date("Y M D d", $meta["created"]),
"updated" => date("Y M D d", $meta["updated"]), "updated" => date("Y M D d", $meta["updated"]),
"rawCreated" => $meta["created"],
"rawUpdated" => $meta["updated"],
"deleted" => $meta["deleted"], "deleted" => $meta["deleted"],
"menu" => $meta["menu"], "menu" => $meta["menu"],
"featured" => $meta["featured"], "featured" => $meta["featured"],
@ -137,7 +270,6 @@ class Book
"filePath" => $file, "filePath" => $file,
"content" => $doc->getContent(), "content" => $doc->getContent(),
]; ];
//checks for duplicates //checks for duplicates
$uuid = $meta["uuid"]; $uuid = $meta["uuid"];
$found = current( $found = current(

@ -38,6 +38,24 @@ class Session
} }
} }
public static function verifyToken($token)
{
$data = json_decode(file_get_contents(self::$file), true);
if ($data["member"] != null) {
$secret = (new Settings())->getFolks("secret");
if (
Token::validate($token, $secret) &&
Token::validateExpiration($token, $secret)
) {
return true;
} else {
return false;
}
} else {
return false;
}
}
public static function set($key, $value) public static function set($key, $value)
{ {
$data = json_decode(file_get_contents(self::$file), true); $data = json_decode(file_get_contents(self::$file), true);

@ -0,0 +1,29 @@
<?php
use Psr\Http\Message\UploadedFileInterface;
//include "brain/data/Auth.inc.php";
class FileUploader
{
public static function uploadFile(
string $directory,
UploadedFileInterface $file
) {
try {
if (!is_dir($directory)) {
//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);
// see http://php.net/manual/en/function.random-bytes.php
//$basename = bin2hex(random_bytes(8));
//$filename = sprintf("%s.%0.8s", $basename, $extension);
$file->moveTo($directory . "/" . $file->getClientFileName());
} catch (Error $e) {
echo "failed to upload image: " . $e->getMessage();
throw new Error("Failed to upload image file");
}
}
}

@ -7,6 +7,7 @@
{% set id = page['id'] %} {% set id = page['id'] %}
{% set uuid = page['uuid'] %} {% set uuid = page['uuid'] %}
{% set slug = page['slug'] %} {% set slug = page['slug'] %}
{% set layout = page['layout'] %}
{% set feature = page['feature'] %} {% set feature = page['feature'] %}
{% set _title = page['title'] %} {% set _title = page['title'] %}
{% set tags = page['tags'] %} {% set tags = page['tags'] %}
@ -16,6 +17,7 @@
{% set id = '' %} {% set id = '' %}
{% set uuid = '' %} {% set uuid = '' %}
{% set slug = '' %} {% set slug = '' %}
{% set layout = 'pages' %}
{% set feature = '' %} {% set feature = '' %}
{% set title = '' %} {% set title = '' %}
{% set tags = '' %} {% set tags = '' %}
@ -32,7 +34,7 @@
{% endblock %} {% endblock %}
{% block mainContent %} {% block mainContent %}
<div id="post-edit-index" data-index="{{ id }}" data-uuid="{{ uuid }}" data-slug="{{ slug }}"> <div id="post-edit-index" data-index="{{ id }}" data-uuid="{{ uuid }}" data-slug="{{ slug }}" data-layout="{{ layout }}">
<div id="post-edit-index-wrapper"> <div id="post-edit-index-wrapper">
<div id="post-feature"> <div id="post-feature">
{% if page['feature'] == null %} {% if page['feature'] == null %}

@ -6,6 +6,7 @@
"slim/twig-view": "^3.0", "slim/twig-view": "^3.0",
"mnapoli/front-yaml": "^1.8", "mnapoli/front-yaml": "^1.8",
"lodash-php/lodash-php": "^0.0.7", "lodash-php/lodash-php": "^0.0.7",
"rbdwllr/reallysimplejwt": "^4.0" "rbdwllr/reallysimplejwt": "^4.0",
"fightbulc/moment": "^1.33"
} }
} }

59
composer.lock generated

@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "0e243f32e05cb4ef6265ce19f141fdae", "content-hash": "d5ef6d43f774049d093af6375d20ac11",
"packages": [ "packages": [
{ {
"name": "erusev/parsedown", "name": "erusev/parsedown",
@ -112,6 +112,63 @@
}, },
"time": "2020-11-24T22:02:12+00:00" "time": "2020-11-24T22:02:12+00:00"
}, },
{
"name": "fightbulc/moment",
"version": "1.33.0",
"source": {
"type": "git",
"url": "https://github.com/fightbulc/moment.php.git",
"reference": "435d68e481ab0a716358926fb51966e696d297e3"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/fightbulc/moment.php/zipball/435d68e481ab0a716358926fb51966e696d297e3",
"reference": "435d68e481ab0a716358926fb51966e696d297e3",
"shasum": ""
},
"require": {
"php": ">=5.3.0"
},
"require-dev": {
"phpunit/phpunit": "^4.8.36 || ^5.5 || ^6.5 || ^7.5 || ^9.0"
},
"type": "library",
"autoload": {
"psr-4": {
"Moment\\": "src/"
}
},
"notification-url": "https://packagist.org/downloads/",
"license": [
"MIT"
],
"authors": [
{
"name": "Tino Ehrich",
"email": "tino@bigpun.me",
"role": "developer"
}
],
"description": "Parse, validate, manipulate, and display dates in PHP w/ i18n support. Inspired by moment.js",
"keywords": [
"date",
"display",
"format",
"i18n",
"locale",
"manipulate",
"moment",
"parse",
"time",
"translation",
"validate"
],
"support": {
"issues": "https://github.com/fightbulc/moment.php/issues",
"source": "https://github.com/fightbulc/moment.php/tree/1.33.0"
},
"time": "2021-03-27T13:10:08+00:00"
},
{ {
"name": "lodash-php/lodash-php", "name": "lodash-php/lodash-php",
"version": "0.0.7", "version": "0.0.7",

@ -11,13 +11,14 @@ include "../brain/controller/RouteControl.inc.php";
include "../brain/data/Auth.inc.php"; include "../brain/data/Auth.inc.php";
include "../brain/utility/StringTools.inc.php"; include "../brain/utility/StringTools.inc.php";
include "../brain/data/Session.inc.php"; include "../brain/data/Session.inc.php";
include "../brain/utility/FileUploader.inc.php";
$app = AppFactory::create(); $app = AppFactory::create();
$twig = Twig::create("../brain/views/"); $twig = Twig::create("../brain/views/");
$app->add(TwigMiddleware::create($app, $twig)); $app->add(TwigMiddleware::create($app, $twig));
//set up routing //set up routing
$app->get("/[{first}[/{second}[/{third}[/{fourth}]]]]", "\RouteControl:get"); $app->get("/[{first}[/{second}[/{third}[/{fourth}]]]]", "\RouteControl:get");
$app->post("/[{first}[/{second}[/{third}[/{fourt}]]]]", "\RouteControl:post"); $app->post("/[{first}[/{second}[/{third}[/{fourth}]]]]", "\RouteControl:post");
//start the app //start the app
$app->run(); $app->run();

@ -1,41 +1,41 @@
import PostIndex from './PostIndex'; import PostIndex from "./PostIndex";
import SettingsIndex from './SettingsIndex'; import SettingsIndex from "./SettingsIndex";
import NaviIndex from './NavIndex'; import NaviIndex from "./NavIndex";
export default class DashManager { export default class DashManager {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
this.currentDisplay = ''; this.currentDisplay = "";
this.urlPieces = document.URL.split('/'); this.urlPieces = document.URL.split("/");
this.chooseDisplay(this.urlPieces[5], this.urlPieces[6]); this.chooseDisplay(this.urlPieces[4], this.urlPieces[5]);
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() {} start() {}
chooseDisplay(section, page) { chooseDisplay(section, page) {
this.currentDisplay = ''; this.currentDisplay = "";
switch (section) { switch (section) {
case 'page': case "page":
this.currentDisplay = new PostIndex(page); this.currentDisplay = new PostIndex(page);
break; break;
case 'settings': case "settings":
this.currentDisplay = new SettingsIndex(); this.currentDisplay = new SettingsIndex();
break; break;
case 'navigation': case "navigation":
this.currentDisplay = new NaviIndex(); this.currentDisplay = new NaviIndex();
break; break;
default: default:
//just chill //just chill
break; break;
} }
this.start(); this.start();
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
} }

@ -1,70 +1,74 @@
//TOOLS //TOOLS
import FipamoAdminAPI, { import FipamoAdminAPI, {
TASK_PAGE_CREATE, TASK_PAGE_CREATE,
TASK_PAGE_EDIT, TASK_PAGE_EDIT,
TASK_PAGE_DELETE TASK_PAGE_DELETE,
} from '../../libraries/FipamoAdminAPI'; } from "../../libraries/FipamoAdminAPI";
import * as DataEvent from '../events/DataEvent'; import * as DataEvent from "../events/DataEvent";
import PageActions from '../actions/PageActions'; import PageActions from "../actions/PageActions";
import * as EditorEvent from '../events/EditorEvent'; import * as EditorEvent from "../events/EditorEvent";
//import TinyDatePicker from 'tiny-date-picker'; //import TinyDatePicker from 'tiny-date-picker';
import TextEditor from '../ui/TextEditor'; import TextEditor from "../ui/TextEditor";
import Notfications from '../ui/Notifications'; import Notfications from "../ui/Notifications";
const admin = new FipamoAdminAPI(); const admin = new FipamoAdminAPI();
const notify = new Notfications(); const notify = new Notfications();
export default class PostEditor { export default class PostEditor {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor() { constructor() {
let self = this; let self = this;
this.urlPieces = document.URL.split('/'); this.urlPieces = document.URL.split("/");
this.post = []; this.post = [];
this.postID = null; this.postID = null;
this.postUUID = null; this.postUUID = null;
this.postLayout = null; this.postLayout = null;
if (document.getElementById('post-edit-index').getAttribute('data-index')) { if (document.getElementById("post-edit-index").getAttribute("data-index")) {
this.postID = document.getElementById('post-edit-index').getAttribute('data-index'); this.postID = document
this.postUUID = document.getElementById('post-edit-index').getAttribute('data-uuid'); .getElementById("post-edit-index")
this.postLayout = document .getAttribute("data-index");
.getElementById('post-edit-index') this.postUUID = document
.getAttribute('data-layout'); .getElementById("post-edit-index")
} .getAttribute("data-uuid");
if (document.getElementById('edit-post-text')) { this.postLayout = document
this.editor = new TextEditor( .getElementById("post-edit-index")
document.getElementById('edit-post-text'), .getAttribute("data-layout");
document.getElementById('header').offsetHeight + }
document.getElementById('post-header').offsetHeight + if (document.getElementById("edit-post-text")) {
document.getElementById('post-feature').offsetHeight this.editor = new TextEditor(
); document.getElementById("edit-post-text"),
this.editor.addListener( document.getElementById("header").offsetHeight +
EditorEvent.EDITOR_DELETE, document.getElementById("post-header").offsetHeight +
() => this.handleEditorOptions(EditorEvent.EDITOR_DELETE), document.getElementById("post-feature").offsetHeight
false );
); this.editor.addListener(
this.editor.addListener( EditorEvent.EDITOR_DELETE,
EditorEvent.EDITOR_UPLOAD_POST_IMAGE, () => this.handleEditorOptions(EditorEvent.EDITOR_DELETE),
() => this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE), false
false );
); this.editor.addListener(
this.editor.addListener( EditorEvent.EDITOR_UPLOAD_POST_IMAGE,
EditorEvent.EDITOR_UPDATE, () => this.handleEditorOptions(EditorEvent.EDITOR_UPLOAD_POST_IMAGE),
() => this.handleEditorOptions(EditorEvent.EDITOR_UPDATE), false
false );
); this.editor.addListener(
this.editor.addListener( EditorEvent.EDITOR_UPDATE,
EditorEvent.EDITOR_SAVE, () => this.handleEditorOptions(EditorEvent.EDITOR_UPDATE),
() => this.handleEditorOptions(EditorEvent.EDITOR_SAVE), false
false );
); this.editor.addListener(
document.getElementById('post-image-upload').addEventListener( EditorEvent.EDITOR_SAVE,
'change', () => this.handleEditorOptions(EditorEvent.EDITOR_SAVE),
e => { false
self.handleImageUpload(e.target.id, e.target.files); );
}, document.getElementById("post-image-upload").addEventListener(
false "change",
); (e) => {
/* self.handleImageUpload(e.target.id, e.target.files);
},
false
);
/*
TinyDatePicker(document.getElementById('post-date'), { TinyDatePicker(document.getElementById('post-date'), {
mode: 'dp-below', mode: 'dp-below',
format() { format() {
@ -73,170 +77,180 @@ export default class PostEditor {
}); });
*/ */
this.start(); this.start();
} }
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() { start() {
if (document.getElementById('featured-image-drop')) { if (document.getElementById("featured-image-drop")) {
document document
.getElementById('featured-image-drop') .getElementById("featured-image-drop")
.addEventListener('dragover', this.handleImageActions, false); .addEventListener("dragover", this.handleImageActions, false);
document document
.getElementById('featured-image-drop') .getElementById("featured-image-drop")
.addEventListener('drop', this.handleImageActions, false); .addEventListener("drop", this.handleImageActions, false);
document document
.getElementById('featured-image-upload') .getElementById("featured-image-upload")
.addEventListener('change', e => this.handleImageActions(e), false); .addEventListener("change", (e) => this.handleImageActions(e), false);
if (document.getElementById('new-feature-upload')) { if (document.getElementById("new-feature-upload")) {
document.getElementById('new-feature-upload').addEventListener('click', () => { document
document.getElementById('featured-image-upload').click(); .getElementById("new-feature-upload")
}); .addEventListener("click", () => {
} document.getElementById("featured-image-upload").click();
var optionButtons = document.querySelectorAll('.post-option-btn'); });
for (var i = 0, length = optionButtons.length; i < length; i++) { }
optionButtons[i].addEventListener('click', e => this.handlePostOptions(e), false); var optionButtons = document.querySelectorAll(".post-option-btn");
} for (var i = 0, length = optionButtons.length; i < length; i++) {
} optionButtons[i].addEventListener(
} "click",
//-------------------------- (e) => this.handlePostOptions(e),
// event handlers false
//-------------------------- );
handlePostOptions(e) { }
let currentOption; }
switch (e.target.id) { }
case 'option-page-icon': //--------------------------
case 'option-menu-pin': // event handlers
currentOption = document.getElementById('option-menu-pin'); //--------------------------
break; handlePostOptions(e) {
case 'option-feature-icon': let currentOption;
case 'option-feature': switch (e.target.id) {
currentOption = document.getElementById('option-feature'); case "option-page-icon":
break; case "option-menu-pin":
case 'option-published-icon': currentOption = document.getElementById("option-menu-pin");
case 'option-published': break;
currentOption = document.getElementById('option-published'); case "option-feature-icon":
break; case "option-feature":
} currentOption = document.getElementById("option-feature");
let active = currentOption.getAttribute('data-active'); break;
active == 'false' case "option-published-icon":
? currentOption.setAttribute('data-active', 'true') case "option-published":
: currentOption.setAttribute('data-active', 'false'); currentOption = document.getElementById("option-published");
} break;
handleEditorOptions(e) { }
switch (e) { let active = currentOption.getAttribute("data-active");
case EditorEvent.EDITOR_SAVE: active == "false"
case EditorEvent.EDITOR_UPDATE: ? currentOption.setAttribute("data-active", "true")
var task = ''; : currentOption.setAttribute("data-active", "false");
e === EditorEvent.EDITOR_SAVE ? (task = TASK_PAGE_CREATE) : (task = TASK_PAGE_EDIT); }
new PageActions() handleEditorOptions(e) {
.collectInfo(document.getElementById('featured-image-upload').files[0]) switch (e) {
.then(page => { case EditorEvent.EDITOR_SAVE:
notify.alert('Writing down changes', null); case EditorEvent.EDITOR_UPDATE:
admin var task = "";
.pageActions(task, page) e === EditorEvent.EDITOR_SAVE
.then(r => { ? (task = TASK_PAGE_CREATE)
if ( : (task = TASK_PAGE_EDIT);
r.type === DataEvent.PAGE_ERROR || new PageActions()
r.type === DataEvent.API_REQUEST_LAME .collectInfo(
) { document.getElementById("featured-image-upload").files[0]
notify.alert(r.message, false); )
} else { .then((page) => {
if (r.type === DataEvent.PAGE_UPDATED) { notify.alert("Writing down changes", null);
notify.alert(r.message, true); admin
} else { .pageActions(task, page)
notify.alert(r.message, true); .then((r) => {
window.location = '/@/dashboard/page/edit/' + r.id; if (
} r.type === DataEvent.PAGE_ERROR ||
} r.type === DataEvent.API_REQUEST_LAME
}) ) {
.catch(err => { notify.alert(r.message, false);
notify.alert(err, false); } else {
}); if (r.type === DataEvent.PAGE_UPDATED) {
}); notify.alert(r.message, true);
break; } else {
case EditorEvent.EDITOR_DELETE: notify.alert(r.message, true);
if (this.postLayout === 'index') { window.location = "/@/dashboard/page/edit/" + r.id;
notify.alert('Index cannot be deleted', false); }
return; }
} })
if (confirm("AYE! You know you're deleting this post, right?")) { .catch((err) => {
let id = { id: this.postUUID }; notify.alert(err, false);
admin });
.pageActions(TASK_PAGE_DELETE, id) });
.then(() => { break;
window.location = '/@/dashboard/page/list/'; case EditorEvent.EDITOR_DELETE:
}) if (this.postLayout === "index") {
.catch(err => { notify.alert("Index cannot be deleted", false);
notify.alert(err, false); return;
}); }
} else { if (confirm("AYE! You know you're deleting this post, right?")) {
// Do nothing! let id = { id: this.postUUID };
} admin
break; .pageActions(TASK_PAGE_DELETE, id)
case EditorEvent.EDITOR_UPLOAD_POST_IMAGE: .then(() => {
document.getElementById('post-image-upload').click(); window.location = "/dashboard/pages";
break; })
} .catch((err) => {
} notify.alert(err, false);
handleImageActions(e) { });
e.stopPropagation(); } else {
e.preventDefault(); // Do nothing!
switch (e.type) { }
case 'dragover': break;
e.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. case EditorEvent.EDITOR_UPLOAD_POST_IMAGE:
break; document.getElementById("post-image-upload").click();
case 'change': break;
case 'drop': }
e.type == 'drop' }
? (PostEditor.uploadFiles = e.dataTransfer.files) handleImageActions(e) {
: (PostEditor.uploadFiles = e.target.files); e.stopPropagation();
for (var i = 0, f; (f = PostEditor.uploadFiles[i]); i++) { e.preventDefault();
// Only process image files. switch (e.type) {
if (!f.type.match('image.*')) { case "dragover":
continue; e.dataTransfer.dropEffect = "copy"; // Explicitly show this is a copy.
} break;
var reader = new FileReader(); case "change":
// Closure to capture the file information. case "drop":
reader.onload = (function (theFile) { e.type == "drop"
return function (f) { ? (PostEditor.uploadFiles = e.dataTransfer.files)
// Render thumbnail. : (PostEditor.uploadFiles = e.target.files);
var image = document.createElement('img'); for (var i = 0, f; (f = PostEditor.uploadFiles[i]); i++) {
image.src = f.target.result; // Only process image files.
image.title = escape(theFile.name); if (!f.type.match("image.*")) {
var span = document.createElement('div'); continue;
span.innerHTML = [ }
'<img src="', var reader = new FileReader();
f.target.result, // Closure to capture the file information.
'" title="', reader.onload = (function (theFile) {
escape(theFile.name), return function (f) {
'"/>' // Render thumbnail.
].join(''); var image = document.createElement("img");
document.getElementById('featured-image-drop').innerHTML = ''; image.src = f.target.result;
document.getElementById('featured-image-drop').appendChild(image); image.title = escape(theFile.name);
}; var span = document.createElement("div");
})(f); span.innerHTML = [
// Read in the image file as a data URL. '<img src="',
reader.readAsDataURL(f); f.target.result,
} '" title="',
} escape(theFile.name),
} '"/>',
handleImageUpload(type, files) { ].join("");
let self = this; document.getElementById("featured-image-drop").innerHTML = "";
notify.alert('Uploading Image', null); document.getElementById("featured-image-drop").appendChild(image);
admin };
.imageUpload(type, files) })(f);
.then(r => { // Read in the image file as a data URL.
if (r.type == DataEvent.POST_IMAGE_ADDED) reader.readAsDataURL(f);
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url); }
notify.alert('Image Added to Entry', true); }
}) }
.catch(() => { handleImageUpload(type, files) {
notify.alert('Uh oh. Image not added', false); let self = this;
//console.log('ERROR', err); notify.alert("Uploading Image", null);
}); admin
} .imageUpload(type, files)
.then((r) => {
if (r.type == DataEvent.POST_IMAGE_ADDED)
self.editor.notify(EditorEvent.EDITOR_UPLOAD_POST_IMAGE, r.url);
notify.alert("Image Added to Entry", true);
})
.catch(() => {
notify.alert("Uh oh. Image not added", false);
//console.log('ERROR', err);
});
}
} }
PostEditor.uploadFiles = []; PostEditor.uploadFiles = [];

@ -1,30 +1,30 @@
import PageEditor from './PageEditor'; import PageEditor from "./PageEditor";
export default class PostIndex { export default class PostIndex {
//-------------------------- //--------------------------
// constructor // constructor
//-------------------------- //--------------------------
constructor(page) { constructor(page) {
this.currentPage = null; this.currentPage = null;
this.choosePage(page); this.choosePage(page);
this.start(); this.start();
} }
//-------------------------- //--------------------------
// methods // methods
//-------------------------- //--------------------------
start() {} start() {}
choosePage(page) { choosePage(page) {
this.currentPage = ''; this.currentPage = "";
switch (page) { switch (page) {
case 'edit': case "edit":
case 'add': case "add":
this.currentPage = new PageEditor(); this.currentPage = new PageEditor();
break; break;
default: default:
//just chill //just chill
break; break;
} }
} }
//-------------------------- //--------------------------
// event handlers // event handlers
//-------------------------- //--------------------------
} }

@ -9,10 +9,10 @@ export const CONTENT_TYPE_JSON = "json";
export const CONTENT_TYPE_FORM = "x-www-form-urlencoded"; export const CONTENT_TYPE_FORM = "x-www-form-urlencoded";
export const API_STATUS = "/api/v1/status"; export const API_STATUS = "/api/v1/status";
export const API_GET_NAV = "/api/settings/nav"; export const API_GET_NAV = "/api/settings/nav";
export const API_NEW_PAGE = "/api/v1/page/write/new"; export const API_NEW_PAGE = "/api/v1/page/create";
export const API_EDIT_PAGE = "/api/v1/page/write"; export const API_EDIT_PAGE = "/api/v1/page/write";
export const API_DELETE_PAGE = "/api/v1/page/delete"; export const API_DELETE_PAGE = "/api/v1/page/delete";
export const API_IMAGE_UPLOAD = "/api/v1/page/add-post-image"; export const API_IMAGE_UPLOAD = "/api/v1/page/add-entry-image";
export const API_SETTINGS_SYNC = "/api/v1/settings/sync"; export const API_SETTINGS_SYNC = "/api/v1/settings/sync";
export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar"; export const API_UPLOAD_AVATAR = "/api/v1/settings/add-avatar";
export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background"; export const API_UPLOAD_BACKGROUND = "/api/v1/settings/add-feature-background";
@ -280,6 +280,7 @@ export default class APIUtils {
request.open(requestType, requestURL, true); request.open(requestType, requestURL, true);
request.onload = () => { request.onload = () => {
if (request.status == 200) { if (request.status == 200) {
//console.log("RESPONSE", request);
let response = JSON.parse(request["response"]); let response = JSON.parse(request["response"]);
resolve(response); resolve(response);
} else { } else {
@ -298,7 +299,7 @@ export default class APIUtils {
eventType === DataEvent.API_BACKUP_RESTORE || eventType === DataEvent.API_BACKUP_RESTORE ||
eventType === DataEvent.API_REINDEX_PAGES eventType === DataEvent.API_REINDEX_PAGES
) )
request.setRequestHeader("x-access-token", self.token); request.setRequestHeader("fipamo-access-token", self.token);
switch (contentType) { switch (contentType) {
case CONTENT_TYPE_JSON: case CONTENT_TYPE_JSON:

Loading…
Cancel
Save