plugged in page list display

This commit is contained in:
Ro 2021-04-07 14:09:40 -07:00
parent c4232a0a01
commit 6c3653277d
4 changed files with 129 additions and 13 deletions

View file

@ -14,13 +14,22 @@ class DashControl
): ResponseInterface { ): ResponseInterface {
$view = Twig::fromRequest($request); $view = Twig::fromRequest($request);
$pageOptions = []; $pageOptions = [];
$template = "";
switch (isset($args["second"]) ? $args["second"] : "index") { switch (isset($args["second"]) ? $args["second"] : "index") {
case "pages": case "pages":
$content = []; $data = (new Book("../content/pages"))->getPages(1, 4);
$template = "dash/book.twig";
$pageOptions = [
"entryCount" => $data["entryCount"],
"filter" => $data["sort"],
"stats" => $data["stats"],
"pages" => $data["pages"],
];
break; break;
default: default:
//$_SESSION["TEST"] = "TESTERZ"; //$_SESSION["TEST"] = "TESTERZ";
//session_unset(); //session_unset();
$template = "dash/start.twig";
if (Session::active()) { if (Session::active()) {
$pageOptions = [ $pageOptions = [
"title" => "Welcome to Fipamo", "title" => "Welcome to Fipamo",
@ -33,9 +42,8 @@ class DashControl
"status" => Session::active(), "status" => Session::active(),
]; ];
} }
break; break;
} }
return $view->render($response, "dash/start.twig", $pageOptions); return $view->render($response, $template, $pageOptions);
} }
} }

View file

@ -2,6 +2,7 @@
use Mni\FrontYAML\Parser; use Mni\FrontYAML\Parser;
use function _\orderBy; use function _\orderBy;
use function _\filter;
class Book class Book
{ {
@ -24,24 +25,64 @@ class Book
} }
} }
public function getPages(int $page, int $limit) public function getPages(int $page, int $limit, string $sort = null)
{ {
$content = $this->getContents(); $content = $this->getContents();
$count = ceil(count($content) / $limit);
$published = filter($content, function ($item) {
return $item["published"] == "true";
});
$deleted = filter($content, function ($item) {
//echo $item["deleted"];
return $item["deleted"];
});
$all = $content;
$filter = isset($sort) ? $sort : "all";
//echo $filter;
$filtered = [];
switch ($filter) {
case "published":
$filtered = $published;
break;
case "deleted":
$filtered = $deleted;
break;
default:
$filtered = $content;
break;
}
$numOfPages = ceil(count($filtered) / $limit);
$folder = []; $folder = [];
$range = $page * $limit - $limit;
for ($i = 0; $i <= $limit; $i++) { if (count($filtered) != 0) {
try { if (count($filtered) < $limit) {
array_push($folder, $content[$i + $range]); $limit = count($filtered) - 1;
} catch (Exception $error) { }
//echo $error; $range = $page * $limit - $limit;
for ($i = 0; $i <= $limit; $i++) {
try {
array_push($folder, $filtered[$i + $range]);
} catch (Exception $error) {
//echo $error;
}
} }
} }
return [ return [
"pages" => $folder, "pages" => $folder,
"total" => $count, "numOfPages" => $numOfPages,
"entryCount" => count($filtered),
"sort" => $filter,
"stats" => [
"all" => count($all),
"published" => count($published),
"deleted" => count($deleted),
],
]; ];
} }
public function getContents() public function getContents()

View file

@ -0,0 +1,67 @@
{% extends "dash/_frame.twig" %}
{% block title %}
{{ title }}
{% endblock %}
{% block stylesheets %}
<link rel="stylesheet" type="text/css" href="/assets/css/dash.css?=wrqrqrewq">
{% endblock %}
{% block mainContent %}
<div id="post-index">
<div id="post-index-wrapper">
<div id="post-index-menu">
<a href="/dashboard/pages/all">All Pages ({{ stats['all'] }})</a>
.
<a href="/dashboard/pages/published">Published ({{ stats['published'] }})</a>
.
<a href="/dashboard/pages/deleted">Deleted ({{ stats['deleted'] }})</a>
</div>
<div id="posts-list">
{% for page in pages %}
<a class="page-link" href="/dashboard/page/edit/{{ page.uuid }}">
<div class="page-bg" style="background: url({{ page.feature }}) no-repeat center center / cover">
<div id="meta">
<label>
{{ page.title }}
</label>
{% if page.menu == 'true' %}
{% set menu = "true" %}
{% else %}
{% set menu = "false" %}
{% endif %}
{% if page.published == 'true' %}
{% set published = "true" %}
{% else %}
{% set published = "false" %}
{% endif %}
{% if page.featured == 'true' %}
{% set featured = "true" %}
{% else %}
{% set featured = "false" %}
{% endif %}
<div id="options">
<span class="meta-options" data-active="{{ menu }}">
Menu Item</span>
<span class="meta-options" data-active="{{ published }}">
Published</span>
<span class="meta-options" data-active="{{ featured }}">
Featured</span>
</div>
<span>{{ page.prettyDate }}</span>
</div>
</div>
</a>
{% endfor %}
</div>
</div>
</div>
{% endblock %}
{% block javascripts %}
<script src="/assets/scripts/dash.min.js" type="text/javascript"></script>
{% endblock %}

View file

@ -3,7 +3,7 @@
<div class="recent-header"> <div class="recent-header">
<h3>Recent</h3> <h3>Recent</h3>
<div class="index-menu"> <div class="index-menu">
<a href='/dashboard/page/list'>View Pages</a> <a href='/dashboard/pages'>View Pages</a>
. .
<a href='/dashboard/page/add/new'>Create Page</a> <a href='/dashboard/page/add/new'>Create Page</a>
</div> </div>