Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F94198
D7827.diff
All Users
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
11 KB
Referenced Files
None
Subscribers
None
D7827.diff
View Options
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -653,6 +653,7 @@
'DrydockLeaseListController' => 'applications/drydock/controller/DrydockLeaseListController.php',
'DrydockLeaseQuery' => 'applications/drydock/query/DrydockLeaseQuery.php',
'DrydockLeaseReleaseController' => 'applications/drydock/controller/DrydockLeaseReleaseController.php',
+ 'DrydockLeaseSearchEngine' => 'applications/drydock/query/DrydockLeaseSearchEngine.php',
'DrydockLeaseStatus' => 'applications/drydock/constants/DrydockLeaseStatus.php',
'DrydockLeaseViewController' => 'applications/drydock/controller/DrydockLeaseViewController.php',
'DrydockLocalCommandInterface' => 'applications/drydock/interface/command/DrydockLocalCommandInterface.php',
@@ -3046,10 +3047,19 @@
'DrydockController' => 'PhabricatorController',
'DrydockDAO' => 'PhabricatorLiskDAO',
'DrydockFilesystemInterface' => 'DrydockInterface',
- 'DrydockLease' => 'DrydockDAO',
- 'DrydockLeaseListController' => 'DrydockController',
- 'DrydockLeaseQuery' => 'PhabricatorOffsetPagedQuery',
+ 'DrydockLease' =>
+ array(
+ 0 => 'DrydockDAO',
+ 1 => 'PhabricatorPolicyInterface',
+ ),
+ 'DrydockLeaseListController' =>
+ array(
+ 0 => 'DrydockController',
+ 1 => 'PhabricatorApplicationSearchResultsControllerInterface',
+ ),
+ 'DrydockLeaseQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'DrydockLeaseReleaseController' => 'DrydockController',
+ 'DrydockLeaseSearchEngine' => 'PhabricatorApplicationSearchEngine',
'DrydockLeaseStatus' => 'DrydockConstants',
'DrydockLeaseViewController' => 'DrydockController',
'DrydockLocalCommandInterface' => 'DrydockCommandInterface',
diff --git a/src/applications/drydock/application/PhabricatorApplicationDrydock.php b/src/applications/drydock/application/PhabricatorApplicationDrydock.php
--- a/src/applications/drydock/application/PhabricatorApplicationDrydock.php
+++ b/src/applications/drydock/application/PhabricatorApplicationDrydock.php
@@ -46,7 +46,7 @@
'(?P<id>[1-9]\d*)/close/' => 'DrydockResourceCloseController',
),
'lease/' => array(
- '' => 'DrydockLeaseListController',
+ '(?:query/(?P<queryKey>[^/]+)/)?' => 'DrydockLeaseListController',
'(?P<id>[1-9]\d*)/' => 'DrydockLeaseViewController',
'(?P<id>[1-9]\d*)/release/' => 'DrydockLeaseReleaseController',
),
diff --git a/src/applications/drydock/constants/DrydockLeaseStatus.php b/src/applications/drydock/constants/DrydockLeaseStatus.php
--- a/src/applications/drydock/constants/DrydockLeaseStatus.php
+++ b/src/applications/drydock/constants/DrydockLeaseStatus.php
@@ -10,16 +10,27 @@
const STATUS_EXPIRED = 4;
public static function getNameForStatus($status) {
- static $map = array(
- self::STATUS_PENDING => 'Pending',
- self::STATUS_ACQUIRING => 'Acquiring',
- self::STATUS_ACTIVE => 'Active',
- self::STATUS_RELEASED => 'Released',
- self::STATUS_BROKEN => 'Broken',
- self::STATUS_EXPIRED => 'Expired',
+ $map = array(
+ self::STATUS_PENDING => pht('Pending'),
+ self::STATUS_ACQUIRING => pht('Acquiring'),
+ self::STATUS_ACTIVE => pht('Active'),
+ self::STATUS_RELEASED => pht('Released'),
+ self::STATUS_BROKEN => pht('Broken'),
+ self::STATUS_EXPIRED => pht('Expired'),
);
- return idx($map, $status, 'Unknown');
+ return idx($map, $status, pht('Unknown'));
+ }
+
+ public static function getAllStatuses() {
+ return array(
+ self::STATUS_PENDING,
+ self::STATUS_ACQUIRING,
+ self::STATUS_ACTIVE,
+ self::STATUS_RELEASED,
+ self::STATUS_BROKEN,
+ self::STATUS_EXPIRED,
+ );
}
}
diff --git a/src/applications/drydock/controller/DrydockController.php b/src/applications/drydock/controller/DrydockController.php
--- a/src/applications/drydock/controller/DrydockController.php
+++ b/src/applications/drydock/controller/DrydockController.php
@@ -2,12 +2,17 @@
abstract class DrydockController extends PhabricatorController {
- final protected function buildSideNav($selected) {
+ final protected function buildSideNav($selected = null) {
$nav = new AphrontSideNavFilterView();
$nav->setBaseURI(new PhutilURI('/drydock/'));
$nav->addFilter('blueprint', 'Blueprints');
$nav->addFilter('resource', 'Resources');
- $nav->addFilter('lease', 'Leases');
+
+ id(new DrydockLeaseSearchEngine())
+ ->setViewer($this->getRequest()->getUser())
+ ->addNavigationItems($nav->getMenu(), pht('Leases'));
+
+ $nav->addLabel(pht('Logs'));
$nav->addFilter('log', 'Logs');
$nav->selectFilter($selected, 'resource');
@@ -80,11 +85,12 @@
protected function buildLeaseListView(array $leases) {
assert_instances_of($leases, 'DrydockLease');
- $user = $this->getRequest()->getUser();
+ $viewer = $this->getRequest()->getUser();
$view = new PHUIObjectItemListView();
foreach ($leases as $lease) {
$item = id(new PHUIObjectItemView())
+ ->setUser($viewer)
->setHeader($lease->getLeaseName())
->setHref($this->getApplicationURI('/lease/'.$lease->getID().'/'));
@@ -107,9 +113,7 @@
$status = DrydockLeaseStatus::getNameForStatus($lease->getStatus());
$item->addAttribute($status);
-
- $date_created = phabricator_date($lease->getDateCreated(), $user);
- $item->addAttribute(pht('Created on %s', $date_created));
+ $item->setEpoch($lease->getDateCreated());
if ($lease->isActive()) {
$item->setBarColor('green');
diff --git a/src/applications/drydock/controller/DrydockLeaseListController.php b/src/applications/drydock/controller/DrydockLeaseListController.php
--- a/src/applications/drydock/controller/DrydockLeaseListController.php
+++ b/src/applications/drydock/controller/DrydockLeaseListController.php
@@ -1,46 +1,34 @@
<?php
-final class DrydockLeaseListController extends DrydockController {
+final class DrydockLeaseListController extends DrydockController
+ implements PhabricatorApplicationSearchResultsControllerInterface {
- public function processRequest() {
- $request = $this->getRequest();
- $user = $request->getUser();
-
- $nav = $this->buildSideNav('lease');
-
- $pager = new AphrontPagerView();
- $pager->setURI(new PhutilURI('/drydock/lease/'), 'offset');
- $pager->setOffset($request->getInt('offset'));
-
- $leases = id(new DrydockLeaseQuery())
- ->setViewer($user)
- ->executeWithOffsetPager($pager);
-
- $title = pht('Leases');
+ private $queryKey;
- $header = id(new PHUIHeaderView())
- ->setHeader($title);
+ public function shouldAllowPublic() {
+ return true;
+ }
- $lease_list = $this->buildLeaseListView($leases);
+ public function willProcessRequest(array $data) {
+ $this->queryKey = idx($data, 'queryKey');
+ }
- $nav->appendChild(
- array(
- $header,
- $lease_list,
- $pager,
- ));
+ public function processRequest() {
+ $request = $this->getRequest();
+ $controller = id(new PhabricatorApplicationSearchController($request))
+ ->setQueryKey($this->queryKey)
+ ->setSearchEngine(new DrydockLeaseSearchEngine())
+ ->setNavigation($this->buildSideNav());
- $crumbs = $this->buildApplicationCrumbs();
- $crumbs->addTextCrumb($title, $request->getRequestURI());
- $nav->setCrumbs($crumbs);
+ return $this->delegateToController($controller);
+ }
- return $this->buildApplicationPage(
- $nav,
- array(
- 'device' => true,
- 'title' => $title,
- ));
+ public function renderResultsList(
+ array $leases,
+ PhabricatorSavedQuery $query) {
+ assert_instances_of($leases, 'DrydockLease');
+ return $this->buildLeaseListView($leases);
}
}
diff --git a/src/applications/drydock/query/DrydockLeaseQuery.php b/src/applications/drydock/query/DrydockLeaseQuery.php
--- a/src/applications/drydock/query/DrydockLeaseQuery.php
+++ b/src/applications/drydock/query/DrydockLeaseQuery.php
@@ -5,6 +5,7 @@
private $ids;
private $resourceIDs;
+ private $statuses;
public function withIDs(array $ids) {
$this->ids = $ids;
@@ -16,6 +17,11 @@
return $this;
}
+ public function withStatuses(array $statuses) {
+ $this->statuses = $statuses;
+ return $this;
+ }
+
public function loadPage() {
$table = new DrydockLease();
$conn_r = $table->establishConnection('r');
@@ -67,6 +73,13 @@
$this->ids);
}
+ if ($this->statuses) {
+ $where[] = qsprintf(
+ $conn_r,
+ 'status IN (%Ld)',
+ $this->statuses);
+ }
+
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
diff --git a/src/applications/drydock/query/DrydockLeaseSearchEngine.php b/src/applications/drydock/query/DrydockLeaseSearchEngine.php
new file mode 100644
--- /dev/null
+++ b/src/applications/drydock/query/DrydockLeaseSearchEngine.php
@@ -0,0 +1,81 @@
+<?php
+
+final class DrydockLeaseSearchEngine
+ extends PhabricatorApplicationSearchEngine {
+
+ public function buildSavedQueryFromRequest(AphrontRequest $request) {
+ $saved = new PhabricatorSavedQuery();
+
+ $saved->setParameter(
+ 'statuses',
+ $this->readListFromRequest($request, 'statuses'));
+
+ return $saved;
+ }
+
+ public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
+ $query = id(new DrydockLeaseQuery());
+
+ $statuses = $saved->getParameter('statuses', array());
+ if ($statuses) {
+ $query->withStatuses($statuses);
+ }
+
+ return $query;
+ }
+
+ public function buildSearchForm(
+ AphrontFormView $form,
+ PhabricatorSavedQuery $saved) {
+
+ $statuses = $saved->getParameter('statuses', array());
+
+ $status_control = id(new AphrontFormCheckboxControl())
+ ->setLabel(pht('Status'));
+ foreach (DrydockLeaseStatus::getAllStatuses() as $status) {
+ $status_control->addCheckbox(
+ 'statuses[]',
+ $status,
+ DrydockLeaseStatus::getNameForStatus($status),
+ in_array($status, $statuses));
+ }
+
+ $form
+ ->appendChild($status_control);
+
+ }
+
+ protected function getURI($path) {
+ return '/drydock/lease/'.$path;
+ }
+
+ public function getBuiltinQueryNames() {
+ $names = array(
+ 'active' => pht('Active Leases'),
+ 'all' => pht('All Leases'),
+ );
+
+ return $names;
+ }
+
+ public function buildSavedQueryFromBuiltin($query_key) {
+ $query = $this->newSavedQuery();
+ $query->setQueryKey($query_key);
+
+ switch ($query_key) {
+ case 'active':
+ return $query->setParameter(
+ 'statuses',
+ array(
+ DrydockLeaseStatus::STATUS_PENDING,
+ DrydockLeaseStatus::STATUS_ACQUIRING,
+ DrydockLeaseStatus::STATUS_ACTIVE,
+ ));
+ case 'all':
+ return $query;
+ }
+
+ return parent::buildSavedQueryFromBuiltin($query_key);
+ }
+
+}
diff --git a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
--- a/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
+++ b/src/applications/search/engine/PhabricatorApplicationSearchEngine.php
@@ -108,10 +108,10 @@
}
- public function addNavigationItems(PHUIListView $menu) {
+ public function addNavigationItems(PHUIListView $menu, $label = null) {
$viewer = $this->requireViewer();
- $menu->newLabel(pht('Queries'));
+ $menu->newLabel(coalesce($label, pht('Queries')));
$named_queries = $this->loadEnabledNamedQueries();
File Metadata
Details
Attached
Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/ve/xh/oikbky6t52juica7
Default Alt Text
D7827.diff (11 KB)
Attached To
Mode
D7827: Use ApplicationSearch to manage DrydockLeases
Attached
Detach File
Event Timeline
Log In to Comment