From 4a761741187d288c11b83e235f4aba35e164c5df Mon Sep 17 00:00:00 2001 From: jungejason Date: Fri, 8 Apr 2011 16:15:00 -0700 Subject: [PATCH] Adding paging to transcript pages Summary: enable paging by adding a AphrontPagerView to the two transcript page. Test Plan: test the paging on both pages. Also test it with a certain phid is given. Reviewed By: epriestley Reviewers: epriestley, tuomaspelkonen CC: epriestley, jungejason Differential Revision: 116 --- .../HeraldTranscriptListController.php | 26 +++++++++++--- .../controller/transcriptlist/__init__.php | 1 + .../list/PhabricatorMetaMTAListController.php | 36 ++++++++++++++++--- .../metamta/controller/list/__init__.php | 4 ++- 4 files changed, 56 insertions(+), 11 deletions(-) diff --git a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php index 1e07887b4f..db69b1612f 100644 --- a/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php +++ b/src/applications/herald/controller/transcriptlist/HeraldTranscriptListController.php @@ -22,6 +22,7 @@ class HeraldTranscriptListController extends HeraldController { $request = $this->getRequest(); + // Get one page of data together with the pager. // Pull these objects manually since the serialized fields are gigantic. $transcript = new HeraldTranscript(); @@ -32,18 +33,31 @@ class HeraldTranscriptListController extends HeraldController { $where_clause = qsprintf( $conn_r, 'WHERE objectPHID = %s', - $phid - ); + $phid); } + $offset = $request->getInt('offset', 0); + $page_size = 100; + $limit_clause = qsprintf( + $conn_r, + 'LIMIT %d, %d', + $offset, $page_size + 1); + $data = queryfx_all( $conn_r, 'SELECT id, objectPHID, time, duration, dryRun FROM %T %Q ORDER BY id DESC - LIMIT 100', + %Q', $transcript->getTableName(), - $where_clause); + $where_clause, + $limit_clause); + + $pager = new AphrontPagerView(); + $pager->getPageSize($page_size); + $pager->setHasMorePages(count($data) == $page_size + 1); + $pager->setOffset($offset); + $pager->setURI($request->getRequestURI(), 'offset'); /* @@ -73,6 +87,7 @@ class HeraldTranscriptListController extends HeraldController { $filter); */ + // Render the table. $handles = array(); if ($data) { $phids = ipull($data, 'objectPHID', 'objectPHID'); @@ -118,10 +133,11 @@ class HeraldTranscriptListController extends HeraldController { 'action', )); - + // Render the whole page. $panel = new AphrontPanelView(); $panel->setHeader('Herald Transcripts'); $panel->appendChild($table); + $panel->appendChild($pager); return $this->buildStandardPageResponse( $panel, diff --git a/src/applications/herald/controller/transcriptlist/__init__.php b/src/applications/herald/controller/transcriptlist/__init__.php index 3a574f58ed..13aacd82dc 100644 --- a/src/applications/herald/controller/transcriptlist/__init__.php +++ b/src/applications/herald/controller/transcriptlist/__init__.php @@ -11,6 +11,7 @@ phutil_require_module('phabricator', 'applications/herald/storage/transcript/bas phutil_require_module('phabricator', 'applications/phid/handle/data'); phutil_require_module('phabricator', 'storage/qsprintf'); phutil_require_module('phabricator', 'storage/queryfx'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); diff --git a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php index 2d93fd140d..be4e328587 100644 --- a/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php +++ b/src/applications/metamta/controller/list/PhabricatorMetaMTAListController.php @@ -19,17 +19,41 @@ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController { public function processRequest() { - $related_phid = $this->getRequest()->getStr('phid'); + // Get a page of mails together with pager. + $request = $this->getRequest(); + $offset = $request->getInt('offset', 0); + $related_phid = $request->getStr('phid'); + + $pager = new AphrontPagerView(); + $pager->setOffset($offset); + $pager->setURI($request->getRequestURI(), 'offset'); + + $mail = new PhabricatorMetaMTAMail(); + $conn_r = $mail->establishConnection('r'); if ($related_phid) { - $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( - 'relatedPHID = %s ORDER BY id DESC LIMIT 100', + $where_clause = qsprintf( + $conn_r, + 'WHERE relatedPHID = %s', $related_phid); } else { - $mails = id(new PhabricatorMetaMTAMail())->loadAllWhere( - '1 = 1 ORDER BY id DESC LIMIT 100'); + $where_clause = 'WHERE 1 = 1'; } + $data = queryfx_all( + $conn_r, + 'SELECT * FROM %T + %Q + ORDER BY id DESC + LIMIT %d, %d', + $mail->getTableName(), + $where_clause, + $pager->getOffset(), $pager->getPageSize() + 1); + $data = $pager->sliceResults($data); + + $mails = $mail->loadAllFromArray($data); + + // Render the details table. $rows = array(); foreach ($mails as $mail) { $rows[] = array( @@ -71,10 +95,12 @@ class PhabricatorMetaMTAListController extends PhabricatorMetaMTAController { 'action', )); + // Render the whole page. $panel = new AphrontPanelView(); $panel->appendChild($table); $panel->setHeader('MetaMTA Messages'); $panel->setCreateButton('Send New Message', '/mail/send/'); + $panel->appendChild($pager); return $this->buildStandardPageResponse( $panel, diff --git a/src/applications/metamta/controller/list/__init__.php b/src/applications/metamta/controller/list/__init__.php index 79f3117912..49a41c7b7f 100644 --- a/src/applications/metamta/controller/list/__init__.php +++ b/src/applications/metamta/controller/list/__init__.php @@ -8,11 +8,13 @@ phutil_require_module('phabricator', 'applications/metamta/controller/base'); phutil_require_module('phabricator', 'applications/metamta/storage/mail'); +phutil_require_module('phabricator', 'storage/qsprintf'); +phutil_require_module('phabricator', 'storage/queryfx'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel'); phutil_require_module('phutil', 'markup'); -phutil_require_module('phutil', 'utils'); phutil_require_source('PhabricatorMetaMTAListController.php');