more microhtml

This commit is contained in:
Luana 2023-07-10 15:03:54 -03:00 committed by Shish
parent aef5bc9e2e
commit b29d536e19
6 changed files with 52 additions and 63 deletions

View file

@ -4,36 +4,35 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{BR,INPUT};
class AliasEditorTheme extends Themelet class AliasEditorTheme extends Themelet
{ {
/** /**
* Show a page of aliases. * Show a page of aliases.
*
* Note: $can_manage = whether things like "add new alias" should be shown
*/ */
public function display_aliases($table, $paginator): void public function display_aliases(HTMLElement $table, HTMLElement $paginator): void
{ {
global $page, $user; global $page, $user;
$can_manage = $user->can(Permissions::MANAGE_ALIAS_LIST); $html = emptyHTML($table, BR(), $paginator, BR(), SHM_A("alias/export/aliases.csv", "Download as CSV", args: ["download"=>"aliases.csv"]));
$html = "
$table
$paginator
<p><a href='".make_link("alias/export/aliases.csv")."' download='aliases.csv'>Download as CSV</a></p>
";
$bulk_html = " $bulk_form = SHM_FORM("alias/import", multipart: true);
".make_form(make_link("alias/import"), 'post', true)." $bulk_form->appendChild(
<input type='file' name='alias_file'> INPUT(["type"=>"file", "name"=>"alias_file"]),
<input type='submit' value='Upload List'> SHM_SUBMIT("Upload List")
</form> );
"; $bulk_html = emptyHTML($bulk_form);
$page->set_title("Alias List"); $page->set_title("Alias List");
$page->set_heading("Alias List"); $page->set_heading("Alias List");
$page->add_block(new NavBlock()); $page->add_block(new NavBlock());
$page->add_block(new Block("Aliases", $html)); $page->add_block(new Block("Aliases", $html));
if ($can_manage) {
if ($user->can(Permissions::MANAGE_ALIAS_LIST)) {
$page->add_block(new Block("Bulk Upload", $bulk_html, "main", 51)); $page->add_block(new Block("Bulk Upload", $bulk_html, "main", 51));
} }
} }

View file

@ -168,10 +168,7 @@ class Approval extends Extension
global $user, $config; global $user, $config;
if ($event->key===HelpPages::SEARCH) { if ($event->key===HelpPages::SEARCH) {
if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) { if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
$block = new Block(); $event->add_block(new Block("Approval", $this->theme->get_help_html()));
$block->header = "Approval";
$block->body = $this->theme->get_help_html();
$event->add_block($block);
} }
} }
} }
@ -231,7 +228,7 @@ class Approval extends Extension
{ {
global $user, $config; global $user, $config;
if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) { if ($user->can(Permissions::APPROVE_IMAGE) && $config->get_bool(ApprovalConfig::IMAGES)) {
$event->add_part($this->theme->get_image_admin_html($event->image)); $event->add_part((string)$this->theme->get_image_admin_html($event->image));
} }
} }

View file

@ -4,43 +4,40 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use function MicroHTML\BR; use MicroHTML\HTMLElement;
use function MicroHTML\BUTTON;
use function MicroHTML\INPUT; use function MicroHTML\emptyHTML;
use function MicroHTML\{BUTTON,INPUT,P};
class ApprovalTheme extends Themelet class ApprovalTheme extends Themelet
{ {
public function get_image_admin_html(Image $image): string public function get_image_admin_html(Image $image): HTMLElement
{ {
if ($image->approved===true) { if ($image->approved===true) {
$html = SHM_SIMPLE_FORM( $form = SHM_SIMPLE_FORM(
'disapprove_image/'.$image->id, 'disapprove_image/'.$image->id,
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]), INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
SHM_SUBMIT("Disapprove") SHM_SUBMIT("Disapprove")
); );
} else { } else {
$html = SHM_SIMPLE_FORM( $form = SHM_SIMPLE_FORM(
'approve_image/'.$image->id, 'approve_image/'.$image->id,
INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]), INPUT(["type"=>'hidden', "name"=>'image_id', "value"=>$image->id]),
SHM_SUBMIT("Approve") SHM_SUBMIT("Approve")
); );
} }
return (string)$html; return $form;
} }
public function get_help_html(): string public function get_help_html(): HTMLElement
{ {
return '<p>Search for posts that are approved/not approved.</p> return emptyHTML(
<div class="command_example"> P("Search for posts that are approved/not approved."),
<pre>approved:yes</pre> SHM_COMMAND_EXAMPLE("approved:yes", "Returns posts that have been approved."),
<p>Returns posts that have been approved.</p> SHM_COMMAND_EXAMPLE("approved:no", "Returns posts that have not been approved.")
</div> );
<div class="command_example">
<pre>approved:no</pre>
<p>Returns posts that have not been approved.</p>
</div>
';
} }
public function display_admin_block(SetupBuildingEvent $event) public function display_admin_block(SetupBuildingEvent $event)
@ -53,12 +50,13 @@ class ApprovalTheme extends Themelet
{ {
global $page; global $page;
$html = (string)SHM_SIMPLE_FORM( $form = SHM_SIMPLE_FORM(
"admin/approval", "admin/approval",
BUTTON(["name"=>'approval_action', "value"=>'approve_all'], "Approve All Posts"), BUTTON(["name"=>'approval_action', "value"=>'approve_all'], "Approve All Posts"),
BR(), " ",
BUTTON(["name"=>'approval_action', "value"=>'disapprove_all'], "Disapprove All Posts"), BUTTON(["name"=>'approval_action', "value"=>'disapprove_all'], "Disapprove All Posts"),
); );
$page->add_block(new Block("Approval", $html));
$page->add_block(new Block("Approval", $form));
} }
} }

View file

@ -57,10 +57,7 @@ class Artists extends Extension
public function onHelpPageBuilding(HelpPageBuildingEvent $event) public function onHelpPageBuilding(HelpPageBuildingEvent $event)
{ {
if ($event->key===HelpPages::SEARCH) { if ($event->key===HelpPages::SEARCH) {
$block = new Block(); $event->add_block(new Block("Artist", $this->theme->get_help_html()));
$block->header = "Artist";
$block->body = $this->theme->get_help_html();
$event->add_block($block);
} }
} }

View file

@ -4,20 +4,20 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML;
use function MicroHTML\{INPUT,P,SPAN,TD,TH,TR};
class ArtistsTheme extends Themelet class ArtistsTheme extends Themelet
{ {
public function get_author_editor_html(string $author): string public function get_author_editor_html(string $author): string
{ {
$h_author = html_escape($author); $h_author = html_escape($author);
return " return (string)TR(TH("Author", TD(
<tr> SPAN(["class"=>"view"], $h_author),
<th>Author</th> INPUT(["class"=>"edit", "type"=>"text", "name"=>"tag_edit__author", "value"=>$h_author])
<td> )));
<span class='view'>$h_author</span>
<input class='edit' type='text' name='tag_edit__author' value='$h_author'>
</td>
</tr>
";
} }
public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): void public function sidebar_options(string $mode, ?int $artistID=null, $is_admin=false): void
@ -554,13 +554,11 @@ class ArtistsTheme extends Themelet
return $html; return $html;
} }
public function get_help_html(): string public function get_help_html(): HTMLElement
{ {
return '<p>Search for posts with a particular artist.</p> return emptyHTML(
<div class="command_example"> P("Search for posts with a particular artist."),
<pre>artist=leonardo</pre> SHM_COMMAND_EXAMPLE("artist=leonardo", "Returns posts with the artist \"leonardo\".")
<p>Returns posts with the artist "leonardo".</p> );
</div>
';
} }
} }

View file

@ -7,7 +7,7 @@ namespace Shimmie2;
use MicroHTML\HTMLElement; use MicroHTML\HTMLElement;
use function MicroHTML\emptyHTML; use function MicroHTML\emptyHTML;
use function MicroHTML\{DIV,INPUT,P,PRE,SPAN,TABLE,TD,TH,TR}; use function MicroHTML\{P,SPAN,TABLE,TD,TH,TR};
class RatingsTheme extends Themelet class RatingsTheme extends Themelet
{ {