mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 22:10: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:
parent
b71ce90b9c
commit
1491269b72
8 changed files with 57 additions and 106 deletions
|
@ -9,8 +9,8 @@ final class DrydockLeaseStatus extends DrydockConstants {
|
|||
const STATUS_BROKEN = 'broken';
|
||||
const STATUS_DESTROYED = 'destroyed';
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = array(
|
||||
public static function getStatusMap() {
|
||||
return array(
|
||||
self::STATUS_PENDING => pht('Pending'),
|
||||
self::STATUS_ACQUIRED => pht('Acquired'),
|
||||
self::STATUS_ACTIVE => pht('Active'),
|
||||
|
@ -18,19 +18,15 @@ final class DrydockLeaseStatus extends DrydockConstants {
|
|||
self::STATUS_BROKEN => pht('Broken'),
|
||||
self::STATUS_DESTROYED => pht('Destroyed'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = self::getStatusMap();
|
||||
return idx($map, $status, pht('Unknown'));
|
||||
}
|
||||
|
||||
public static function getAllStatuses() {
|
||||
return array(
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_ACQUIRED,
|
||||
self::STATUS_ACTIVE,
|
||||
self::STATUS_RELEASED,
|
||||
self::STATUS_BROKEN,
|
||||
self::STATUS_DESTROYED,
|
||||
);
|
||||
return array_keys(self::getStatusMap());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -8,26 +8,23 @@ final class DrydockResourceStatus extends DrydockConstants {
|
|||
const STATUS_BROKEN = 'broken';
|
||||
const STATUS_DESTROYED = 'destroyed';
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = array(
|
||||
public static function getStatusMap() {
|
||||
return array(
|
||||
self::STATUS_PENDING => pht('Pending'),
|
||||
self::STATUS_ACTIVE => pht('Active'),
|
||||
self::STATUS_RELEASED => pht('Released'),
|
||||
self::STATUS_BROKEN => pht('Broken'),
|
||||
self::STATUS_DESTROYED => pht('Destroyed'),
|
||||
);
|
||||
}
|
||||
|
||||
public static function getNameForStatus($status) {
|
||||
$map = self::getStatusMap();
|
||||
return idx($map, $status, pht('Unknown'));
|
||||
}
|
||||
|
||||
public static function getAllStatuses() {
|
||||
return array(
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_ACTIVE,
|
||||
self::STATUS_RELEASED,
|
||||
self::STATUS_BROKEN,
|
||||
self::STATUS_DESTROYED,
|
||||
);
|
||||
return array_keys(self::getStatusMap());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -9,6 +9,12 @@ final class DrydockBlueprintCoreCustomField
|
|||
}
|
||||
|
||||
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();
|
||||
$specs = $impl->getFieldSpecifications();
|
||||
|
||||
|
|
|
@ -85,21 +85,4 @@ final class DrydockBlueprintQuery extends DrydockQuery {
|
|||
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,
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -11,17 +11,19 @@ final class DrydockBlueprintSearchEngine
|
|||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
return new PhabricatorSavedQuery();
|
||||
public function newQuery() {
|
||||
return id(new DrydockBlueprintQuery());
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
return new DrydockBlueprintQuery();
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved) {}
|
||||
protected function buildCustomSearchFields() {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/drydock/blueprint/'.$path;
|
||||
|
|
|
@ -11,46 +11,27 @@ final class DrydockLeaseSearchEngine
|
|||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$saved->setParameter(
|
||||
'statuses',
|
||||
$this->readListFromRequest($request, 'statuses'));
|
||||
|
||||
return $saved;
|
||||
public function newQuery() {
|
||||
return new DrydockLeaseQuery();
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new DrydockLeaseQuery());
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
$statuses = $saved->getParameter('statuses', array());
|
||||
if ($statuses) {
|
||||
$query->withStatuses($statuses);
|
||||
if ($map['statuses']) {
|
||||
$query->withStatuses($map['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 buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorSearchCheckboxesField())
|
||||
->setLabel(pht('Statuses'))
|
||||
->setKey('statuses')
|
||||
->setOptions(DrydockLeaseStatus::getStatusMap()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
|
|
@ -11,45 +11,27 @@ final class DrydockResourceSearchEngine
|
|||
return 'PhabricatorDrydockApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
|
||||
$saved->setParameter(
|
||||
'statuses',
|
||||
$this->readListFromRequest($request, 'statuses'));
|
||||
|
||||
return $saved;
|
||||
public function newQuery() {
|
||||
return new DrydockResourceQuery();
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new DrydockResourceQuery());
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
$statuses = $saved->getParameter('statuses', array());
|
||||
if ($statuses) {
|
||||
$query->withStatuses($statuses);
|
||||
if ($map['statuses']) {
|
||||
$query->withStatuses($map['statuses']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved) {
|
||||
|
||||
$statuses = $saved->getParameter('statuses', array());
|
||||
|
||||
$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 buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorSearchCheckboxesField())
|
||||
->setLabel(pht('Statuses'))
|
||||
->setKey('statuses')
|
||||
->setOptions(DrydockResourceStatus::getStatusMap()),
|
||||
);
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
|
|
|
@ -64,6 +64,10 @@ final class DrydockBlueprint extends DrydockDAO
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function hasImplementation() {
|
||||
return ($this->implementation !== self::ATTACHABLE);
|
||||
}
|
||||
|
||||
public function getDetail($key, $default = null) {
|
||||
return idx($this->details, $key, $default);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue