Convert Files to SearchFields

Summary:
Ref T8441. Ref T7715.

  - Update FileSearchEngine.
  - Nothing too special/fancy.

Test Plan:
  - Searched for various files.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7715, T8441

Differential Revision: https://secure.phabricator.com/D13175
This commit is contained in:
epriestley
2015-06-07 07:32:09 -07:00
parent 2492fef029
commit cdef3e8bc8
4 changed files with 107 additions and 92 deletions

View File

@@ -11,76 +11,54 @@ final class PhabricatorFileSearchEngine
return 'PhabricatorFilesApplication';
}
public function buildSavedQueryFromRequest(AphrontRequest $request) {
$saved = new PhabricatorSavedQuery();
$saved->setParameter(
'authorPHIDs',
$this->readUsersFromRequest($request, 'authors'));
$saved->setParameter('explicit', $request->getBool('explicit'));
$saved->setParameter('createdStart', $request->getStr('createdStart'));
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
return $saved;
public function newResultObject() {
return new PhabricatorFile();
}
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
protected function buildCustomSearchFields() {
return array(
id(new PhabricatorSearchUsersField())
->setKey('authorPHIDs')
->setAliases(array('author', 'authors'))
->setLabel(pht('Authors')),
id(new PhabricatorSearchThreeStateField())
->setKey('explicit')
->setLabel(pht('Upload Source'))
->setOptions(
pht('(Show All)'),
pht('Show Only Manually Uploaded Files'),
pht('Hide Manually Uploaded Files')),
id(new PhabricatorSearchDateField())
->setKey('createdStart')
->setLabel(pht('Created After')),
id(new PhabricatorSearchDateField())
->setKey('createdEnd')
->setLabel(pht('Created Before')),
);
}
public function buildQueryFromParameters(array $map) {
$query = id(new PhabricatorFileQuery());
$author_phids = $saved->getParameter('authorPHIDs', array());
if ($author_phids) {
$query->withAuthorPHIDs($author_phids);
if ($map['authorPHIDs']) {
$query->withAuthorPHIDs($map['authorPHIDs']);
}
if ($saved->getParameter('explicit')) {
$query->showOnlyExplicitUploads(true);
if ($map['explicit'] !== null) {
$query->showOnlyExplicitUploads($map['explicit']);
}
$start = $this->parseDateTime($saved->getParameter('createdStart'));
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
if ($start) {
$query->withDateCreatedAfter($start);
if ($map['createdStart']) {
$query->withDateCreatedAfter($map['createdStart']);
}
if ($end) {
$query->withDateCreatedBefore($end);
if ($map['createdEnd']) {
$query->withDateCreatedBefore($map['createdEnd']);
}
return $query;
}
public function buildSearchForm(
AphrontFormView $form,
PhabricatorSavedQuery $saved_query) {
$author_phids = $saved_query->getParameter('authorPHIDs', array());
$explicit = $saved_query->getParameter('explicit');
$form
->appendControl(
id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource())
->setName('authors')
->setLabel(pht('Authors'))
->setValue($author_phids))
->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;
}