Refactor entry API: consolidate entry handling, update naming conventions, and enhance error reporting

This commit is contained in:
marc-go committed 2026-10-11 19:19:36 +02:00
1 parent 205f2e2f73
commit ad9290d2ad
9 files changed
+72 -12

No files matched your search

+5 -1
View File
@@ -48,7 +48,7 @@ class HTMLLoader {
function setPage($page) {
if (!array_key_exists($page, $this->template_conf)) {
$this->showError("Page " . $page . " for template " . $this->template . " not found.");
$this->showError('Page <span class="code">' . $page . '</span> for template <span class="code">' . $this->template . '</span> not found.');
}else{
$this->page = $page;
}
@@ -93,6 +93,10 @@ class HTMLLoader {
$page = $tempalte_conf[$this->page];
if (!is_file(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"])) {
$this->showError('HTML File <span class="code">' . $page["html_file"] . '</span> for page <span class="code">' . $page["name"] . '</span> in template <span class="code">' . $template . '</span> does not exists.');
}
$html = file_get_contents(TEMPLATE_PATH . $template_dir . "/" . $page["dir_name"] . "/" . $page["html_file"]);
if ($showAppName) {
+6 -2
View File
@@ -13,12 +13,16 @@ require FRONTEND_PATH . "html_loader.php";
$htmlLoader = new HTMLLoader();
// Build Entry Page
$htmlLoader->setPage("entrys_frontend");
$htmlLoader->setPage("entries_frontend");
// Get entrys
$call = new APICall("entrys/get.php");
$call = new APICall("entry/get.php");
$response = $call->response;
if ($call->getError() !== false) {
$htmlLoader->showError("Entry API Returned an error: " . $call->getError());
}
if ($response["data"]["empty"]) {
$html_block = "<p>There aren'n any entrys yet. Be the first one!</p>";
}else{
+9 -1
View File
@@ -46,7 +46,7 @@ class APICall {
// Check Path
if (!is_file(API_DIR . $path)) {
$this->error("API Path invalid.");
$this->error = "API Path invalid.";
return false;
}
@@ -58,4 +58,12 @@ class APICall {
$this->response = $response;
}
function getError() {
if (isset($this->error)) {
return $this->error;
}else{
return false;
}
}
}
@@ -101,7 +101,7 @@
<md-icon-button id="toggle" aria-label="Menü ein-/ausklappen">
<md-icon>menu</md-icon>
</md-icon-button>
<span class="title">Dashboard</span>
<span class="md-typescale-body-large title">%appname%</span>
</div>
<md-list>
@@ -117,7 +117,14 @@
</aside>
<main class="content">
<h1>Dashboard</h1>
<h1 class="md-typescale-display-large">%appname%</h1>
<h3 class="md-typescale-display-medium">Entrys</h3>
<md-list>
<md-list-item>
<div slot="headline">Cucumber</div>
<div slot="supporting-text">Cucumbers are long green fruits that are just as long as this multi-line description</div>
</md-list-item>
</md-list>
</main>
</div>
@@ -16,7 +16,7 @@
document.adoptedStyleSheets.push(typescaleStyles.styleSheet);
</script>
<title>%appname% // Entrys</title>
<title>%appname% // Entries</title>
<style>
:root {
@@ -86,7 +86,7 @@
name = document.getElementById("entry_name").value;
text = document.getElementById("entry_text").value;
fetch("/api/entrys/add.php", {
fetch("/api/entry/add.php", {
method: "POST",
body: JSON.stringify({
name: name,
+4 -4
View File
@@ -15,10 +15,10 @@
"css_files":[]
},
"entrys_frontend":{
"name":"entrys_frontend",
"dir_name":"entrys_frontend",
"html_file":"entrys_frontend.html",
"entries_frontend":{
"name":"entries_frontend",
"dir_name":"entries_frontend",
"html_file":"entries_frontend.html",
"css_files":[]
},