From b9cdf52ec5492c979020bf0d3fa78fb4e9c7e288 Mon Sep 17 00:00:00 2001 From: Peter Knut Date: Mon, 14 Oct 2024 00:49:57 +0200 Subject: [PATCH] Add drag-n-drop moving of rows in table selection filter --- adminer/include/adminer.inc.php | 159 +++++++++++++++++------------- adminer/include/functions.inc.php | 7 +- adminer/static/default.css | 8 +- adminer/static/functions.js | 127 ++++++++++++++++++++++-- editor/include/adminer.inc.php | 12 +-- plugins/plugin.php | 6 +- 6 files changed, 228 insertions(+), 91 deletions(-) diff --git a/adminer/include/adminer.inc.php b/adminer/include/adminer.inc.php index 7dfb5ced..1f4331fd 100644 --- a/adminer/include/adminer.inc.php +++ b/adminer/include/adminer.inc.php @@ -393,100 +393,123 @@ class Adminer { echo "\n"; } - /** Print columns box in select - * @param array result of selectColumnsProcess()[0] - * @param array selectable columns - * @return null - */ - function selectColumnsPrint($select, $columns) { + /** + * Prints columns box in select filter. + * + * @param array $select result of selectColumnsProcess()[0] + * @param array $columns selectable columns + */ + function selectColumnsPrint(array $select, array $columns) { global $functions, $grouping; - print_fieldset("select", lang('Select'), $select); + + print_fieldset("select", lang('Select'), $select, true); + + $_GET["columns"][""] = []; $i = 0; - $select[""] = array(); - foreach ($select as $key => $val) { - $val = $_GET["columns"][$key]; + + foreach ($_GET["columns"] as $key => $val) { + if ($key != "" && $val["col"] == "") continue; + $column = select_input( - " name='columns[$i][col]'", + "name='columns[$i][col]'", $columns, $val["col"], - ($key !== "" ? "selectFieldChange" : "selectAddRow") + $key !== "" ? "selectFieldChange" : "selectAddRow" ); - echo "
" . ($functions || $grouping ? "" - . on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'", 1) - . script("qsl('select').onchange = function () { helpClose();" . ($key !== "" ? "" : " qsl('select, input', this.parentNode).onchange();") . " };", "") - . "($column)" : $column) - . " " - . script('qsl(".icon").onclick = selectRemoveRow;', "") - . "
\n"; + + echo "
", + "="; + + if ($functions || $grouping) { + echo "", + on_help("getTarget(event).value && getTarget(event).value.replace(/ |\$/, '(') + ')'", 1), + script("qsl('select').onchange = (event) => { helpClose();" . ($key !== "" ? "" : " qsl('select, input:not(.remove)', event.target.parentNode).onchange();") . " };", ""), + "($column)"; + } else { + echo $column; + } + + echo " ", + script("qsl('#fieldset-select .remove').onclick = selectRemoveRow;", ""), + "
\n"; + $i++; } - echo "\n"; + + echo "", script("initSortable('#fieldset-select');"), "\n"; } - /** Print search box in select - * @param array result of selectSearchProcess() - * @param array selectable columns - * @param array - * @return null - */ - function selectSearchPrint($where, $columns, $indexes) { + /** + * Prints search box in select. + * + * @param array $where result of selectSearchProcess() + * @param array $columns selectable columns + */ + function selectSearchPrint(array $where, array $columns, array $indexes) { print_fieldset("search", lang('Search'), $where); + foreach ($indexes as $i => $index) { if ($index["type"] == "FULLTEXT") { - echo "
(" . implode(", ", array_map('h', $index["columns"])) . ") AGAINST"; - echo " "; - echo script("qsl('input').oninput = selectFieldChange;", ""); - echo checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL"); - echo "
\n"; + echo "
(" . implode(", ", array_map('h', $index["columns"])) . ") AGAINST", + " ", + script("qsl('input').oninput = selectFieldChange;", ""), + checkbox("boolean[$i]", 1, isset($_GET["boolean"][$i]), "BOOL"), + "
\n"; } } + $change_next = "this.parentNode.firstChild.onchange();"; foreach (array_merge((array) $_GET["where"], array(array())) as $i => $val) { if (!$val || ("$val[col]$val[val]" != "" && in_array($val["op"], $this->operators))) { - echo "
" . select_input( - " name='where[$i][col]'", - $columns, - $val["col"], - ($val ? "selectFieldChange" : "selectAddRow"), - "(" . lang('anywhere') . ")" - ); - echo html_select("where[$i][op]", $this->operators, $val["op"], $change_next); - echo ""; - echo script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", ""); - echo " "; - echo script('qsl(".icon").onclick = selectRemoveRow;', ""); - echo "
\n"; + echo "
", + select_input( + " name='where[$i][col]'", + $columns, + $val["col"], + ($val ? "selectFieldChange" : "selectAddRow"), + "(" . lang('anywhere') . ")" + ), + html_select("where[$i][op]", $this->operators, $val["op"], $change_next), + "", + script("mixin(qsl('input'), {oninput: function () { $change_next }, onkeydown: selectSearchKeydown, onsearch: selectSearchSearch});", ""), + " ", + script('qsl("#fieldset-search .remove").onclick = selectRemoveRow;', ""), + "
\n"; } } + echo "\n"; } - /** Print order box in select - * @param array result of selectOrderProcess() - * @param array selectable columns - * @param array - * @return null - */ - function selectOrderPrint($order, $columns, $indexes) { - print_fieldset("sort", lang('Sort'), $order); + /** + * Prints order box in select filter. + * + * @param array $order result of selectOrderProcess() + * @param array $columns selectable columns + */ + function selectOrderPrint(array $order, array $columns, array $indexes) { + print_fieldset("sort", lang('Sort'), $order, true); + + $_GET["order"][""] = ""; $i = 0; + foreach ((array) $_GET["order"] as $key => $val) { - if ($val != "") { - echo "
" . select_input(" name='order[$i]'", $columns, $val, "selectFieldChange"); - echo checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')); - echo " "; - echo script('qsl(".icon").onclick = selectRemoveRow;', ""); - echo "
\n"; - $i++; - } + if ($key != "" && $val == "") continue; + + echo "
", + "=", + select_input("name='order[$i]'", $columns, $val, $key !== "" ? "selectFieldChange" : "selectAddRow"), + checkbox("desc[$i]", 1, isset($_GET["desc"][$key]), lang('descending')), + " ", + script('qsl("#fieldset-sort .remove").onclick = selectRemoveRow;', ""), + "
\n"; + + $i++; } - echo "
" . select_input(" name='order[$i]'", $columns, "", "selectAddRow"); - echo checkbox("desc[$i]", 1, false, lang('descending')); - echo " "; - echo script('qsl(".icon").onclick = selectRemoveRow;', ""); - echo "
\n"; - echo "\n"; + + echo "", script("initSortable('#fieldset-sort');"), "\n"; } /** Print limit box in select diff --git a/adminer/include/functions.inc.php b/adminer/include/functions.inc.php index b7d1d5ef..7e183d6b 100644 --- a/adminer/include/functions.inc.php +++ b/adminer/include/functions.inc.php @@ -235,7 +235,7 @@ function html_select($name, $options, $value = "", $onchange = true, $labelled_b */ function select_input($attrs, $options, $value = "", $onchange = "", $placeholder = "") { $tag = ($options ? "select" : "input"); - return "<$tag$attrs" . ($options + return "<$tag $attrs" . ($options ? ">