2013-12-26 12:30:29 -08:00
|
|
|
<?php
|
|
|
|
|
2014-07-23 10:03:09 +10:00
|
|
|
final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine {
|
2013-12-26 12:30:29 -08:00
|
|
|
|
2014-06-12 13:22:20 -07:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Drydock Logs');
|
|
|
|
}
|
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2013-12-26 12:30:29 -08:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
2015-08-24 21:13:20 +10:00
|
|
|
$query = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$query->setParameter(
|
|
|
|
'resourcePHIDs',
|
|
|
|
$this->readListFromRequest($request, 'resources'));
|
|
|
|
$query->setParameter(
|
|
|
|
'leasePHIDs',
|
|
|
|
$this->readListFromRequest($request, 'leases'));
|
|
|
|
|
|
|
|
return $query;
|
2013-12-26 12:30:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
2015-08-24 21:13:20 +10:00
|
|
|
|
|
|
|
// TODO: Change logs to use PHIDs instead of IDs.
|
|
|
|
$resource_ids = id(new DrydockResourceQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPHIDs($saved->getParameter('resourcePHIDs', array()))
|
|
|
|
->execute();
|
|
|
|
$resource_ids = mpull($resource_ids, 'getID');
|
|
|
|
$lease_ids = id(new DrydockLeaseQuery())
|
|
|
|
->setViewer(PhabricatorUser::getOmnipotentUser())
|
|
|
|
->withPHIDs($saved->getParameter('leasePHIDs', array()))
|
|
|
|
->execute();
|
|
|
|
$lease_ids = mpull($lease_ids, 'getID');
|
|
|
|
|
|
|
|
return id(new DrydockLogQuery())
|
|
|
|
->withResourceIDs($resource_ids)
|
|
|
|
->withLeaseIDs($lease_ids);
|
2013-12-26 12:30:29 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
2015-08-24 21:13:20 +10:00
|
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
|
|
|
|
$form
|
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource(new DrydockResourceDatasource())
|
|
|
|
->setName('resources')
|
|
|
|
->setLabel(pht('Resources'))
|
|
|
|
->setValue($saved->getParameter('resourcePHIDs', array())))
|
|
|
|
->appendControl(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource(new DrydockLeaseDatasource())
|
|
|
|
->setName('leases')
|
|
|
|
->setLabel(pht('Leases'))
|
|
|
|
->setValue($saved->getParameter('leasePHIDs', array())));
|
|
|
|
}
|
2013-12-26 12:30:29 -08:00
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/drydock/log/'.$path;
|
|
|
|
}
|
|
|
|
|
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:29 -08:00
|
|
|
'all' => pht('All Logs'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-13 12:14:33 -07:00
|
|
|
protected function renderResultList(
|
|
|
|
array $logs,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
|
2015-06-19 11:46:20 +01:00
|
|
|
$list = id(new DrydockLogListView())
|
2014-05-13 12:14:33 -07:00
|
|
|
->setUser($this->requireViewer())
|
2015-06-19 11:46:20 +01:00
|
|
|
->setLogs($logs);
|
|
|
|
|
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setTable($list);
|
|
|
|
|
|
|
|
return $result;
|
2014-05-13 12:14:33 -07:00
|
|
|
}
|
|
|
|
|
2013-12-26 12:30:29 -08:00
|
|
|
}
|