1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-19 12:00:55 +01:00

Modernize Drydock SearchEngine implementations

Summary:
Ref T9252. Move these to the more modern stuff to pick up ordering and interface support for free.

Also work around the blueprint / custom field integration a little more gracefully.

Test Plan: Searched for blueprints, resources and leases.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9252

Differential Revision: https://secure.phabricator.com/D14155
This commit is contained in:
epriestley 2015-09-24 09:56:49 -07:00
parent b71ce90b9c
commit 1491269b72
8 changed files with 57 additions and 106 deletions

View file

@ -9,8 +9,8 @@ final class DrydockLeaseStatus extends DrydockConstants {
const STATUS_BROKEN = 'broken'; const STATUS_BROKEN = 'broken';
const STATUS_DESTROYED = 'destroyed'; const STATUS_DESTROYED = 'destroyed';
public static function getNameForStatus($status) { public static function getStatusMap() {
$map = array( return array(
self::STATUS_PENDING => pht('Pending'), self::STATUS_PENDING => pht('Pending'),
self::STATUS_ACQUIRED => pht('Acquired'), self::STATUS_ACQUIRED => pht('Acquired'),
self::STATUS_ACTIVE => pht('Active'), self::STATUS_ACTIVE => pht('Active'),
@ -18,19 +18,15 @@ final class DrydockLeaseStatus extends DrydockConstants {
self::STATUS_BROKEN => pht('Broken'), self::STATUS_BROKEN => pht('Broken'),
self::STATUS_DESTROYED => pht('Destroyed'), self::STATUS_DESTROYED => pht('Destroyed'),
); );
}
public static function getNameForStatus($status) {
$map = self::getStatusMap();
return idx($map, $status, pht('Unknown')); return idx($map, $status, pht('Unknown'));
} }
public static function getAllStatuses() { public static function getAllStatuses() {
return array( return array_keys(self::getStatusMap());
self::STATUS_PENDING,
self::STATUS_ACQUIRED,
self::STATUS_ACTIVE,
self::STATUS_RELEASED,
self::STATUS_BROKEN,
self::STATUS_DESTROYED,
);
} }
} }

View file

@ -8,26 +8,23 @@ final class DrydockResourceStatus extends DrydockConstants {
const STATUS_BROKEN = 'broken'; const STATUS_BROKEN = 'broken';
const STATUS_DESTROYED = 'destroyed'; const STATUS_DESTROYED = 'destroyed';
public static function getNameForStatus($status) { public static function getStatusMap() {
$map = array( return array(
self::STATUS_PENDING => pht('Pending'), self::STATUS_PENDING => pht('Pending'),
self::STATUS_ACTIVE => pht('Active'), self::STATUS_ACTIVE => pht('Active'),
self::STATUS_RELEASED => pht('Released'), self::STATUS_RELEASED => pht('Released'),
self::STATUS_BROKEN => pht('Broken'), self::STATUS_BROKEN => pht('Broken'),
self::STATUS_DESTROYED => pht('Destroyed'), self::STATUS_DESTROYED => pht('Destroyed'),
); );
}
public static function getNameForStatus($status) {
$map = self::getStatusMap();
return idx($map, $status, pht('Unknown')); return idx($map, $status, pht('Unknown'));
} }
public static function getAllStatuses() { public static function getAllStatuses() {
return array( return array_keys(self::getStatusMap());
self::STATUS_PENDING,
self::STATUS_ACTIVE,
self::STATUS_RELEASED,
self::STATUS_BROKEN,
self::STATUS_DESTROYED,
);
} }
} }

View file

@ -9,6 +9,12 @@ final class DrydockBlueprintCoreCustomField
} }
public function createFields($object) { public function createFields($object) {
// If this is a generic object without an attached implementation (for
// example, via ApplicationSearch), just don't build any custom fields.
if (!$object->hasImplementation()) {
return array();
}
$impl = $object->getImplementation(); $impl = $object->getImplementation();
$specs = $impl->getFieldSpecifications(); $specs = $impl->getFieldSpecifications();

View file

@ -85,21 +85,4 @@ final class DrydockBlueprintQuery extends DrydockQuery {
return $where; return $where;
} }
public function getOrderableColumns() {
// TODO: Blueprints implement CustomFields, but can not be ordered by
// custom field classes because the custom fields are not global. There
// is no graceful way to handle this in ApplicationSearch at the moment.
// Just brute force around it until we can clean this up.
return array(
'id' => array(
'table' => $this->getPrimaryTableAlias(),
'column' => 'id',
'reverse' => false,
'type' => 'int',
'unique' => true,
),
);
}
} }

View file

@ -11,17 +11,19 @@ final class DrydockBlueprintSearchEngine
return 'PhabricatorDrydockApplication'; return 'PhabricatorDrydockApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
return new PhabricatorSavedQuery(); return id(new DrydockBlueprintQuery());
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildQueryFromParameters(array $map) {
return new DrydockBlueprintQuery(); $query = $this->newQuery();
return $query;
} }
public function buildSearchForm( protected function buildCustomSearchFields() {
AphrontFormView $form, return array();
PhabricatorSavedQuery $saved) {} }
protected function getURI($path) { protected function getURI($path) {
return '/drydock/blueprint/'.$path; return '/drydock/blueprint/'.$path;

View file

@ -11,46 +11,27 @@ final class DrydockLeaseSearchEngine
return 'PhabricatorDrydockApplication'; return 'PhabricatorDrydockApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new DrydockLeaseQuery();
$saved->setParameter(
'statuses',
$this->readListFromRequest($request, 'statuses'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildQueryFromParameters(array $map) {
$query = id(new DrydockLeaseQuery()); $query = $this->newQuery();
$statuses = $saved->getParameter('statuses', array()); if ($map['statuses']) {
if ($statuses) { $query->withStatuses($map['statuses']);
$query->withStatuses($statuses);
} }
return $query; return $query;
} }
public function buildSearchForm( protected function buildCustomSearchFields() {
AphrontFormView $form, return array(
PhabricatorSavedQuery $saved) { id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Statuses'))
$statuses = $saved->getParameter('statuses', array()); ->setKey('statuses')
->setOptions(DrydockLeaseStatus::getStatusMap()),
$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) { protected function getURI($path) {

View file

@ -11,45 +11,27 @@ final class DrydockResourceSearchEngine
return 'PhabricatorDrydockApplication'; return 'PhabricatorDrydockApplication';
} }
public function buildSavedQueryFromRequest(AphrontRequest $request) { public function newQuery() {
$saved = new PhabricatorSavedQuery(); return new DrydockResourceQuery();
$saved->setParameter(
'statuses',
$this->readListFromRequest($request, 'statuses'));
return $saved;
} }
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { protected function buildQueryFromParameters(array $map) {
$query = id(new DrydockResourceQuery()); $query = $this->newQuery();
$statuses = $saved->getParameter('statuses', array()); if ($map['statuses']) {
if ($statuses) { $query->withStatuses($map['statuses']);
$query->withStatuses($statuses);
} }
return $query; return $query;
} }
public function buildSearchForm( protected function buildCustomSearchFields() {
AphrontFormView $form, return array(
PhabricatorSavedQuery $saved) { id(new PhabricatorSearchCheckboxesField())
->setLabel(pht('Statuses'))
$statuses = $saved->getParameter('statuses', array()); ->setKey('statuses')
->setOptions(DrydockResourceStatus::getStatusMap()),
$status_control = id(new AphrontFormCheckboxControl()) );
->setLabel(pht('Status'));
foreach (DrydockResourceStatus::getAllStatuses() as $status) {
$status_control->addCheckbox(
'statuses[]',
$status,
DrydockResourceStatus::getNameForStatus($status),
in_array($status, $statuses));
}
$form
->appendChild($status_control);
} }
protected function getURI($path) { protected function getURI($path) {

View file

@ -64,6 +64,10 @@ final class DrydockBlueprint extends DrydockDAO
return $this; return $this;
} }
public function hasImplementation() {
return ($this->implementation !== self::ATTACHABLE);
}
public function getDetail($key, $default = null) { public function getDetail($key, $default = null) {
return idx($this->details, $key, $default); return idx($this->details, $key, $default);
} }