From 59cd14bc61ab2b716f3652b726a5b61f032f3fe3 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 2 May 2011 08:53:08 -0700 Subject: [PATCH] Add a pager to "Files" Summary: Adds a pager control to the "Files" tool so you can page through files if there are >100. Test Plan: Set page size to a smaller number, paged through files. Reviewed By: aran Reviewers: aran, tuomaspelkonen, jungejason CC: aran Differential Revision: 211 --- .../list/PhabricatorFileListController.php | 18 +++++++++++++++++- .../files/controller/list/__init__.php | 1 + 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/src/applications/files/controller/list/PhabricatorFileListController.php b/src/applications/files/controller/list/PhabricatorFileListController.php index 0fa1f718ba..3820ba8d78 100644 --- a/src/applications/files/controller/list/PhabricatorFileListController.php +++ b/src/applications/files/controller/list/PhabricatorFileListController.php @@ -19,8 +19,23 @@ class PhabricatorFileListController extends PhabricatorFileController { public function processRequest() { + + $request = $this->getRequest(); + + $pager = new AphrontPagerView(); + $pager->setOffset($request->getInt('page')); + $files = id(new PhabricatorFile())->loadAllWhere( - '1 = 1 ORDER BY id DESC LIMIT 100'); + '1 = 1 ORDER BY id DESC LIMIT %d, %d', + $pager->getOffset(), + $pager->getPageSize() + 1); + + if (count($files) > $pager->getPageSize()) { + $files = array_slice($files, 0, $pager->getPageSize(), true); + $pager->setHasMorePages(true); + } + + $pager->setURI($request->getRequestURI(), 'page'); $rows = array(); foreach ($files as $file) { @@ -81,6 +96,7 @@ class PhabricatorFileListController extends PhabricatorFileController { $panel->appendChild($table); $panel->setHeader('Files'); $panel->setCreateButton('Upload File', '/file/upload/'); + $panel->appendChild($pager); return $this->buildStandardPageResponse($panel, array( 'title' => 'Files', diff --git a/src/applications/files/controller/list/__init__.php b/src/applications/files/controller/list/__init__.php index 91678ceb0e..3bdf0dba19 100644 --- a/src/applications/files/controller/list/__init__.php +++ b/src/applications/files/controller/list/__init__.php @@ -8,6 +8,7 @@ phutil_require_module('phabricator', 'applications/files/controller/base'); phutil_require_module('phabricator', 'applications/files/storage/file'); +phutil_require_module('phabricator', 'view/control/pager'); phutil_require_module('phabricator', 'view/control/table'); phutil_require_module('phabricator', 'view/layout/panel');