From e9d7546081e398fb710c2abdf2126aa459259cd7 Mon Sep 17 00:00:00 2001 From: padams Date: Mon, 5 Jul 2010 01:43:12 +0000 Subject: [PATCH] fixed bug in pagination of datagrids. --- modules/base/classes/resultSetManager.php | 9 +++--- modules/base/js/owa.resultSetExplorer.js | 36 ++++++++++++++++++--- modules/base/module.php | 8 ++--- modules/base/templates/report_dashboard.tpl | 4 ++- 4 files changed, 43 insertions(+), 14 deletions(-) diff --git a/modules/base/classes/resultSetManager.php b/modules/base/classes/resultSetManager.php index b8386b961..e0f0039aa 100644 --- a/modules/base/classes/resultSetManager.php +++ b/modules/base/classes/resultSetManager.php @@ -1230,8 +1230,9 @@ function makeResultSetUrls() { } // build url for this result set + $link_template = owa_coreAPI::getSetting('base', 'link_template'); $q = $this->buildQueryString($query_params); - $urls['self'] = sprintf("%s?%s", $api_url, $q); + $urls['self'] = sprintf($link_template, $api_url, $q); // build url for next page of result set $next_query_params = $query_params; @@ -1242,14 +1243,14 @@ function makeResultSetUrls() { } $nq = $this->buildQueryString($next_query_params); - $urls['next'] = sprintf("%s?%s", $api_url, $nq); + $urls['next'] = sprintf($link_template, $api_url, $nq); // build previous url if page is greater than 2 if ($this->page >= 2) { $previous_query_params = $query_params; $previous_query_params['page'] = $query_params['page'] - 1; $pq = $this->buildQueryString($previous_query_params); - $urls['previous'] = sprintf("%s?%s", $api_url, $pq); + $urls['previous'] = sprintf($link_template, $api_url, $pq); } $base_query_params = $this->query_params; @@ -1257,7 +1258,7 @@ function makeResultSetUrls() { // build pagination url template for use in constructing $q = $this->buildQueryString($base_query_params); - $url['base_url'] = sprintf("%s?%s", $api_url, $q); + $url['base_url'] = sprintf($link_template, $api_url, $q); return $urls; } diff --git a/modules/base/js/owa.resultSetExplorer.js b/modules/base/js/owa.resultSetExplorer.js index f15888cf2..17f57aa65 100644 --- a/modules/base/js/owa.resultSetExplorer.js +++ b/modules/base/js/owa.resultSetExplorer.js @@ -1,3 +1,4 @@ +OWA.setSetting('debug', true); OWA.resultSetExplorer = function(dom_id, options) { this.dom_id = dom_id || ''; @@ -151,6 +152,25 @@ OWA.resultSetExplorer.prototype = { var that = this; + // custom formattter functions. + jQuery.extend(jQuery.fn.fmatter , { + // urlFormatter allows for a single param substitution. + urlFormatter : function(cellvalue, options, rowdata) { + var sub_value = options.rowId; + //alert(options.rowId); + var name = options.colModel.realColName; + //var name = 'actionName'; + //alert(that.columnLinks[name].template); + OWA.debug(options.rowId-1+' '+name); + //var new_url = that.columnLinks[name].template.replace('%s', escape(sub_value)); + var new_url = that.resultSet.resultsRows[options.rowId-1][name].link; + var link = '' + cellvalue + ''; + return link; + } + }); + + + if (this.resultSet.resultsReturned > 0) { // happens with first results set when loading from URL. @@ -285,7 +305,8 @@ OWA.resultSetExplorer.prototype = { hoverrows: false }); - // custom formattter functions. + /* +// custom formattter functions. jQuery.extend(jQuery.fn.fmatter , { // urlFormatter allows for a single param substitution. urlFormatter : function(cellvalue, options, rowdata) { @@ -294,12 +315,14 @@ OWA.resultSetExplorer.prototype = { var name = options.colModel.realColName; //var name = 'actionName'; //alert(that.columnLinks[name].template); + OWA.debug(options.rowId-1+' '+name); //var new_url = that.columnLinks[name].template.replace('%s', escape(sub_value)); var new_url = that.resultSet.resultsRows[options.rowId-1][name].link; var link = '' + cellvalue + ''; return link; } }); +*/ }, makeGridColumnDef : function(column) { @@ -419,7 +442,7 @@ OWA.resultSetExplorer.prototype = { p = p + 'Next Page'; jQuery("#"+that.dom_id + ' > .owa_resultsExplorerBottomControls > UL').append(p); - jQuery(".owa_nextPageControl").bind('click', function() {that.pageGrid(that.resultSet.next)}); + jQuery("#"+that.dom_id + ' > .owa_resultsExplorerBottomControls > UL > .owa_nextPageControl').bind('click', function() {that.pageGrid(that.resultSet.next)}); if (this.resultSet.page == 1) { jQuery("#"+that.dom_id +' > .owa_resultsExplorerBottomControls > UL > .owa_previousPageControl').hide(); @@ -592,8 +615,9 @@ OWA.resultSetExplorer.prototype = { switch(type) { // convery yyyymmdd to javascript timestamp as flot requires that case 'yyyymmdd': - date = jQuery.datepicker.parseDate('yymmdd', value); - value = Date.parse(date); + + date = jQuery.datepicker.parseDate('yymmdd', value); + value = Date.parse(date); break; } @@ -609,6 +633,7 @@ OWA.resultSetExplorer.prototype = { var curr_year = d.getFullYear(); //alert(d+' date: '+curr_month); var date = curr_month + "/" + curr_date + "/" + curr_year; + //var date = curr_month + "/" + curr_date; return date; }, @@ -678,7 +703,8 @@ OWA.resultSetExplorer.prototype = { if (data_type_x === 'yyyymmdd') { options.xaxis.mode = "time"; - options.xaxis.timeformat = "%m/%d/%y"; + //options.xaxis.timeformat = "%m/%d/%y"; + options.xaxis.timeformat = "%m/%d"; } this.options.areaChart.flot = options; diff --git a/modules/base/module.php b/modules/base/module.php index cc1d30691..6d17ed8da 100644 --- a/modules/base/module.php +++ b/modules/base/module.php @@ -173,7 +173,7 @@ function __construct() { $this->registerCliCommand('build', 'base.build'); /// register API methods /// - $this->registerApiMethod('getResultSet', array($this, 'getResultSet'), array('metrics', 'dimensions', 'siteId', 'constraints', 'sort', 'limit', 'page', 'offset', 'period', 'startDate', 'endDate', 'startTime', 'endTime', 'format')); + $this->registerApiMethod('getResultSet', array($this, 'getResultSet'), array('metrics', 'dimensions', 'siteId', 'constraints', 'sort', 'resultsPerPage', 'page', 'offset', 'period', 'startDate', 'endDate', 'startTime', 'endTime', 'format')); $this->registerApiMethod('getDomstreams', array($this, 'getDomstreams'), array( 'startDate', 'endDate', 'document_id', 'siteId', 'resultsPerPage', 'page', 'format')); @@ -558,7 +558,7 @@ function makeUrlCanonical($url) { * @return paginatedResultSet obj * @link http://wiki.openwebanalytics.com/index.php?title=REST_API */ - function getResultSet($metrics, $dimensions = '', $siteId = '', $constraints = '', $sort = '', $limit = '', $page = '', $offset = '', $period = '', $startDate = '', $endDate = '', $startTime = '', $endTime = '', $format = '') { + function getResultSet($metrics, $dimensions = '', $siteId = '', $constraints = '', $sort = '', $resultsPerPage = '', $page = '', $offset = '', $period = '', $startDate = '', $endDate = '', $startTime = '', $endTime = '', $format = '') { //print_r(func_get_args()); // create the metric obj for the first metric @@ -625,8 +625,8 @@ function getResultSet($metrics, $dimensions = '', $siteId = '', $constraints = ' } // set limit (alt key) - if ($limit) { - $rsm->setLimit($limit); + if ($resultsPerPage) { + $rsm->setLimit($resultsPerPage); } // set page diff --git a/modules/base/templates/report_dashboard.tpl b/modules/base/templates/report_dashboard.tpl index 9316fdc4c..5784bfe28 100644 --- a/modules/base/templates/report_dashboard.tpl +++ b/modules/base/templates/report_dashboard.tpl @@ -111,7 +111,9 @@ 'metrics' => 'pageViews', 'dimensions' => 'pageTitle,pageUrl', 'sort' => 'pageViews-', - 'format' => 'json' + 'format' => 'json', + 'page' => 1, + 'resultsPerPage' => 10 ),true);?>'; OWA.items.tc = new OWA.resultSetExplorer('top-pages');