mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-29 10:12:41 +01:00
d403700e1f
Summary: Ref T7689. Ref T4100. This advances the goals of removing `loadViewerHandles()` (only 67 callsites remain!) and letting tokenizers some day take token functions like `viewer()` and `members(differential)`. Test Plan: - Sent a new message; used "To". - I simplified the cancel URI construction slightly because it's moot in all normal cases. - Edited a thread; used "Add Participants". - Searched rooms; used "Participants". - Searched countdowns; used "Authors". - Created a diff; used "Repository". - Edited a revision; edited "Projects"; edited "Reveiwers"; edited "Subscribers". - Searched for revisions; edited "responsible users"; "authors"; "reviwers"; "subscribers"; "repositories". - Added revision comments; edited "Add Reveiwers"; "Add Subscribers". - Commented on a commit; edited "Add Auditors"; "Add subscribers". - Edited a commit; edited "Projects". - Edited a repository; edited "Projects". - Searched feed, used "include Users"; "include Proejcts". - Searched files, used "authors". - Edited initiative; edited "Projects". - Searched backers; used "Backers". - Searched initiatives; used "Owners". - Edited build plans; edited "Run Command". - Searched Herald; used "Authors". - Added signature exemption in Legalpad. - Searhced legalpad; used "creators"; used "contributors". - Searched signatures; used "documents"; used "signers". - Created meme. - Searched macros; used "Authors". - Used "Projects" in Maniphest reports. - Used Maniphest comment actions. - Edited Maniphest tasks; edited "Assigned To"; edited "CC"; edited "projects". - Used "parent" in Maniphest task creation workflow. - Searched for projects; used "assigned to"; "in any projec"; "in all projects"; "not in projects"; "in users' projects"; "authors"; "subscribers". - Edited Maniphest bug filing domains, used "Default Author". - Searched for OAuth applications, used "Creators". - Edited Owners pacakge; edited "Primary Owner"; edited "Owners". - Searched for Owners packages; used "Owner". - OMG this UI is OLD - Edited a paste; edited "Projects". - Searched for paste; used "Authors". - Searched user activity log; used "Actors"; used "Users". - Edited a mock; edited "Projects"; edited "CC". - Searched for mocks; used "Authors". - Edited Phortune account; edited "Members". - Edited Phortune merchant account; edited "Members". - Searched Phrequent; used "Users". - Edited Ponder question; sued "projects". - Searched Ponder; used "Authors"; used "Answered By". - Added project members. - Searched for projects; used "Members". - Edited a Releeph product; edited "Pushers". - Searched pull requests; searched "Requestors". - Edited an arcanist project; used "Uses Symbols From". - Searhced push logs; used "Repositories"; used "Pushers". - Searched repositories; used "In nay project". - Used global search; used Authors/owners/Subscribers/In Any Project. - Edited a slowvote; used "Projects". - Searched slovotes; used "Authors". - Created a custom "Users" field; edited and searched for it. - Made a whole lot of typos in this list. ^^^^^^ Did not test: - Lint is nontrivial to test locally, I'll test it in production. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T4100, T7689 Differential Revision: https://secure.phabricator.com/D12224
311 lines
9.2 KiB
PHP
311 lines
9.2 KiB
PHP
<?php
|
|
|
|
final class DifferentialRevisionSearchEngine
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
public function getResultTypeDescription() {
|
|
return pht('Differential Revisions');
|
|
}
|
|
|
|
public function getApplicationClassName() {
|
|
return 'PhabricatorDifferentialApplication';
|
|
}
|
|
|
|
public function getPageSize(PhabricatorSavedQuery $saved) {
|
|
if ($saved->getQueryKey() == 'active') {
|
|
return 0xFFFF;
|
|
}
|
|
return parent::getPageSize($saved);
|
|
}
|
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
$saved->setParameter(
|
|
'responsiblePHIDs',
|
|
$this->readUsersFromRequest($request, 'responsibles'));
|
|
|
|
$saved->setParameter(
|
|
'authorPHIDs',
|
|
$this->readUsersFromRequest($request, 'authors'));
|
|
|
|
$saved->setParameter(
|
|
'reviewerPHIDs',
|
|
$this->readUsersFromRequest(
|
|
$request,
|
|
'reviewers',
|
|
array(
|
|
PhabricatorProjectProjectPHIDType::TYPECONST,
|
|
)));
|
|
|
|
$saved->setParameter(
|
|
'subscriberPHIDs',
|
|
$this->readUsersFromRequest($request, 'subscribers'));
|
|
|
|
$saved->setParameter(
|
|
'repositoryPHIDs',
|
|
$request->getArr('repositories'));
|
|
|
|
$saved->setParameter(
|
|
'draft',
|
|
$request->getBool('draft'));
|
|
|
|
$saved->setParameter(
|
|
'order',
|
|
$request->getStr('order'));
|
|
|
|
$saved->setParameter(
|
|
'status',
|
|
$request->getStr('status'));
|
|
|
|
return $saved;
|
|
}
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
$query = id(new DifferentialRevisionQuery())
|
|
->needFlags(true)
|
|
->needDrafts(true)
|
|
->needRelationships(true);
|
|
|
|
$responsible_phids = $saved->getParameter('responsiblePHIDs', array());
|
|
if ($responsible_phids) {
|
|
$query->withResponsibleUsers($responsible_phids);
|
|
}
|
|
|
|
$author_phids = $saved->getParameter('authorPHIDs', array());
|
|
if ($author_phids) {
|
|
$query->withAuthors($author_phids);
|
|
}
|
|
|
|
$reviewer_phids = $saved->getParameter('reviewerPHIDs', array());
|
|
if ($reviewer_phids) {
|
|
$query->withReviewers($reviewer_phids);
|
|
}
|
|
|
|
$subscriber_phids = $saved->getParameter('subscriberPHIDs', array());
|
|
if ($subscriber_phids) {
|
|
$query->withCCs($subscriber_phids);
|
|
}
|
|
|
|
$repository_phids = $saved->getParameter('repositoryPHIDs', array());
|
|
if ($repository_phids) {
|
|
$query->withRepositoryPHIDs($repository_phids);
|
|
}
|
|
|
|
$draft = $saved->getParameter('draft', false);
|
|
if ($draft && $this->requireViewer()->isLoggedIn()) {
|
|
$query->withDraftRepliesByAuthors(
|
|
array($this->requireViewer()->getPHID()));
|
|
}
|
|
|
|
$status = $saved->getParameter('status');
|
|
if (idx($this->getStatusOptions(), $status)) {
|
|
$query->withStatus($status);
|
|
}
|
|
|
|
$order = $saved->getParameter('order');
|
|
if (idx($this->getOrderOptions(), $order)) {
|
|
$query->setOrder($order);
|
|
} else {
|
|
$query->setOrder(DifferentialRevisionQuery::ORDER_CREATED);
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function buildSearchForm(
|
|
AphrontFormView $form,
|
|
PhabricatorSavedQuery $saved) {
|
|
|
|
$responsible_phids = $saved->getParameter('responsiblePHIDs', array());
|
|
$author_phids = $saved->getParameter('authorPHIDs', array());
|
|
$reviewer_phids = $saved->getParameter('reviewerPHIDs', array());
|
|
$subscriber_phids = $saved->getParameter('subscriberPHIDs', array());
|
|
$repository_phids = $saved->getParameter('repositoryPHIDs', array());
|
|
$only_draft = $saved->getParameter('draft', false);
|
|
|
|
$form
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Responsible Users'))
|
|
->setName('responsibles')
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
->setValue($responsible_phids))
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Authors'))
|
|
->setName('authors')
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
|
->setValue($author_phids))
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Reviewers'))
|
|
->setName('reviewers')
|
|
->setDatasource(new PhabricatorProjectOrUserDatasource())
|
|
->setValue($reviewer_phids))
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Subscribers'))
|
|
->setName('subscribers')
|
|
->setDatasource(new PhabricatorMetaMTAMailableDatasource())
|
|
->setValue($subscriber_phids))
|
|
->appendControl(
|
|
id(new AphrontFormTokenizerControl())
|
|
->setLabel(pht('Repositories'))
|
|
->setName('repositories')
|
|
->setDatasource(new DiffusionRepositoryDatasource())
|
|
->setValue($repository_phids))
|
|
->appendChild(
|
|
id(new AphrontFormSelectControl())
|
|
->setLabel(pht('Status'))
|
|
->setName('status')
|
|
->setOptions($this->getStatusOptions())
|
|
->setValue($saved->getParameter('status')));
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormCheckboxControl())
|
|
->addCheckbox(
|
|
'draft',
|
|
1,
|
|
pht('Show only revisions with a draft comment.'),
|
|
$only_draft));
|
|
}
|
|
|
|
$form
|
|
->appendChild(
|
|
id(new AphrontFormSelectControl())
|
|
->setLabel(pht('Order'))
|
|
->setName('order')
|
|
->setOptions($this->getOrderOptions())
|
|
->setValue($saved->getParameter('order')));
|
|
}
|
|
|
|
protected function getURI($path) {
|
|
return '/differential/'.$path;
|
|
}
|
|
|
|
protected function getBuiltinQueryNames() {
|
|
$names = array();
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
$names['active'] = pht('Active Revisions');
|
|
$names['authored'] = pht('Authored');
|
|
}
|
|
|
|
$names['all'] = pht('All Revisions');
|
|
|
|
return $names;
|
|
}
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
$query = $this->newSavedQuery();
|
|
$query->setQueryKey($query_key);
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
switch ($query_key) {
|
|
case 'active':
|
|
return $query
|
|
->setParameter('responsiblePHIDs', array($viewer->getPHID()))
|
|
->setParameter('status', DifferentialRevisionQuery::STATUS_OPEN);
|
|
case 'authored':
|
|
return $query
|
|
->setParameter('authorPHIDs', array($viewer->getPHID()));
|
|
case 'all':
|
|
return $query;
|
|
}
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
}
|
|
|
|
private function getStatusOptions() {
|
|
return array(
|
|
DifferentialRevisionQuery::STATUS_ANY => pht('All'),
|
|
DifferentialRevisionQuery::STATUS_OPEN => pht('Open'),
|
|
DifferentialRevisionQuery::STATUS_ACCEPTED => pht('Accepted'),
|
|
DifferentialRevisionQuery::STATUS_NEEDS_REVIEW => pht('Needs Review'),
|
|
DifferentialRevisionQuery::STATUS_NEEDS_REVISION => pht('Needs Revision'),
|
|
DifferentialRevisionQuery::STATUS_CLOSED => pht('Closed'),
|
|
DifferentialRevisionQuery::STATUS_ABANDONED => pht('Abandoned'),
|
|
);
|
|
}
|
|
|
|
private function getOrderOptions() {
|
|
return array(
|
|
DifferentialRevisionQuery::ORDER_CREATED => pht('Created'),
|
|
DifferentialRevisionQuery::ORDER_MODIFIED => pht('Updated'),
|
|
);
|
|
}
|
|
|
|
protected function renderResultList(
|
|
array $revisions,
|
|
PhabricatorSavedQuery $query,
|
|
array $handles) {
|
|
assert_instances_of($revisions, 'DifferentialRevision');
|
|
|
|
$viewer = $this->requireViewer();
|
|
$template = id(new DifferentialRevisionListView())
|
|
->setUser($viewer)
|
|
->setNoBox($this->isPanelContext());
|
|
|
|
$views = array();
|
|
if ($query->getQueryKey() == 'active') {
|
|
$split = DifferentialRevisionQuery::splitResponsible(
|
|
$revisions,
|
|
$query->getParameter('responsiblePHIDs'));
|
|
list($blocking, $active, $waiting) = $split;
|
|
|
|
$views[] = id(clone $template)
|
|
->setHeader(pht('Blocking Others'))
|
|
->setNoDataString(
|
|
pht('No revisions are blocked on your action.'))
|
|
->setHighlightAge(true)
|
|
->setRevisions($blocking)
|
|
->setHandles(array());
|
|
|
|
$views[] = id(clone $template)
|
|
->setHeader(pht('Action Required'))
|
|
->setNoDataString(
|
|
pht('No revisions require your action.'))
|
|
->setHighlightAge(true)
|
|
->setRevisions($active)
|
|
->setHandles(array());
|
|
|
|
$views[] = id(clone $template)
|
|
->setHeader(pht('Waiting on Others'))
|
|
->setNoDataString(
|
|
pht('You have no revisions waiting on others.'))
|
|
->setRevisions($waiting)
|
|
->setHandles(array());
|
|
} else {
|
|
$views[] = id(clone $template)
|
|
->setRevisions($revisions)
|
|
->setHandles(array());
|
|
}
|
|
|
|
$phids = array_mergev(mpull($views, 'getRequiredHandlePHIDs'));
|
|
if ($phids) {
|
|
$handles = id(new PhabricatorHandleQuery())
|
|
->setViewer($viewer)
|
|
->withPHIDs($phids)
|
|
->execute();
|
|
} else {
|
|
$handles = array();
|
|
}
|
|
|
|
foreach ($views as $view) {
|
|
$view->setHandles($handles);
|
|
}
|
|
|
|
if (count($views) == 1) {
|
|
// Reduce this to a PHUIObjectItemListView so we can get the free
|
|
// support from ApplicationSearch.
|
|
return head($views)->render();
|
|
} else {
|
|
return $views;
|
|
}
|
|
}
|
|
|
|
}
|