Skip to content

Commit

Permalink
fixed bug in pagination of datagrids.
Browse files Browse the repository at this point in the history
  • Loading branch information
padams committed Jul 5, 2010
1 parent 9c9bde6 commit e9d7546
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 14 deletions.
9 changes: 5 additions & 4 deletions modules/base/classes/resultSetManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -1242,22 +1243,22 @@ 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;
$base_query_params['format'] = $this->format;

// 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;
}
Expand Down
36 changes: 31 additions & 5 deletions modules/base/js/owa.resultSetExplorer.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
OWA.setSetting('debug', true);
OWA.resultSetExplorer = function(dom_id, options) {

this.dom_id = dom_id || '';
Expand Down Expand Up @@ -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 = '<a href="' + new_url + '">' + cellvalue + '</a>';
return link;
}
});



if (this.resultSet.resultsReturned > 0) {

// happens with first results set when loading from URL.
Expand Down Expand Up @@ -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) {
Expand All @@ -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 = '<a href="' + new_url + '">' + cellvalue + '</a>';
return link;
}
});
*/
},

makeGridColumnDef : function(column) {
Expand Down Expand Up @@ -419,7 +442,7 @@ OWA.resultSetExplorer.prototype = {
p = p + '<span>Next Page</span></LI>';

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();
Expand Down Expand Up @@ -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;
}
Expand All @@ -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;
},

Expand Down Expand Up @@ -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;
Expand Down
8 changes: 4 additions & 4 deletions modules/base/module.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'));

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion modules/base/templates/report_dashboard.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit e9d7546

Please sign in to comment.