mirror of
https://we.phorge.it/source/phorge.git
synced 2025-02-20 02:38:39 +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';
|
return 'PhabricatorLegalpadApplication';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
public function newQuery() {
|
||||||
$saved = new PhabricatorSavedQuery();
|
return id(new LegalpadDocumentQuery())
|
||||||
$saved->setParameter(
|
->needViewerSignatures(true);
|
||||||
'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 buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
protected function buildCustomSearchFields() {
|
||||||
$query = id(new LegalpadDocumentQuery())
|
return array(
|
||||||
->needViewerSignatures(true);
|
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());
|
protected function buildQueryFromParameters(array $map) {
|
||||||
if ($creator_phids) {
|
$query = $this->newQuery();
|
||||||
$query->withCreatorPHIDs($creator_phids);
|
|
||||||
|
if ($map['signerPHIDs']) {
|
||||||
|
$query->withSignerPHIDs($map['signerPHIDs']);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contributor_phids = $saved->getParameter('contributorPHIDs', array());
|
if ($map['contributorPHIDs']) {
|
||||||
if ($contributor_phids) {
|
$query->withContributorPHIDs($map['creatorPHIDs']);
|
||||||
$query->withContributorPHIDs($contributor_phids);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($saved->getParameter('withViewerSignature')) {
|
if ($map['creatorPHIDs']) {
|
||||||
$viewer_phid = $this->requireViewer()->getPHID();
|
$query->withCreatorPHIDs($map['creatorPHIDs']);
|
||||||
if ($viewer_phid) {
|
|
||||||
$query->withSignerPHIDs(array($viewer_phid));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$start = $this->parseDateTime($saved->getParameter('createdStart'));
|
if ($map['createdStart']) {
|
||||||
$end = $this->parseDateTime($saved->getParameter('createdEnd'));
|
$query->withDateCreatedAfter($map['createdStart']);
|
||||||
|
|
||||||
if ($start) {
|
|
||||||
$query->withDateCreatedAfter($start);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($end) {
|
if ($map['createdEnd']) {
|
||||||
$query->withDateCreatedBefore($end);
|
$query->withDateCreatedAfter($map['createdStart']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $query;
|
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) {
|
protected function getURI($path) {
|
||||||
return '/legalpad/'.$path;
|
return '/legalpad/'.$path;
|
||||||
}
|
}
|
||||||
|
@ -130,10 +91,11 @@ final class LegalpadDocumentSearchEngine
|
||||||
$query = $this->newSavedQuery();
|
$query = $this->newSavedQuery();
|
||||||
$query->setQueryKey($query_key);
|
$query->setQueryKey($query_key);
|
||||||
|
|
||||||
|
$viewer = $this->requireViewer();
|
||||||
|
|
||||||
switch ($query_key) {
|
switch ($query_key) {
|
||||||
case 'signed':
|
case 'signed':
|
||||||
return $query
|
return $query->setParameter('signerPHIDs', array($viewer->getPHID()));
|
||||||
->setParameter('withViewerSignature', true);
|
|
||||||
case 'all':
|
case 'all':
|
||||||
return $query;
|
return $query;
|
||||||
}
|
}
|
||||||
|
@ -141,12 +103,6 @@ final class LegalpadDocumentSearchEngine
|
||||||
return parent::buildSavedQueryFromBuiltin($query_key);
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRequiredHandlePHIDsForResultList(
|
|
||||||
array $documents,
|
|
||||||
PhabricatorSavedQuery $query) {
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function renderResultList(
|
protected function renderResultList(
|
||||||
array $documents,
|
array $documents,
|
||||||
PhabricatorSavedQuery $query,
|
PhabricatorSavedQuery $query,
|
||||||
|
|
Loading…
Add table
Reference in a new issue