current index updates when new page added
This commit is contained in:
parent
bc6fc33592
commit
043bd25cf7
4 changed files with 32 additions and 6 deletions
|
@ -112,7 +112,7 @@ class Book
|
||||||
$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"] : 6;
|
$id = $task != "create" ? $body["id"] : Settings::getCurrentIndex();
|
||||||
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
$uuid = $task != "create" ? $body["uuid"] : StringTools::createUUID();
|
||||||
$write =
|
$write =
|
||||||
"---\n" .
|
"---\n" .
|
||||||
|
@ -171,7 +171,7 @@ class Book
|
||||||
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
$writePath = "../content/pages/" . $path . "/" . $body["slug"] . ".md";
|
||||||
}
|
}
|
||||||
|
|
||||||
$status = DocTools::write($task, $path, $writePath, $write);
|
$status = DocTools::writePages($task, $path, $writePath, $write);
|
||||||
|
|
||||||
if ($status) {
|
if ($status) {
|
||||||
$response = [
|
$response = [
|
||||||
|
@ -179,6 +179,10 @@ class Book
|
||||||
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
"type" => $task == "write" ? "postUpdated" : "postAdded",
|
||||||
"id" => $uuid,
|
"id" => $uuid,
|
||||||
];
|
];
|
||||||
|
//if new page added, update current index in Settings file
|
||||||
|
if ($task == "create") {
|
||||||
|
Settings::updateIndex();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$response = [
|
$response = [
|
||||||
"message" => "Uh oh. File save problem. Don't panic",
|
"message" => "Uh oh. File save problem. Don't panic",
|
||||||
|
|
|
@ -4,14 +4,14 @@ class Settings
|
||||||
{
|
{
|
||||||
private $folks;
|
private $folks;
|
||||||
private $tags;
|
private $tags;
|
||||||
private $settings;
|
private static $settings;
|
||||||
|
|
||||||
public function __construct()
|
public function __construct()
|
||||||
{
|
{
|
||||||
//gets all settings files and converts to php objects
|
//gets all settings files and converts to php objects
|
||||||
$this->folks = json_decode(file_get_contents("../config/folks.json"), true);
|
$this->folks = json_decode(file_get_contents("../config/folks.json"), true);
|
||||||
$this->tags = json_decode(file_get_contents("../config/tags.json"), true);
|
$this->tags = json_decode(file_get_contents("../config/tags.json"), true);
|
||||||
$this->settings = json_decode(
|
self::$settings = json_decode(
|
||||||
file_get_contents("../config/settings.json"),
|
file_get_contents("../config/settings.json"),
|
||||||
true
|
true
|
||||||
);
|
);
|
||||||
|
@ -27,4 +27,19 @@ class Settings
|
||||||
return $this->folks;
|
return $this->folks;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function getCurrentIndex()
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
return $settings["library_stats"]["current_index"];
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function updateIndex()
|
||||||
|
{
|
||||||
|
$settings = self::$settings;
|
||||||
|
$index = $settings["library_stats"]["current_index"];
|
||||||
|
$settings["library_stats"]["current_index"] = $index + 1;
|
||||||
|
|
||||||
|
DocTools::writeSettings("../config/settings.json", $settings);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,7 @@ class DocTools
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function write($task, $path, $fileLocation, $fileContents)
|
public static function writePages($task, $path, $fileLocation, $fileContents)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if ($task == "create") {
|
if ($task == "create") {
|
||||||
|
@ -26,4 +26,11 @@ class DocTools
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function writeSettings($fileLocation, $fileContents)
|
||||||
|
{
|
||||||
|
($new = fopen($fileLocation, "w")) or die("Unable to open file!");
|
||||||
|
fwrite($new, json_encode($fileContents));
|
||||||
|
fclose($new);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -280,7 +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);
|
//console.log("RESPONSE", request);
|
||||||
let response = JSON.parse(request["response"]);
|
let response = JSON.parse(request["response"]);
|
||||||
resolve(response);
|
resolve(response);
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue