Remember column order only in 'Browse' tab

This commit is contained in:
Aris Feryanto 2011-06-13 12:08:17 +07:00
parent c89e0aa2ab
commit cf64d5282b
4 changed files with 61 additions and 23 deletions

View File

@ -9,7 +9,7 @@
alignment: 'horizontal', // 3 possibilities: vertical, horizontal, horizontalflipped
actionSpan: 5,
colOrder: new Array(), // array of column order
tableCreateTime: null, // table creation time
tableCreateTime: null, // table creation time, only available in "Browse tab"
hintShown: false, // true if hint balloon is shown, used by updateHint() method
reorderHint: '', // string, hint for column reordering
sortHint: '', // string, hint for column sorting
@ -163,7 +163,9 @@
this.colMov.objLeft = objPos.left;
this.colMov.n = this.colMov.newn;
// send request to server to remember the column order
this.sendColOrder();
if (this.tableCreateTime) {
this.sendColOrder();
}
this.refreshRestoreButton();
}
@ -293,8 +295,10 @@
this.shiftCol(i, j + 1);
}
}
// send request to server to remember the column order
this.sendColOrder();
if (this.tableCreateTime) {
// send request to server to remember the column order
this.sendColOrder();
}
this.refreshRestoreButton();
},
@ -427,6 +431,7 @@
}
// assign table create time
// #table_create_time will only available if we are in "Browse" tab
g.tableCreateTime = $('#table_create_time').val();
// assign column reorder & column sort hint

View File

@ -1375,12 +1375,14 @@ class PMA_Table
if ($property == self::PROP_COLUMN_ORDER) {
$curr_create_time = self::sGetStatusInfo($this->db_name, $this->name, 'CREATE_TIME');
if (isset($table_create_time) &&
$table_create_time < $curr_create_time) {
$table_create_time > $curr_create_time) {
$this->uiprefs['CREATE_TIME'] = $curr_create_time;
} else {
// there is no $table_create_time, or
// supplied $table_create_time is older than current create time,
// so don't save
return false;
}
$this->uiprefs['CREATE_TIME'] = $curr_create_time;
}
// save the value
$this->uiprefs[$property] = $value;

View File

@ -184,6 +184,20 @@ function PMA_setDisplayMode(&$the_disp_mode, &$the_total)
} // end of the 'PMA_setDisplayMode()' function
/**
* Return true if we are currently browsing a table from the browse tab
*
* @return boolean
*/
function PMA_isBrowsing()
{
return basename($GLOBALS['PMA_PHP_SELF']) == 'sql.php'
&& ! ($is_count || $is_export || $is_func || $is_analyse)
&& isset($analyzed_sql[0]['queryflags']['select_from'])
&& count($analyzed_sql[0]['table_ref']) == 1;
}
/**
* Displays a navigation button
*
@ -377,15 +391,17 @@ function PMA_displayTableNavigation($pos_next, $pos_prev, $sql_query, $id_for_di
<td>
<input class="restore_column" type="submit" value="<?php echo __('Restore column order'); ?>" />
<?php
// generate the column order, if it is set
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
if ($col_order) {
echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
if (PMA_isBrowsing()) {
// generate the column order, if it is set
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
if ($col_order) {
echo '<input id="col_order" type="hidden" value="' . implode(',', $col_order) . '" />';
}
// generate table create time
echo '<input id="table_create_time" type="hidden" value="' .
PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'CREATE_TIME') . '" />';
}
// generate table create time
echo '<input id="table_create_time" type="hidden" value="' .
PMA_Table::sGetStatusInfo($GLOBALS['db'], $GLOBALS['table'], 'CREATE_TIME') . '" />';
// generate text for draggable column hint
echo '<input id="col_order_hint" type="hidden" value="' . __('Drag to reorder') . '" />';
// generate text for sortable column hint
@ -753,9 +769,13 @@ function PMA_displayTableHeaders(&$is_display, &$fields_meta, $fields_cnt = 0, $
}
}
// prepare to get the column order, if there is
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
if (PMA_isBrowsing()) {
// prepare to get the column order, if available
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
} else {
$col_order = false;
}
for ($j = 0; $j < $fields_cnt; $j++) {
// assign $i with appropriate column order
@ -1315,9 +1335,13 @@ function PMA_displayTableBody(&$dt_result, &$is_display, $map, $analyzed_sql) {
// 2. Displays the rows' values
// prepare to get the column order, if there is
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
if (PMA_isBrowsing()) {
// prepare to get the column order, if available
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
} else {
$col_order = false;
}
for ($j = 0; $j < $fields_cnt; ++$j) {
// assign $i with appropriate column order
@ -1689,9 +1713,13 @@ function PMA_displayVerticalTable()
echo '</tr>' . "\n";
} // end if
// prepare to get the column order, if there is
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
if (PMA_isBrowsing()) {
// prepare to get the column order, if available
$pmatable = new PMA_Table($GLOBALS['table'], $GLOBALS['db']);
$col_order = $pmatable->getUiProp(PMA_Table::PROP_COLUMN_ORDER);
} else {
$col_order = false;
}
// Displays data
foreach ($vertical_display['desc'] AS $j => $val) {

View File

@ -153,6 +153,9 @@ if(isset($_REQUEST['get_set_values']) && $_REQUEST['get_set_values'] == true) {
PMA_ajaxResponse(NULL, true, $extra_data);
}
/**
* Check ajax request to set the column order
*/
if(isset($_REQUEST['set_col_order']) && $_REQUEST['set_col_order'] == true) {
$pmatable = new PMA_Table($table, $db);
$retval = $pmatable->setUiProp(PMA_Table::PROP_COLUMN_ORDER, $_REQUEST['col_order'], $_REQUEST['table_create_time']);