Implement ApplicationSearch in Files
Summary: Ref T2625. Ref T1163. A couple of small generalization nudges, but this is almost entirely straightforward. Test Plan: Executed various File queries. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T1163, T2625 Differential Revision: https://secure.phabricator.com/D6091
This commit is contained in:
113
src/applications/files/query/PhabricatorFileSearchEngine.php
Normal file
113
src/applications/files/query/PhabricatorFileSearchEngine.php
Normal file
@@ -0,0 +1,113 @@
|
||||
<?php
|
||||
|
||||
final class PhabricatorFileSearchEngine
|
||||
extends PhabricatorApplicationSearchEngine {
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
$saved->setParameter(
|
||||
'authorPHIDs',
|
||||
array_values($request->getArr('authors')));
|
||||
|
||||
$saved->setParameter('explicit', $request->getBool('explicit'));
|
||||
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
||||
|
||||
return $saved;
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new PhabricatorFileQuery())
|
||||
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()));
|
||||
|
||||
if ($saved->getParameter('explicit')) {
|
||||
$query->showOnlyExplicitUploads(true);
|
||||
}
|
||||
|
||||
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
||||
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
||||
|
||||
if ($start) {
|
||||
$query->withDateCreatedAfter($start);
|
||||
}
|
||||
|
||||
if ($end) {
|
||||
$query->withDateCreatedBefore($end);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
$phids = $saved_query->getParameter('authorPHIDs', array());
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->setViewer($this->requireViewer())
|
||||
->loadHandles();
|
||||
$author_tokens = mpull($handles, 'getFullName', 'getPHID');
|
||||
|
||||
$explicit = $saved_query->getParameter('explicit');
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource('/typeahead/common/users/')
|
||||
->setName('authors')
|
||||
->setLabel(pht('Authors'))
|
||||
->setValue($author_tokens))
|
||||
->appendChild(
|
||||
id(new AphrontFormCheckboxControl())
|
||||
->addCheckbox(
|
||||
'explicit',
|
||||
1,
|
||||
pht('Show only manually uploaded files.'),
|
||||
$explicit));
|
||||
|
||||
$this->buildDateRange(
|
||||
$form,
|
||||
$saved_query,
|
||||
'createdStart',
|
||||
pht('Created After'),
|
||||
'createdEnd',
|
||||
pht('Created Before'));
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/file/'.$path;
|
||||
}
|
||||
|
||||
public function getBuiltinQueryNames() {
|
||||
$names = array();
|
||||
|
||||
if ($this->requireViewer()->isLoggedIn()) {
|
||||
$names['authored'] = pht('Authored');
|
||||
}
|
||||
|
||||
$names += array(
|
||||
'all' => pht('All'),
|
||||
);
|
||||
|
||||
return $names;
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromBuiltin($query_key) {
|
||||
|
||||
$query = $this->newSavedQuery();
|
||||
$query->setQueryKey($query_key);
|
||||
|
||||
switch ($query_key) {
|
||||
case 'all':
|
||||
return $query;
|
||||
case 'authored':
|
||||
$author_phid = array($this->requireViewer()->getPHID());
|
||||
return $query
|
||||
->setParameter('authorPHIDs', $author_phid)
|
||||
->setParameter('explicit', true);
|
||||
}
|
||||
|
||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user