ratings ext fully MicroHTML

This commit is contained in:
Luana 2023-06-29 14:44:57 -03:00 committed by Shish
parent 91710f4c59
commit 34b608c4b7
4 changed files with 73 additions and 35 deletions

View file

@ -7,6 +7,9 @@ namespace Shimmie2;
use GQLA\Type; use GQLA\Type;
use GQLA\Field; use GQLA\Field;
use GQLA\Query; use GQLA\Query;
use MicroHTML\HTMLElement;
use function MicroHTML\INPUT;
function _new_user(array $row): User function _new_user(array $row): User
{ {
@ -277,6 +280,13 @@ class User
return '<input type="hidden" name="auth_token" value="'.$at.'">'; return '<input type="hidden" name="auth_token" value="'.$at.'">';
} }
// Temporary? This should eventually become get_auth_html (probably with a different name?).
public function get_auth_microhtml(): HTMLElement
{
$at = $this->get_auth_token();
return INPUT(["type"=>"hidden", "name"=>"auth_token", "value"=>$at]);
}
public function check_auth_token(): bool public function check_auth_token(): bool
{ {
if (defined("UNITTEST")) { if (defined("UNITTEST")) {

View file

@ -754,6 +754,30 @@ function make_form(string $target, string $method="POST", bool $multipart=false,
return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$extra_inputs; return '<form action="'.$target.'" method="'.$method.'" '.$extra.'>'.$extra_inputs;
} }
// Temporary? This should eventually become make_form.
function make_form_microhtml(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit=""): HTMLElement
{
global $user;
if ($method == "GET") {
$extra_inputs = INPUT(["type"=>"hidden", "name"=>"q", "value"=>$target]);
$target = make_link($target);
} else {
$extra_inputs = $user->get_auth_microhtml();
}
$args = ["action"=>$target, "method"=>$method];
if ($multipart) {
$args["enctype"] = "multipart/form-data";
}
if ($onsubmit) {
$args["onsubmit"] = $onsubmit;
}
return FORM($args, $extra_inputs);
}
function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit=""): HTMLElement function SHM_FORM(string $target, string $method="POST", bool $multipart=false, string $form_id="", string $onsubmit=""): HTMLElement
{ {
global $user; global $user;

View file

@ -231,13 +231,8 @@ class Ratings 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();
$block->header = "Ratings";
$ratings = self::get_sorted_ratings(); $ratings = self::get_sorted_ratings();
$event->add_block(new Block("Ratings", $this->theme->get_help_html($ratings)));
$block->body = $this->theme->get_help_html($ratings);
$event->add_block($block);
} }
} }

View file

@ -6,7 +6,8 @@ namespace Shimmie2;
use MicroHTML\HTMLElement; use MicroHTML\HTMLElement;
use function MicroHTML\{TR,TH,TD,SPAN,INPUT}; use function MicroHTML\emptyHTML;
use function MicroHTML\{DIV,INPUT,P,PRE,SPAN,TABLE,TD,TH,TR};
class RatingsTheme extends Themelet class RatingsTheme extends Themelet
{ {
@ -39,42 +40,50 @@ class RatingsTheme extends Themelet
{ {
global $page; global $page;
$html = make_form(make_link("admin/update_ratings"))."<table class='form'>"; $html = make_form_microhtml(make_link("admin/update_ratings"));
$html .= TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings))); $html->appendChild(TABLE(
$html .= TR(TH("To"), TD($this->get_selection_rater_html("rating_new"))); ["class"=>"form"],
TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings))),
$html .= TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"]))); TR(TH("To"), TD($this->get_selection_rater_html("rating_new"))),
$html .= "</table></form>\n"; TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])))
));
$page->add_block(new Block("Update Ratings", $html)); $page->add_block(new Block("Update Ratings", $html));
} }
public function get_help_html(array $ratings): string public function get_help_html(array $ratings): HTMLElement
{ {
$output = '<p>Search for posts with one or more possible ratings.</p> $output = emptyHTML(
<div class="command_example"> P("Search for posts with one or more possible ratings."),
<pre>rating:'.$ratings[0]->search_term.'</pre> DIV(
<p>Returns posts with the '.$ratings[0]->name.' rating.</p> ["class"=>"command_example"],
</div> PRE("rating:" . $ratings[0]->search_term),
<p>Ratings can be abbreviated to a single letter as well</p> P("Returns posts with the " . $ratings[0]->name . " rating.")
<div class="command_example"> ),
<pre>rating:'.$ratings[0]->code.'</pre> P("Ratings can be abbreviated to a single letter as well."),
<p>Returns posts with the '.$ratings[0]->name.' rating.</p> DIV(
</div> ["class"=>"command_example"],
<p>If abbreviations are used, multiple ratings can be searched for.</p> PRE("rating:" . $ratings[0]->code),
<div class="command_example"> P("Returns posts with the " . $ratings[0]->name . " rating.")
<pre>rating:'.$ratings[0]->code.$ratings[1]->code.'</pre> ),
<p>Returns posts with the '.$ratings[0]->name.' or '.$ratings[1]->name.' rating.</p> P("If abbreviations are used, multiple ratings can be searched for."),
</div> DIV(
<p>Available ratings:</p> ["class"=>"command_example"],
<table> PRE("rating:" . $ratings[0]->code . $ratings[1]->code),
<tr><th>Name</th><th>Search Term</th><th>Abbreviation</th></tr> P("Returns posts with the " . $ratings[0]->name . " or " . $ratings[1]->name . " rating.")
'; ),
P("Available ratings:")
);
$table = TABLE(TR(TH("Name"),TH("Search Term"),TH("Abbreviation")));
foreach ($ratings as $rating) { foreach ($ratings as $rating) {
$output .= "<tr><td>{$rating->name}</td><td>{$rating->search_term}</td><td>{$rating->code}</td></tr>"; $table->appendChild(TR(TD($rating->name),TD($rating->search_term),TD($rating->code)));
} }
$output .= "</table>";
$output->appendChild($table);
return $output; return $output;
} }