Skip to content

Commit

Permalink
Remember visible columns in Create Table form (bug #493)
Browse files Browse the repository at this point in the history
  • Loading branch information
vrana committed Jan 22, 2019
1 parent 7defb77 commit 21f0481
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 34 deletions.
25 changes: 9 additions & 16 deletions adminer/create.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
$row["fields"][$row["auto_increment_col"]]["auto_increment"] = true;
}

if ($_POST) {
set_adminer_settings(array("comments" => $_POST["comments"], "defaults" => $_POST["defaults"]));
}

if ($_POST && !process_fields($row["fields"]) && !$error) {
if ($_POST["drop"]) {
queries_redirect(substr(ME, 0, -1), lang('Table has been dropped.'), drop_tables(array($TABLE)));
Expand Down Expand Up @@ -173,27 +177,16 @@
<div class="scrollable">
<table cellspacing="0" id="edit-fields" class="nowrap">
<?php
$comments = ($_POST ? $_POST["comments"] : $row["Comment"] != "");
if (!$_POST && !$comments) {
foreach ($row["fields"] as $field) {
if ($field["comment"] != "") {
$comments = true;
break;
}
}
}
edit_fields($row["fields"], $collations, "TABLE", $foreign_keys, $comments);
edit_fields($row["fields"], $collations, "TABLE", $foreign_keys);
?>
</table>
</div>
<p>
<?php echo lang('Auto Increment'); ?>: <input type="number" name="Auto_increment" size="6" value="<?php echo h($row["Auto_increment"]); ?>">
<?php echo checkbox("defaults", 1, !$_POST || $_POST["defaults"], lang('Default values'), "columnShow(this.checked, 5)", "jsonly"); ?>
<?php echo ($_POST ? "" : script("editingHideDefaults();")); ?>
<?php echo checkbox("defaults", 1, ($_POST ? $_POST["defaults"] : adminer_setting("defaults")), lang('Default values'), "columnShow(this.checked, 5)", "jsonly"); ?>
<?php echo (support("comment")
? "<label><input type='checkbox' name='comments' value='1' class='jsonly'" . ($comments ? " checked" : "") . ">" . lang('Comment') . "</label>"
. script("qsl('input').onclick = partial(editingCommentsClick, true);")
. ' <input name="Comment" value="' . h($row["Comment"]) . '" data-maxlength="' . (min_version(5.5) ? 2048 : 60) . '"' . ($comments ? '' : ' class="hidden"') . '>'
? checkbox("comments", 1, ($_POST ? $_POST["comments"] : adminer_setting("comments")), lang('Comment'), "editingCommentsClick(this, true);", "jsonly")
. ' <input name="Comment" value="' . h($row["Comment"]) . '" data-maxlength="' . (min_version(5.5) ? 2048 : 60) . '">'
: '')
; ?>
<p>
Expand Down Expand Up @@ -227,4 +220,4 @@
?>
<input type="hidden" name="token" value="<?php echo $token; ?>">
</form>
<?php echo script("qs('#form')['defaults'].onclick();" . (support("comment") ? " editingCommentsClick.call(qs('#form')['comments']);" : "")); ?>
<?php echo script("qs('#form')['defaults'].onclick();" . (support("comment") ? " editingCommentsClick(qs('#form')['comments']);" : "")); ?>
32 changes: 28 additions & 4 deletions adminer/include/editing.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,31 @@ function referencable_primary($self) {
return $return;
}

/** Get settings stored in a cookie
* @return array
*/
function adminer_settings() {
parse_str($_COOKIE["adminer_settings"], $settings);
return $settings;
}

/** Get setting stored in a cookie
* @param string
* @return array
*/
function adminer_setting($key) {
$settings = adminer_settings();
return $settings[$key];
}

/** Store settings to a cookie
* @param array
* @return bool
*/
function set_adminer_settings($settings) {
return cookie("adminer_settings", http_build_query($settings + adminer_settings()));
}

/** Print SQL <textarea> tag
* @param string
* @param string or array in which case [0] of every element is used
Expand Down Expand Up @@ -236,10 +261,9 @@ function type_class($type) {
* @param array
* @param string TABLE or PROCEDURE
* @param array returned by referencable_primary()
* @param bool display comments column
* @return null
*/
function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = array(), $comments = false) {
function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = array()) {
global $inout;
$fields = array_values($fields);
?>
Expand All @@ -259,7 +283,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
'mssql' => "ms186775.aspx",
)); ?>
<td id="label-default"><?php echo lang('Default value'); ?>
<?php echo (support("comment") ? "<td id='label-comment'" . ($comments ? "" : " class='hidden'") . ">" . lang('Comment') : ""); ?>
<?php echo (support("comment") ? "<td id='label-comment'>" . lang('Comment') : ""); ?>
<?php } ?>
<td><?php echo "<input type='image' class='icon' name='add[" . (support("move_col") ? 0 : count($fields)) . "]' src='../adminer/static/plus.gif' alt='+' title='" . lang('Add next') . "'>" . script("row_count = " . count($fields) . ";"); ?>
</thead>
Expand All @@ -280,7 +304,7 @@ function edit_fields($fields, $collations, $type = "TABLE", $foreign_keys = arra
<td><?php echo checkbox("fields[$i][null]", 1, $field["null"], "", "", "block", "label-null"); ?>
<td><label class="block"><input type="radio" name="auto_increment_col" value="<?php echo $i; ?>"<?php if ($field["auto_increment"]) { ?> checked<?php } ?> aria-labelledby="label-ai"></label><td><?php
echo checkbox("fields[$i][has_default]", 1, $field["has_default"], "", "", "", "label-default"); ?><input name="fields[<?php echo $i; ?>][default]" value="<?php echo h($field["default"]); ?>" aria-labelledby="label-default"><?php
echo (support("comment") ? "<td" . ($comments ? "" : " class='hidden'") . "><input name='fields[$i][comment]' value='" . h($field["comment"]) . "' data-maxlength='" . (min_version(5.5) ? 1024 : 255) . "' aria-labelledby='label-comment'>" : "");
echo (support("comment") ? "<td><input name='fields[$i][comment]' value='" . h($field["comment"]) . "' data-maxlength='" . (min_version(5.5) ? 1024 : 255) . "' aria-labelledby='label-comment'>" : "");
}
echo "<td>";
echo (support("move_col") ?
Expand Down
20 changes: 6 additions & 14 deletions adminer/static/editing.js
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,6 @@ function columnShow(checked, column) {
}
}

/** Hide column with default values in narrow window
*/
function editingHideDefaults() {
if (innerWidth < document.documentElement.scrollWidth) {
qs('#form')['defaults'].checked = false;
}
}

/** Display partition options
* @this HTMLSelectElement
*/
Expand All @@ -489,14 +481,14 @@ function partitionNameChange() {
}

/** Show or hide comment fields
* @param HTMLInputElement
* @param [boolean] whether to focus Comment if checked
* @this HTMLInputElement
*/
function editingCommentsClick(focus) {
var comment = this.form['Comment'];
columnShow(this.checked, 6);
alterClass(comment, 'hidden', !this.checked);
if (focus && this.checked) {
function editingCommentsClick(el, focus) {
var comment = el.form['Comment'];
columnShow(el.checked, 6);
alterClass(comment, 'hidden', !el.checked);
if (focus && el.checked) {
comment.focus();
}
}
Expand Down
1 change: 1 addition & 0 deletions changes.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Adminer 4.7.1-dev:
Display the tables scrollbar (bug #647)
Remember visible columns in Create Table form (bug #493)
Add autocomplete attributes to login form
PHP <5.4 compatibility even with ClickHouse enabled (regression from 4.7.0)
SQLite: Hide server field in login form
Expand Down

0 comments on commit 21f0481

Please sign in to comment.