pools theme fully MicroHTML

This commit is contained in:
Luana 2023-07-05 16:04:26 -03:00 committed by Shish
parent 0978ef99e3
commit ff237fc00c

View file

@ -8,7 +8,7 @@ use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML; use function MicroHTML\emptyHTML;
use function MicroHTML\rawHTML; use function MicroHTML\rawHTML;
use function MicroHTML\{A,BR,INPUT,P,SCRIPT,TABLE,THEAD,TBODY,TR,TH,TD,TEXTAREA,SPAN}; use function MicroHTML\{A,BR,DIV,INPUT,P,SCRIPT,SPAN,TABLE,TBODY,TD,TEXTAREA,TH,THEAD,TR};
class PoolsTheme extends Themelet class PoolsTheme extends Themelet
{ {
@ -20,27 +20,25 @@ class PoolsTheme extends Themelet
{ {
global $page; global $page;
$linksPools = []; //TODO: Use a 3 column table?
$linksPools = emptyHTML();
foreach ($navIDs as $poolID => $poolInfo) { foreach ($navIDs as $poolID => $poolInfo) {
$linksPools[] = "<a href='" . make_link("pool/view/" . $poolID) . "'>" . html_escape($poolInfo['info']->title) . "</a>"; $div = DIV(A(["href"=>make_link("pool/view/" . $poolID)], $poolInfo["info"]->title));
if (!empty($poolInfo['nav'])) { if (!empty($poolInfo["nav"])) {
$navlinks = ""; if (!empty($poolInfo["nav"]["prev"])) {
if (!empty($poolInfo['nav']['prev'])) { $div->appendChild(A(["href"=>make_link("post/view/" . $poolInfo["nav"]["prev"]), "class"=>"pools_prev_img"], "Prev"));
$navlinks .= '<a href="' . make_link('post/view/' . $poolInfo['nav']['prev']) . '" class="pools_prev_img">Prev</a>';
} }
if (!empty($poolInfo['nav']['next'])) { if (!empty($poolInfo["nav"]["next"])) {
$navlinks .= '<a href="' . make_link('post/view/' . $poolInfo['nav']['next']) . '" class="pools_next_img">Next</a>'; $div->appendChild(A(["href"=>make_link("post/view/" . $poolInfo["nav"]["next"]), "class"=>"pools_next_img"], "Next"));
}
if (!empty($navlinks)) {
$navlinks .= "<div style='height: 5px'></div>";
$linksPools[] = $navlinks;
} }
} }
$linksPools->appendChild($div);
} }
if (count($linksPools) > 0) { if (!empty($navIDs)) {
$page->add_block(new Block("Pools", implode("<br>", $linksPools), "left")); $page->add_block(new Block("Pools", $linksPools, "left"));
} }
} }
@ -280,23 +278,22 @@ class PoolsTheme extends Themelet
{ {
$this->display_top($pool, "Sorting Pool"); $this->display_top($pool, "Sorting Pool");
$pool_images = "\n<form action='" . make_link("pool/order") . "' method='POST' name='checks'>"; $form = SHM_FORM("pool/order", name: "checks");
$i = 0; foreach ($images as $i=>$image) {
foreach ($images as $image) { $form->appendChild(SPAN(
$thumb_html = $this->build_thumb_html($image); ["class"=>"thumb"],
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" . $this->build_thumb_html($image),
'<br><input name="imgs[' . $i . '][]" type="number" style="max-width:50px;" value="' . $image->image_order . '" />' . INPUT(["type"=>"number", "name"=>"imgs[$i][]", "value"=>$image->image_order, "style"=>"max-width: 50px;"]),
'<input name="imgs[' . $i . '][]" type="hidden" value="' . $image->id . '" />' . INPUT(["type"=>"hidden", "name"=>"imgs[$i][]", "value"=>$image->id])
'</span>'; ));
$i++;
} }
$pool_images .= "<br>" . $form->appendChild(
"<input type='submit' name='edit' id='edit_pool_order' value='Order'/>" . INPUT(["type"=>"hidden", "name"=>"pool_id", "value"=>$pool->id]),
"<input type='hidden' name='pool_id' value='" . $pool->id . "'>" . SHM_SUBMIT("Order", ["name"=>"edit", "id"=>"edit_pool_order"])
"</form>"; );
$page->add_block(new Block("Sorting Posts", $pool_images, "main", 30)); $page->add_block(new Block("Sorting Posts", $form, position: 30));
} }
/** /**
@ -307,35 +304,35 @@ class PoolsTheme extends Themelet
*/ */
public function edit_pool(Page $page, Pool $pool, array $images) public function edit_pool(Page $page, Pool $pool, array $images)
{ {
/* EDIT POOL DESCRIPTION */ $_input_id = INPUT(["type"=>"hidden", "name"=>"pool_id", "value"=>$pool->id]);
$desc_html = "
" . make_form(make_link("pool/edit_description")) . "
<textarea name='description'>" . $pool->description . "</textarea><br />
<input type='hidden' name='pool_id' value='" . $pool->id . "'>
<input type='submit' value='Change Description' />
</form>
";
/* REMOVE POOLS */ $desc_form = SHM_SIMPLE_FORM(
$pool_images = "\n<form action='" . make_link("pool/remove_posts") . "' method='POST' name='checks'>"; "pool/edit/description",
TEXTAREA(["name"=>"description"], $pool->description),
BR(),
$_input_id,
SHM_SUBMIT("Change Description")
);
$images_form = SHM_FORM("pool/remove_posts", name: "checks");
foreach ($images as $image) { foreach ($images as $image) {
$thumb_html = $this->build_thumb_html($image); $images_form->appendChild(SPAN(
["class"=>"thumb"],
$pool_images .= '<span class="thumb">' . "\n" . $thumb_html . "\n" . $this->build_thumb_html($image),
'<br><input name="check[]" type="checkbox" value="' . $image->id . '" />' . INPUT(["type"=>"checkbox", "name"=>"check[]", "value"=>$image->id])
'</span>'; ));
} }
$pool_images .= "<br>" . $images_form->appendChild(
"<input type='submit' name='edit' id='edit_pool_remove_sel' value='Remove Selected'/>" . BR(),
"<input type='hidden' name='pool_id' value='" . $pool->id . "'>" . $_input_id,
"</form>"; SHM_SUBMIT("Remove Selected", ["name"=>"edit", "id"=>"edit_pool_remove_sel"])
);
$pool->description = ""; //This is a rough fix to avoid showing the description twice. $pool->description = ""; //This is a rough fix to avoid showing the description twice.
$this->display_top($pool, "Editing Pool", true); $this->display_top($pool, "Editing Pool", true);
$page->add_block(new Block("Editing Description", $desc_html, "main", 28)); $page->add_block(new Block("Editing Description", $desc_form, position: 28));
$page->add_block(new Block("Editing Posts", $pool_images, "main", 30)); $page->add_block(new Block("Editing Posts", $images_form, position: 30));
} }
/** /**
@ -344,21 +341,17 @@ class PoolsTheme extends Themelet
public function show_history(array $histories, int $pageNumber, int $totalPages) public function show_history(array $histories, int $pageNumber, int $totalPages)
{ {
global $page; global $page;
$html = '
<table id="poolsList" class="zebra">
<thead><tr>
<th>Pool</th>
<th>Post Count</th>
<th>Changes</th>
<th>Updater</th>
<th>Date</th>
<th>Action</th>
</tr></thead><tbody>';
$table = TABLE(
["id"=>"poolsList", "class"=>"zebra"],
THEAD(TR(TH("Pool"), TH("Post Count"), TH("Changes"), TH("Updater"), TH("Date"), TH("Action")))
);
$body = [];
foreach ($histories as $history) { foreach ($histories as $history) {
$pool_link = "<a href='" . make_link("pool/view/" . $history['pool_id']) . "'>" . html_escape($history['title']) . "</a>"; $pool_link = A(["href"=>make_link("pool/view/" . $history["pool_id"])], $history["title"]);
$user_link = "<a href='" . make_link("user/" . url_escape($history['user_name'])) . "'>" . html_escape($history['user_name']) . "</a>"; $user_link = A(["href"=>make_link("user/" . url_escape($history["user_name"]))], $history["user_name"]);
$revert_link = "<a href='" . make_link("pool/revert/" . $history['id']) . "'>Revert</a>"; $revert_link = A(["href"=>make_link("pool/revert/" . $history["id"])], "Revert");
if ($history['action'] == 1) { if ($history['action'] == 1) {
$prefix = "+"; $prefix = "+";
@ -368,28 +361,28 @@ class PoolsTheme extends Themelet
throw new \RuntimeException("history['action'] not in {0, 1}"); throw new \RuntimeException("history['action'] not in {0, 1}");
} }
$images = trim($history['images']); $images = trim($history["images"]);
$images = explode(" ", $images); $images = explode(" ", $images);
$image_link = ""; $image_links = emptyHTML();
foreach ($images as $image) { foreach ($images as $image) {
$image_link .= "<a href='" . make_link("post/view/" . $image) . "'>" . $prefix . $image . " </a>"; $image_links->appendChild(" ", A(["href"=>make_link("post/view/" . $image)], $prefix . $image));
} }
$html .= "<tr>" . $body[] = TR(
"<td class='left'>" . $pool_link . "</td>" . TD(["class"=>"left"], $pool_link),
"<td>" . $history['count'] . "</td>" . TD($history["count"]),
"<td>" . $image_link . "</td>" . TD($image_links),
"<td>" . $user_link . "</td>" . TD($user_link),
"<td>" . $history['date'] . "</td>" . TD($history["date"]),
"<td>" . $revert_link . "</td>" . TD($revert_link)
"</tr>"; );
} }
$html .= "</tbody></table>"; $table->appendChild(TBODY(...$body));
$this->display_top(null, "Recent Changes"); $this->display_top(null, "Recent Changes");
$page->add_block(new Block("Recent Changes", $html, "main", 10)); $page->add_block(new Block("Recent Changes", $table, position: 10));
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages); $this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);
} }