2013-12-26 12:30:10 -08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DrydockResourceSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2015-09-24 13:52:43 -07:00
|
|
|
private $blueprint;
|
|
|
|
|
|
|
|
public function setBlueprint(DrydockBlueprint $blueprint) {
|
|
|
|
$this->blueprint = $blueprint;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBlueprint() {
|
|
|
|
return $this->blueprint;
|
|
|
|
}
|
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Drydock Resources');
|
|
|
|
}
|
|
|
|
|
2015-02-04 15:47:48 -08:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return 'PhabricatorDrydockApplication';
|
2014-05-13 12:14:33 -07:00
|
|
|
}
|
|
|
|
|
2015-09-24 09:56:49 -07:00
|
|
|
public function newQuery() {
|
2015-09-24 13:52:43 -07:00
|
|
|
$query = new DrydockResourceQuery();
|
|
|
|
|
|
|
|
$blueprint = $this->getBlueprint();
|
|
|
|
if ($blueprint) {
|
|
|
|
$query->withBlueprintPHIDs(array($blueprint->getPHID()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
2013-12-26 12:30:10 -08:00
|
|
|
}
|
|
|
|
|
2015-09-24 09:56:49 -07:00
|
|
|
protected function buildQueryFromParameters(array $map) {
|
|
|
|
$query = $this->newQuery();
|
2013-12-26 12:30:10 -08:00
|
|
|
|
2015-09-24 09:56:49 -07:00
|
|
|
if ($map['statuses']) {
|
|
|
|
$query->withStatuses($map['statuses']);
|
2013-12-26 12:30:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
2015-09-24 09:56:49 -07:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
return array(
|
|
|
|
id(new PhabricatorSearchCheckboxesField())
|
|
|
|
->setLabel(pht('Statuses'))
|
|
|
|
->setKey('statuses')
|
|
|
|
->setOptions(DrydockResourceStatus::getStatusMap()),
|
|
|
|
);
|
2013-12-26 12:30:10 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
2015-09-24 13:52:43 -07:00
|
|
|
$blueprint = $this->getBlueprint();
|
|
|
|
if ($blueprint) {
|
|
|
|
$id = $blueprint->getID();
|
|
|
|
return "/drydock/blueprint/{$id}/resources/".$path;
|
|
|
|
} else {
|
|
|
|
return '/drydock/resource/'.$path;
|
|
|
|
}
|
2013-12-26 12:30:10 -08:00
|
|
|
}
|
|
|
|
|
2015-01-07 07:34:51 +11:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-07-23 10:03:09 +10:00
|
|
|
return array(
|
2013-12-26 12:30:10 -08:00
|
|
|
'active' => pht('Active Resources'),
|
|
|
|
'all' => pht('All Resources'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'active':
|
|
|
|
return $query->setParameter(
|
|
|
|
'statuses',
|
|
|
|
array(
|
|
|
|
DrydockResourceStatus::STATUS_PENDING,
|
2015-09-24 07:57:05 -07:00
|
|
|
DrydockResourceStatus::STATUS_ACTIVE,
|
2013-12-26 12:30:10 -08:00
|
|
|
));
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:14:33 -07:00
|
|
|
protected function renderResultList(
|
|
|
|
array $resources,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
|
2015-06-19 11:46:20 +01:00
|
|
|
$list = id(new DrydockResourceListView())
|
2014-05-13 12:14:33 -07:00
|
|
|
->setUser($this->requireViewer())
|
2015-06-19 11:46:20 +01:00
|
|
|
->setResources($resources);
|
|
|
|
|
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setTable($list);
|
|
|
|
|
|
|
|
return $result;
|
2014-05-13 12:14:33 -07:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:30:10 -08:00
|
|
|
}
|