diff --git a/src/applications/drydock/constants/DrydockLeaseStatus.php b/src/applications/drydock/constants/DrydockLeaseStatus.php index 39f4ce5e1b..f37e4ab9be 100644 --- a/src/applications/drydock/constants/DrydockLeaseStatus.php +++ b/src/applications/drydock/constants/DrydockLeaseStatus.php @@ -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()); } } diff --git a/src/applications/drydock/constants/DrydockResourceStatus.php b/src/applications/drydock/constants/DrydockResourceStatus.php index d88f77625a..d8a860d6a0 100644 --- a/src/applications/drydock/constants/DrydockResourceStatus.php +++ b/src/applications/drydock/constants/DrydockResourceStatus.php @@ -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()); } } diff --git a/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php b/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php index 4317242c10..f4e6ba3a27 100644 --- a/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php +++ b/src/applications/drydock/customfield/DrydockBlueprintCoreCustomField.php @@ -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(); diff --git a/src/applications/drydock/query/DrydockBlueprintQuery.php b/src/applications/drydock/query/DrydockBlueprintQuery.php index c8e53217c9..7404c9457a 100644 --- a/src/applications/drydock/query/DrydockBlueprintQuery.php +++ b/src/applications/drydock/query/DrydockBlueprintQuery.php @@ -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, - ), - ); - } - } diff --git a/src/applications/drydock/query/DrydockBlueprintSearchEngine.php b/src/applications/drydock/query/DrydockBlueprintSearchEngine.php index ccb4c80803..a0420c610c 100644 --- a/src/applications/drydock/query/DrydockBlueprintSearchEngine.php +++ b/src/applications/drydock/query/DrydockBlueprintSearchEngine.php @@ -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; diff --git a/src/applications/drydock/query/DrydockLeaseSearchEngine.php b/src/applications/drydock/query/DrydockLeaseSearchEngine.php index eb5338b2cb..7d85ddbe70 100644 --- a/src/applications/drydock/query/DrydockLeaseSearchEngine.php +++ b/src/applications/drydock/query/DrydockLeaseSearchEngine.php @@ -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) { diff --git a/src/applications/drydock/query/DrydockResourceSearchEngine.php b/src/applications/drydock/query/DrydockResourceSearchEngine.php index 2ebd3971d0..7b0bca0324 100644 --- a/src/applications/drydock/query/DrydockResourceSearchEngine.php +++ b/src/applications/drydock/query/DrydockResourceSearchEngine.php @@ -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) { diff --git a/src/applications/drydock/storage/DrydockBlueprint.php b/src/applications/drydock/storage/DrydockBlueprint.php index ed83ded571..c687c996a9 100644 --- a/src/applications/drydock/storage/DrydockBlueprint.php +++ b/src/applications/drydock/storage/DrydockBlueprint.php @@ -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); }