More MicroHTML

This commit is contained in:
Luana
2023-06-29 02:50:32 -03:00
committed by Shish
parent 84d232ca0d
commit 91710f4c59
4 changed files with 50 additions and 34 deletions

View File

@@ -555,8 +555,9 @@ class Pools extends Extension
$options = $database->get_pairs("SELECT id,title FROM pools ORDER BY title"); $options = $database->get_pairs("SELECT id,title FROM pools ORDER BY title");
$event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", $this->theme->get_bulk_pool_selector($options)); // TODO: Don't cast into strings, make BABBE accept HTMLElement instead.
$event->add_action("bulk_pool_add_new", "Create Pool", "", "", $this->theme->get_bulk_pool_input($event->search_terms)); $event->add_action("bulk_pool_add_existing", "Add To (P)ool", "p", "", (string)$this->theme->get_bulk_pool_selector($options));
$event->add_action("bulk_pool_add_new", "Create Pool", "", "", (string)$this->theme->get_bulk_pool_input($event->search_terms));
} }
public function onBulkAction(BulkActionEvent $event) public function onBulkAction(BulkActionEvent $event)

View File

@@ -4,6 +4,10 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\INPUT;
class PoolsTheme extends Themelet class PoolsTheme extends Themelet
{ {
/** /**
@@ -385,14 +389,22 @@ class PoolsTheme extends Themelet
$this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages); $this->display_paginator($page, "pool/updated", null, $pageNumber, $totalPages);
} }
public function get_bulk_pool_selector(array $options): string public function get_bulk_pool_selector(array $options): HTMLElement
{ {
return (string)$this->build_selector("bulk_pool_select", $options, required: true, empty_option: true); return $this->build_selector("bulk_pool_select", $options, required: true, empty_option: true);
} }
public function get_bulk_pool_input(array $search_terms): string public function get_bulk_pool_input(array $search_terms): HTMLElement
{ {
return "<input type='text' name='bulk_pool_new' placeholder='New pool' required='required' value='".(implode(" ", $search_terms))."' />"; return INPUT(
[
"type"=>"text",
"name"=>"bulk_pool_new",
"placeholder"=>"New Pool",
"required"=>"",
"value"=>implode(" ", $search_terms)
]
);
} }
public function get_help_html(): string public function get_help_html(): string

View File

@@ -203,7 +203,7 @@ class Ratings extends Extension
{ {
global $user; global $user;
$event->add_part( $event->add_part(
$this->theme->get_rater_html( (string)$this->theme->get_rater_html(
$event->image->id, $event->image->id,
$event->image->rating, $event->image->rating,
$user->can(Permissions::EDIT_IMAGE_RATING) $user->can(Permissions::EDIT_IMAGE_RATING)
@@ -345,7 +345,7 @@ class Ratings extends Extension
global $user; global $user;
if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) { if ($user->can(Permissions::BULK_EDIT_IMAGE_RATING)) {
$event->add_action("bulk_rate", "Set (R)ating", "r", "", $this->theme->get_selection_rater_html(["?"])); $event->add_action("bulk_rate", "Set (R)ating", "r", "", (string)$this->theme->get_selection_rater_html(selected_options: ["?"]));
} }
} }

View File

@@ -4,26 +4,34 @@ declare(strict_types=1);
namespace Shimmie2; namespace Shimmie2;
use MicroHTML\HTMLElement;
use function MicroHTML\{TR,TH,TD,SPAN,INPUT};
class RatingsTheme extends Themelet class RatingsTheme extends Themelet
{ {
public function get_rater_html(int $image_id, string $rating, bool $can_rate): string public function get_selection_rater_html(string $name = "rating", array $ratings = [], array $selected_options = []): HTMLElement
{
return $this->build_selector($name, !empty($ratings) ? $ratings : Ratings::get_ratings_dict(), required: true, selected_options: $selected_options);
}
public function get_rater_html(int $image_id, string $rating, bool $can_rate): HTMLElement
{ {
$human_rating = Ratings::rating_to_human($rating); $human_rating = Ratings::rating_to_human($rating);
$html = "
<tr> $html = TR(TH("Rating"));
<th>Rating</th>
<td> if ($can_rate) {
".($can_rate ? " $selector = $this->get_selection_rater_html(selected_options: [$rating]);
<span class='view'>$human_rating</span>
<span class='edit'> $html->appendChild(TD(
".$this->get_selection_rater_html([$rating])." SPAN(["class"=>"view"], $human_rating),
</span> SPAN(["class"=>"edit"], $selector)
" : " ));
$human_rating } else {
")." $html->appendChild(TD($human_rating));
</td> }
</tr>
";
return $html; return $html;
} }
@@ -33,20 +41,15 @@ class RatingsTheme extends Themelet
$html = make_form(make_link("admin/update_ratings"))."<table class='form'>"; $html = make_form(make_link("admin/update_ratings"))."<table class='form'>";
$html .= "<tr><th>Change</th><td>" . $this->build_selector("rating_old", $current_ratings, required: true) . "</td></tr>"; $html .= TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings)));
$html .= "<tr><th>To</th><td>" . $this->build_selector("rating_new", Ratings::get_ratings_dict(), required: true) . "</td></tr>"; $html .= TR(TH("To"), TD($this->get_selection_rater_html("rating_new")));
$html .= "<tr><td colspan='2'><input type='submit' value='Update'></td></tr></table> $html .= TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])));
</form>\n"; $html .= "</table></form>\n";
$page->add_block(new Block("Update Ratings", $html)); $page->add_block(new Block("Update Ratings", $html));
} }
public function get_selection_rater_html(array $selected_options, bool $multiple = false): string
{
return (string)$this->build_selector("rating", Ratings::get_ratings_dict(), multiple: $multiple, empty_option: false, selected_options: $selected_options);
}
public function get_help_html(array $ratings): string public function get_help_html(array $ratings): string
{ {
$output = '<p>Search for posts with one or more possible ratings.</p> $output = '<p>Search for posts with one or more possible ratings.</p>
@@ -89,7 +92,7 @@ class RatingsTheme extends Themelet
<tbody> <tbody>
<tr><td>This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search.</td></tr> <tr><td>This controls the default rating search results will be filtered by, and nothing else. To override in your search results, add rating:* to your search.</td></tr>
<tr><td> <tr><td>
".$this->get_selection_rater_html($selected_ratings, true, $available_ratings)." ".$this->build_selector("ratings", selected_options: $selected_ratings, multiple: true, options: $available_ratings)."
</td></tr> </td></tr>
</tbody> </tbody>
<tfoot> <tfoot>