ratings ext fully MicroHTML
This commit is contained in:
parent
91710f4c59
commit
34b608c4b7
4 changed files with 73 additions and 35 deletions
|
@ -7,6 +7,9 @@ namespace Shimmie2;
|
|||
use GQLA\Type;
|
||||
use GQLA\Field;
|
||||
use GQLA\Query;
|
||||
use MicroHTML\HTMLElement;
|
||||
|
||||
use function MicroHTML\INPUT;
|
||||
|
||||
function _new_user(array $row): User
|
||||
{
|
||||
|
@ -277,6 +280,13 @@ class User
|
|||
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
|
||||
{
|
||||
if (defined("UNITTEST")) {
|
||||
|
|
|
@ -754,6 +754,30 @@ function make_form(string $target, string $method="POST", bool $multipart=false,
|
|||
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
|
||||
{
|
||||
global $user;
|
||||
|
|
|
@ -231,13 +231,8 @@ class Ratings extends Extension
|
|||
public function onHelpPageBuilding(HelpPageBuildingEvent $event)
|
||||
{
|
||||
if ($event->key===HelpPages::SEARCH) {
|
||||
$block = new Block();
|
||||
$block->header = "Ratings";
|
||||
|
||||
$ratings = self::get_sorted_ratings();
|
||||
|
||||
$block->body = $this->theme->get_help_html($ratings);
|
||||
$event->add_block($block);
|
||||
$event->add_block(new Block("Ratings", $this->theme->get_help_html($ratings)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -6,7 +6,8 @@ namespace Shimmie2;
|
|||
|
||||
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
|
||||
{
|
||||
|
@ -39,42 +40,50 @@ class RatingsTheme extends Themelet
|
|||
{
|
||||
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 .= TR(TH("To"), TD($this->get_selection_rater_html("rating_new")));
|
||||
|
||||
$html .= TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])));
|
||||
$html .= "</table></form>\n";
|
||||
$html->appendChild(TABLE(
|
||||
["class"=>"form"],
|
||||
TR(TH("Change"), TD($this->get_selection_rater_html("rating_old", $current_ratings))),
|
||||
TR(TH("To"), TD($this->get_selection_rater_html("rating_new"))),
|
||||
TR(TD(["colspan"=>"2"], INPUT(["type"=>"submit", "value"=>"Update"])))
|
||||
));
|
||||
|
||||
$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>
|
||||
<div class="command_example">
|
||||
<pre>rating:'.$ratings[0]->search_term.'</pre>
|
||||
<p>Returns posts with the '.$ratings[0]->name.' rating.</p>
|
||||
</div>
|
||||
<p>Ratings can be abbreviated to a single letter as well</p>
|
||||
<div class="command_example">
|
||||
<pre>rating:'.$ratings[0]->code.'</pre>
|
||||
<p>Returns posts with the '.$ratings[0]->name.' rating.</p>
|
||||
</div>
|
||||
<p>If abbreviations are used, multiple ratings can be searched for.</p>
|
||||
<div class="command_example">
|
||||
<pre>rating:'.$ratings[0]->code.$ratings[1]->code.'</pre>
|
||||
<p>Returns posts with the '.$ratings[0]->name.' or '.$ratings[1]->name.' rating.</p>
|
||||
</div>
|
||||
<p>Available ratings:</p>
|
||||
<table>
|
||||
<tr><th>Name</th><th>Search Term</th><th>Abbreviation</th></tr>
|
||||
';
|
||||
$output = emptyHTML(
|
||||
P("Search for posts with one or more possible ratings."),
|
||||
DIV(
|
||||
["class"=>"command_example"],
|
||||
PRE("rating:" . $ratings[0]->search_term),
|
||||
P("Returns posts with the " . $ratings[0]->name . " rating.")
|
||||
),
|
||||
P("Ratings can be abbreviated to a single letter as well."),
|
||||
DIV(
|
||||
["class"=>"command_example"],
|
||||
PRE("rating:" . $ratings[0]->code),
|
||||
P("Returns posts with the " . $ratings[0]->name . " rating.")
|
||||
),
|
||||
P("If abbreviations are used, multiple ratings can be searched for."),
|
||||
DIV(
|
||||
["class"=>"command_example"],
|
||||
PRE("rating:" . $ratings[0]->code . $ratings[1]->code),
|
||||
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) {
|
||||
$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;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue