mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-24 21:48:21 +01:00
e117ace8c7
Summary: Ref T9252. Drydock currently uses integer statuses, but there's no reason for this (they don't need to be ordered) and it makes debugging them, working with them, future APIs, etc., more cumbersome. Switch to string instead. Also rename `STATUS_OPEN` to `STATUS_ACTIVE` and `STATUS_CLOSED` to `STATUS_RELEASED` for consistency. This makes resources and leases have more similar states, and gives resource states more accurate names. Test Plan: Browsed web UI, grepped for changed constants, applied patch, inspected database. Reviewers: chad Reviewed By: chad Maniphest Tasks: T9252 Differential Revision: https://secure.phabricator.com/D14153
100 lines
2.4 KiB
PHP
100 lines
2.4 KiB
PHP
<?php
|
|
|
|
final class DrydockResourceSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function getResultTypeDescription() {
|
|
return pht('Drydock Resources');
|
|
}
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorDrydockApplication';
|
|
}
|
|
|
|
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 DrydockResourceQuery());
|
|
|
|
$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 (DrydockResourceStatus::getAllStatuses() as $status) {
|
|
$status_control->addCheckbox(
|
|
'statuses[]',
|
|
$status,
|
|
DrydockResourceStatus::getNameForStatus($status),
|
|
in_array($status, $statuses));
|
|
}
|
|
|
|
$form
|
|
->appendChild($status_control);
|
|
}
|
|
|
|
protected function getURI($path) {
|
|
return '/drydock/resource/'.$path;
|
|
}
|
|
|
|
protected function getBuiltinQueryNames() {
|
|
return array(
|
|
'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,
|
|
DrydockResourceStatus::STATUS_ACTIVE,
|
|
));
|
|
case 'all':
|
|
return $query;
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
protected function renderResultList(
|
|
array $resources,
|
|
PhabricatorSavedQuery $query,
|
|
array $handles) {
|
|
|
|
$list = id(new DrydockResourceListView())
|
|
->setUser($this->requireViewer())
|
|
->setResources($resources);
|
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
$result->setTable($list);
|
|
|
|
return $result;
|
|
}
|
|
|
|
}
|