2013-12-26 21:30:29 +01:00
|
|
|
<?php
|
|
|
|
|
2014-07-23 02:03:09 +02:00
|
|
|
final class DrydockLogSearchEngine extends PhabricatorApplicationSearchEngine {
|
2013-12-26 21:30:29 +01:00
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Drydock Logs');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorDrydockApplication';
|
2014-05-13 21:14:33 +02:00
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:29 +01:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
2015-08-24 13:13:20 +02:00
|
|
|
$query = new PhabricatorSavedQuery();
|
|
|
|
|
|
|
|
$query->setParameter(
|
|
|
|
'resourcePHIDs',
|
|
|
|
$this->readListFromRequest($request, 'resources'));
|
|
|
|
$query->setParameter(
|
|
|
|
'leasePHIDs',
|
|
|
|
$this->readListFromRequest($request, 'leases'));
|
|
|
|
|
|
|
|
return $query;
|
2013-12-26 21:30:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
2015-08-24 13:13:20 +02: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 21:30:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
2015-08-24 13:13:20 +02: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 21:30:29 +01:00
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/drydock/log/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return array(
|
2013-12-26 21:30:29 +01: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 21:14:33 +02:00
|
|
|
protected function renderResultList(
|
|
|
|
array $logs,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$list = id(new DrydockLogListView())
|
2014-05-13 21:14:33 +02:00
|
|
|
->setUser($this->requireViewer())
|
2015-06-19 12:46:20 +02:00
|
|
|
->setLogs($logs);
|
|
|
|
|
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setTable($list);
|
|
|
|
|
|
|
|
return $result;
|
2014-05-13 21:14:33 +02:00
|
|
|
}
|
|
|
|
|
2013-12-26 21:30:29 +01:00
|
|
|
}
|