Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[alias_editor] search #971

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions ext/alias_editor/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,26 @@
use MicroCRUD\TextColumn;
use MicroCRUD\Table;

use MicroHTML\HTMLElement;

use function MicroHTML\emptyHTML;
use function MicroHTML\TABLE as html_TABLE;
use function MicroHTML\THEAD;
use function MicroHTML\TBODY;
use function MicroHTML\TFOOT;
use function MicroHTML\TR;
use function MicroHTML\TH;
use function MicroHTML\TD;
use function MicroHTML\INPUT;
use function MicroHTML\FORM;
use function MicroHTML\DIV;
use function MicroHTML\A;
use function MicroHTML\B;
use function MicroHTML\BR;

class AliasTable extends Table
{
public $search_url = null;
public function __construct(\FFSPHP\PDO $db)
{
parent::__construct($db);
Expand All @@ -26,6 +44,33 @@ public function __construct(\FFSPHP\PDO $db)
$this->order_by = ["oldtag"];
$this->table_attrs = ["class" => "zebra"];
}

public function thead(): HTMLElement
{
$thead = THEAD(["id"=>"read"]);

$tr = TR();
foreach ($this->columns as $col) {
if ($col->sortable) {
$sort_name = (@$this->inputs["r__sort"] == $col->name) ? "-{$col->name}" : $col->name;
$sort = "?" . $this->modify_url(["r__sort"=>$sort_name]);
$tr->appendChild(TH(A(["href"=>$sort], $col->title)));
} else {
$tr->appendChild(TH($col->title));
}
}
$thead->appendChild($tr);

if ($this->create_url) {
$tr = TR();
foreach ($this->columns as $col) {
$tr->appendChild(TD($col->read_input($this->inputs)));
}
}
$thead->appendChild(FORM(["method"=>"POST", 'action'=>$this->search_url], $tr));

return $thead;
}
}

class AddAliasEvent extends Event
Expand Down Expand Up @@ -91,7 +136,17 @@ public function onPageRequest(PageRequestEvent $event)
$t->token = $user->get_auth_token();
$t->inputs = $_GET;
$t->size = $config->get_int('alias_items_per_page', 30);
$input = validate_input(["r_oldtag"=>"string,optional", "r_newtag"=>"string,optional"]);
$tag_inputs = [];
if (isset($_GET["r_oldtag"])) {
$tag_inputs["r_oldtag"] = $_GET["r_oldtag"];
}
if (isset($_GET["r_newtag"])) {
$tag_inputs["r_newtag"] = $_GET["r_newtag"];
}
$t->inputs = array_merge($t->inputs, $input, $tag_inputs);
if ($user->can(Permissions::MANAGE_ALIAS_LIST)) {
$t->search_url = make_link("alias/list");
$t->create_url = make_link("alias/add");
$t->delete_url = make_link("alias/remove");
}
Expand Down
8 changes: 7 additions & 1 deletion ext/alias_editor/theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ public function display_aliases(HTMLElement $table, HTMLElement $paginator): voi
$page->set_title("Alias List");
$page->set_heading("Alias List");
$page->add_block(new NavBlock());
$page->add_block(new Block("Aliases", $html));
$block = new Block("Aliases", $html);
$block->body = str_replace(
["name='c_oldtag'", "name='c_newtag'"],
["name='c_oldtag' class='autocomplete_tags'", "name='c_newtag' class='autocomplete_tags'"],
$block->body
);
$page->add_block($block);

if ($user->can(Permissions::MANAGE_ALIAS_LIST)) {
$page->add_block(new Block("Bulk Upload", $bulk_html, "main", 51));
Expand Down
Loading