forked from projects/fipamo
plugged in page list display
This commit is contained in:
parent
c4232a0a01
commit
6c3653277d
4 changed files with 129 additions and 13 deletions
|
@ -14,13 +14,22 @@ class DashControl
|
|||
): ResponseInterface {
|
||||
$view = Twig::fromRequest($request);
|
||||
$pageOptions = [];
|
||||
$template = "";
|
||||
switch (isset($args["second"]) ? $args["second"] : "index") {
|
||||
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;
|
||||
default:
|
||||
//$_SESSION["TEST"] = "TESTERZ";
|
||||
//session_unset();
|
||||
$template = "dash/start.twig";
|
||||
if (Session::active()) {
|
||||
$pageOptions = [
|
||||
"title" => "Welcome to Fipamo",
|
||||
|
@ -33,9 +42,8 @@ class DashControl
|
|||
"status" => Session::active(),
|
||||
];
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
return $view->render($response, "dash/start.twig", $pageOptions);
|
||||
return $view->render($response, $template, $pageOptions);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use Mni\FrontYAML\Parser;
|
||||
use function _\orderBy;
|
||||
use function _\filter;
|
||||
|
||||
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();
|
||||
$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 = [];
|
||||
|
||||
if (count($filtered) != 0) {
|
||||
if (count($filtered) < $limit) {
|
||||
$limit = count($filtered) - 1;
|
||||
}
|
||||
$range = $page * $limit - $limit;
|
||||
for ($i = 0; $i <= $limit; $i++) {
|
||||
try {
|
||||
array_push($folder, $content[$i + $range]);
|
||||
array_push($folder, $filtered[$i + $range]);
|
||||
} catch (Exception $error) {
|
||||
//echo $error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return [
|
||||
"pages" => $folder,
|
||||
"total" => $count,
|
||||
"numOfPages" => $numOfPages,
|
||||
"entryCount" => count($filtered),
|
||||
"sort" => $filter,
|
||||
"stats" => [
|
||||
"all" => count($all),
|
||||
"published" => count($published),
|
||||
"deleted" => count($deleted),
|
||||
],
|
||||
];
|
||||
}
|
||||
public function getContents()
|
||||
|
|
67
brain/views/dash/book.twig
Normal file
67
brain/views/dash/book.twig
Normal 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 %}
|
|
@ -3,7 +3,7 @@
|
|||
<div class="recent-header">
|
||||
<h3>Recent</h3>
|
||||
<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>
|
||||
</div>
|
||||
|
|
Loading…
Reference in a new issue