mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-17 01:08:41 +01:00
Lightly modernize LegalpadDocumentSearchEngine
Summary: Depends on D18785. Ref T13024. While I'm in here, update this a bit to use the newer stuff. Test Plan: Searched for Legalpad documents, saw more modern support (subscribers, order by, viewer()). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13024 Differential Revision: https://secure.phabricator.com/D18786
This commit is contained in:
parent
3d742eb50b
commit
71406ca93b
1 changed files with 47 additions and 91 deletions
|
@ -11,105 +11,66 @@ final class LegalpadDocumentSearchEngine
|
|||
return 'PhabricatorLegalpadApplication';
|
||||
}
|
||||
|
||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
||||
$saved = new PhabricatorSavedQuery();
|
||||
$saved->setParameter(
|
||||
'creatorPHIDs',
|
||||
$this->readUsersFromRequest($request, 'creators'));
|
||||
|
||||
$saved->setParameter(
|
||||
'contributorPHIDs',
|
||||
$this->readUsersFromRequest($request, 'contributors'));
|
||||
|
||||
$saved->setParameter(
|
||||
'withViewerSignature',
|
||||
$request->getBool('withViewerSignature'));
|
||||
|
||||
$saved->setParameter('createdStart', $request->getStr('createdStart'));
|
||||
$saved->setParameter('createdEnd', $request->getStr('createdEnd'));
|
||||
|
||||
return $saved;
|
||||
public function newQuery() {
|
||||
return id(new LegalpadDocumentQuery())
|
||||
->needViewerSignatures(true);
|
||||
}
|
||||
|
||||
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
||||
$query = id(new LegalpadDocumentQuery())
|
||||
->needViewerSignatures(true);
|
||||
protected function buildCustomSearchFields() {
|
||||
return array(
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setLabel(pht('Signed By'))
|
||||
->setKey('signerPHIDs')
|
||||
->setAliases(array('signer', 'signers', 'signerPHID'))
|
||||
->setDescription(
|
||||
pht('Search for documents signed by given users.')),
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setLabel(pht('Creators'))
|
||||
->setKey('creatorPHIDs')
|
||||
->setAliases(array('creator', 'creators', 'creatorPHID'))
|
||||
->setDescription(
|
||||
pht('Search for documents with given creators.')),
|
||||
id(new PhabricatorUsersSearchField())
|
||||
->setLabel(pht('Contributors'))
|
||||
->setKey('contributorPHIDs')
|
||||
->setAliases(array('contributor', 'contributors', 'contributorPHID'))
|
||||
->setDescription(
|
||||
pht('Search for documents with given contributors.')),
|
||||
id(new PhabricatorSearchDateField())
|
||||
->setLabel(pht('Created After'))
|
||||
->setKey('createdStart'),
|
||||
id(new PhabricatorSearchDateField())
|
||||
->setLabel(pht('Created Before'))
|
||||
->setKey('createdEnd'),
|
||||
);
|
||||
}
|
||||
|
||||
$creator_phids = $saved->getParameter('creatorPHIDs', array());
|
||||
if ($creator_phids) {
|
||||
$query->withCreatorPHIDs($creator_phids);
|
||||
protected function buildQueryFromParameters(array $map) {
|
||||
$query = $this->newQuery();
|
||||
|
||||
if ($map['signerPHIDs']) {
|
||||
$query->withSignerPHIDs($map['signerPHIDs']);
|
||||
}
|
||||
|
||||
$contributor_phids = $saved->getParameter('contributorPHIDs', array());
|
||||
if ($contributor_phids) {
|
||||
$query->withContributorPHIDs($contributor_phids);
|
||||
if ($map['contributorPHIDs']) {
|
||||
$query->withContributorPHIDs($map['creatorPHIDs']);
|
||||
}
|
||||
|
||||
if ($saved->getParameter('withViewerSignature')) {
|
||||
$viewer_phid = $this->requireViewer()->getPHID();
|
||||
if ($viewer_phid) {
|
||||
$query->withSignerPHIDs(array($viewer_phid));
|
||||
}
|
||||
if ($map['creatorPHIDs']) {
|
||||
$query->withCreatorPHIDs($map['creatorPHIDs']);
|
||||
}
|
||||
|
||||
$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->withDateCreatedAfter($map['createdStart']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
public function buildSearchForm(
|
||||
AphrontFormView $form,
|
||||
PhabricatorSavedQuery $saved_query) {
|
||||
|
||||
$creator_phids = $saved_query->getParameter('creatorPHIDs', array());
|
||||
$contributor_phids = $saved_query->getParameter(
|
||||
'contributorPHIDs', array());
|
||||
|
||||
$viewer_signature = $saved_query->getParameter('withViewerSignature');
|
||||
if (!$this->requireViewer()->getPHID()) {
|
||||
$viewer_signature = false;
|
||||
}
|
||||
|
||||
$form
|
||||
->appendChild(
|
||||
id(new AphrontFormCheckboxControl())
|
||||
->addCheckbox(
|
||||
'withViewerSignature',
|
||||
1,
|
||||
pht('Show only documents I have signed.'),
|
||||
$viewer_signature)
|
||||
->setDisabled(!$this->requireViewer()->getPHID()))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new PhabricatorPeopleDatasource())
|
||||
->setName('creators')
|
||||
->setLabel(pht('Creators'))
|
||||
->setValue($creator_phids))
|
||||
->appendControl(
|
||||
id(new AphrontFormTokenizerControl())
|
||||
->setDatasource(new PhabricatorPeopleDatasource())
|
||||
->setName('contributors')
|
||||
->setLabel(pht('Contributors'))
|
||||
->setValue($contributor_phids));
|
||||
|
||||
$this->buildDateRange(
|
||||
$form,
|
||||
$saved_query,
|
||||
'createdStart',
|
||||
pht('Created After'),
|
||||
'createdEnd',
|
||||
pht('Created Before'));
|
||||
}
|
||||
|
||||
protected function getURI($path) {
|
||||
return '/legalpad/'.$path;
|
||||
}
|
||||
|
@ -130,10 +91,11 @@ final class LegalpadDocumentSearchEngine
|
|||
$query = $this->newSavedQuery();
|
||||
$query->setQueryKey($query_key);
|
||||
|
||||
$viewer = $this->requireViewer();
|
||||
|
||||
switch ($query_key) {
|
||||
case 'signed':
|
||||
return $query
|
||||
->setParameter('withViewerSignature', true);
|
||||
return $query->setParameter('signerPHIDs', array($viewer->getPHID()));
|
||||
case 'all':
|
||||
return $query;
|
||||
}
|
||||
|
@ -141,12 +103,6 @@ final class LegalpadDocumentSearchEngine
|
|||
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||
}
|
||||
|
||||
protected function getRequiredHandlePHIDsForResultList(
|
||||
array $documents,
|
||||
PhabricatorSavedQuery $query) {
|
||||
return array();
|
||||
}
|
||||
|
||||
protected function renderResultList(
|
||||
array $documents,
|
||||
PhabricatorSavedQuery $query,
|
||||
|
|
Loading…
Add table
Reference in a new issue