From 241caff7818f69531400eecd1ea63849009bffa9 Mon Sep 17 00:00:00 2001 From: Ammar Yasir Date: Wed, 3 Aug 2011 09:17:16 +0530 Subject: [PATCH] Used AJAX to get data row on point select, hence reducing the amount of data to be sent from server initially for plot. --- js/tbl_zoom_plot.js | 54 +++++++++++++++++++++++++++++---------------- tbl_zoom_select.php | 27 ++++++++++++++++++++++- 2 files changed, 61 insertions(+), 20 deletions(-) diff --git a/js/tbl_zoom_plot.js b/js/tbl_zoom_plot.js index 6060969ee6..9b67311ee7 100644 --- a/js/tbl_zoom_plot.js +++ b/js/tbl_zoom_plot.js @@ -58,7 +58,7 @@ function isEmpty(obj) { ** @param field: field type (as in database structure) **/ function getType(field) { - if(field.toString().search(/int/i) != -1 || field.toString().search(/decimal/i) != -1) + if(field.toString().search(/int/i) != -1 || field.toString().search(/decimal/i) != -1 || field.toString().search(/year/i) != -1) return 'numeric'; else if(field.toString().search(/time/i) != -1) return 'text'; @@ -181,17 +181,17 @@ $(document).ready(function() { //Prevent default submission of form event.preventDefault(); - //Update the data, find changed values + //Find changed values by comparing form values with selectedRow Object var newValues = new Array();//Stores the values changed from original var it = 4; var xChange = false; var yChange = false; - for (key in data[currentData]) { + for (key in selectedRow) { if (key != 'where_clause'){ - var oldVal = data[currentData][key]; + var oldVal = selectedRow[key]; var newVal = ($('#fields_null_id_' + it).attr('checked')) ? null : $('#fieldID_' + it).val(); if (oldVal != newVal){ - data[currentData][key] = newVal; + selectedRow[key] = newVal; newValues[key] = newVal; if(key == xLabel) xChange = true; @@ -201,8 +201,8 @@ $(document).ready(function() { } it++ }//End data update - - //Update the chart series and replot + + //Update the chart series and replot if (xChange || yChange) { var newSeries = new Array(); newSeries[0] = new Object(); @@ -211,9 +211,9 @@ $(document).ready(function() { }; //Logic similar to plot generation, replot only if xAxis changes or yAxis changes. Code includes a lot of checks so as to replot only when necessary if(xChange) { - xCord[currentData] = data[currentData][xLabel]; + xCord[currentData] = selectedRow[xLabel]; if(xType == 'numeric') { - currentChart.series[0].data[currentData].update({ x : data[currentData][xLabel] }); + currentChart.series[0].data[currentData].update({ x : selectedRow[xLabel] }); currentChart.xAxis[0].setExtremes(Array.min(xCord) - 2,Array.max(xCord) + 2); } else { @@ -244,9 +244,9 @@ $(document).ready(function() { } if(yChange) { - yCord[currentData] = data[currentData][yLabel]; + yCord[currentData] = selectedRow[yLabel]; if(yType == 'numeric') { - currentChart.series[0].data[currentData].update({ y : data[currentData][yLabel] }); + currentChart.series[0].data[currentData].update({ y : selectedRow[yLabel] }); currentChart.yAxis[0].setExtremes(Array.min(yCord) - 2,Array.max(yCord) + 2); } else { @@ -326,6 +326,7 @@ $(document).ready(function() { .text(PMA_messages['strShowSearchCriteria']) $('#togglesearchformdiv').show(); + var selectedRow; var columnNames = new Array(); var colorCodes = ['#FF0000','#00FFFF','#0000FF','#0000A0','#FF0080','#800080','#FFFF00','#00FF00','#FF00FF']; var series = new Array(); @@ -362,15 +363,30 @@ $(document).ready(function() { events: { click: function() { var id = this.id; - var j = 4; - for( key in data[id]) { - if (data[id][key] == null) - $('#fields_null_id_' + j).attr('checked', true); - else - $('#fieldID_' + j).val(data[id][key]); - j++; - } + var fid = 4; currentData = id; + // Make AJAX request to tbl_zoom_select.php for getting the complete row info + var post_params = { + 'ajax_request' : true, + 'get_data_row' : true, + 'db' : window.parent.db, + 'table' : window.parent.table, + 'where_clause' : data[id]['where_clause'], + 'token' : window.parent.token, + } + $.post('tbl_zoom_select.php', post_params, function(data) { + // Row is contained in data.row_info, now fill the displayResultForm with row values + for ( key in data.row_info) { + if (data.row_info[key] == null) + $('#fields_null_id_' + fid).attr('checked', true); + else + $('#fieldID_' + fid).val(data.row_info[key]); + fid++; + } + selectedRow = new Object(); + selectedRow = data.row_info; + }); + $("#dataDisplay").dialog("open"); }, } diff --git a/tbl_zoom_select.php b/tbl_zoom_select.php index 8955eecbc3..4ce2001717 100644 --- a/tbl_zoom_select.php +++ b/tbl_zoom_select.php @@ -29,6 +29,23 @@ $GLOBALS['js_include'][] = 'jquery/jquery-ui-1.8.custom.js'; $GLOBALS['js_include'][] = 'jquery/timepicker.js'; +/** + * Handle AJAX request for data row on point select + * @var post_params Object containing parameters for the POST request + */ + +if (isset($_REQUEST['get_data_row']) && $_REQUEST['get_data_row'] == true) { + + $extra_data = array(); + $row_info_query = 'SELECT * FROM `' . $_REQUEST['db'] . '`.`' . $_REQUEST['table'] . '` WHERE ' . $_REQUEST['where_clause']; + $result = PMA_DBI_query( $row_info_query . ";" , null, PMA_DBI_QUERY_STORE); + $fields_meta = PMA_DBI_get_fields_meta($result); + while ($row = PMA_DBI_fetch_assoc($result)) + $extra_data['row_info'] = $row; + + PMA_ajaxResponse(NULL, true, $extra_data); +} + $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaThemeImage); /** * Not selection yet required -> displays the selection form @@ -71,6 +88,7 @@ $titles['Browse'] = PMA_tbl_setTitle($GLOBALS['cfg']['PropertiesIconic'], $pmaTh ?> +
/> + +
@@ -343,7 +365,10 @@ if(isset($zoom_submit) && $inputs[0] != __('pma_null') && $inputs[1] != __('pma_ $uniqueCondition = PMA_getUniqueCondition($result, $fields_cnt, $fields_meta, $tmpRow, true); //Append it to row array as where_clause $row['where_clause'] = $uniqueCondition[0]; - $data[] = $row; + if($dataLabel == $inputs[0] || $dataLabel == $inputs[1]) + $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], 'where_clause' => $uniqueCondition[0]); + else + $data[] = array($inputs[0] => $row[$inputs[0]], $inputs[1] => $row[$inputs[1]], $dataLabel => $row[$dataLabel], 'where_clause' => $uniqueCondition[0]); } ?>