2013-07-22 21:21:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PholioMockSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
public function getApplicationClassName() {
|
|
|
|
return 'PhabricatorApplicationPholio';
|
|
|
|
}
|
|
|
|
|
2013-07-22 21:21:15 +02:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
$saved->setParameter(
|
|
|
|
'authorPHIDs',
|
Allow construction of ApplicationSearch queries with GET
Summary:
Ref T3775 (discussion here). Ref T2625.
T3775 presents two problems:
# Existing tools which linked to `/differential/active/epriestley/` (that is, put a username in the URL) can't generate search links now.
# Humans can't edit the URL anymore, either.
I think (1) is an actual issue, and this fixes it. I think (2) is pretty fluff, and this doesn't really try to fix it, although it probably improves it.
The fix for (1) is:
- Provide a helper to read a parameter containing either a list of user PHIDs or a list of usernames, so `/?users[]=PHID-USER-xyz` (from a tokenizer) and `/?users=alincoln,htaft` (from an external program) are equivalent inputs.
- Rename all the form parameters to be more digestable (`authorPHIDs` -> `authors`). Almost all of them were in this form already anyway. This just gives us `?users=alincoln` instead of `userPHIDs=alincoln`.
- Inside ApplicationSearch, if a request has no query associated with it but does have query parameters, build a query from the request instead of issuing the user's default query. Basically, this means that `/differential/` runs the default query, while `/differential/?users=x` runs a custom query.
Test Plan: {F56612}
Reviewers: btrahan
Reviewed By: btrahan
CC: aran
Maniphest Tasks: T2625, T3775
Differential Revision: https://secure.phabricator.com/D6840
2013-08-29 20:52:29 +02:00
|
|
|
$this->readUsersFromRequest($request, 'authors'));
|
2014-05-19 20:33:34 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'statuses',
|
|
|
|
$request->getStrList('status'));
|
2013-07-22 21:21:15 +02:00
|
|
|
|
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
|
|
|
$query = id(new PholioMockQuery())
|
|
|
|
->needCoverFiles(true)
|
|
|
|
->needImages(true)
|
|
|
|
->needTokenCounts(true)
|
2014-05-19 20:33:34 +02:00
|
|
|
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
|
|
|
|
->withStatuses($saved->getParameter('statuses', array()));
|
2013-07-22 21:21:15 +02:00
|
|
|
|
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
|
|
|
PhabricatorSavedQuery $saved_query) {
|
|
|
|
|
|
|
|
$phids = $saved_query->getParameter('authorPHIDs', array());
|
2013-10-07 21:51:24 +02:00
|
|
|
$author_handles = id(new PhabricatorHandleQuery())
|
2013-07-22 21:21:15 +02:00
|
|
|
->setViewer($this->requireViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
2013-07-22 21:21:15 +02:00
|
|
|
|
2014-05-19 20:33:34 +02:00
|
|
|
$statuses = array(
|
2014-06-10 01:03:58 +02:00
|
|
|
'' => pht('Any Status'),
|
|
|
|
'closed' => pht('Closed'),
|
|
|
|
'open' => pht('Open'));
|
2014-05-19 20:33:34 +02:00
|
|
|
|
|
|
|
$status = $saved_query->getParameter('statuses', array());
|
|
|
|
$status = head($status);
|
|
|
|
|
2013-07-22 21:21:15 +02:00
|
|
|
$form
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
|
|
|
->setDatasource('/typeahead/common/users/')
|
|
|
|
->setName('authors')
|
|
|
|
->setLabel(pht('Authors'))
|
2014-05-19 20:33:34 +02:00
|
|
|
->setValue($author_handles))
|
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setName('status')
|
|
|
|
->setOptions($statuses)
|
|
|
|
->setValue($status));
|
2013-07-22 21:21:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/pholio/'.$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
$names = array(
|
2014-05-19 20:33:34 +02:00
|
|
|
'open' => pht('Open Mocks'),
|
2013-07-22 21:21:15 +02:00
|
|
|
'all' => pht('All Mocks'),
|
|
|
|
);
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['authored'] = pht('Authored');
|
|
|
|
}
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
switch ($query_key) {
|
2014-05-19 20:33:34 +02:00
|
|
|
case 'open':
|
|
|
|
return $query->setParameter(
|
|
|
|
'statuses',
|
|
|
|
array('open'));
|
2013-07-22 21:21:15 +02:00
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
case 'authored':
|
|
|
|
return $query->setParameter(
|
|
|
|
'authorPHIDs',
|
|
|
|
array($this->requireViewer()->getPHID()));
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $mocks,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return mpull($mocks, 'getAuthorPHID');
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderResultList(
|
|
|
|
array $mocks,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($mocks, 'PholioMock');
|
|
|
|
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$board = new PHUIPinboardView();
|
|
|
|
foreach ($mocks as $mock) {
|
2014-05-19 20:33:34 +02:00
|
|
|
|
|
|
|
$header = 'M'.$mock->getID().' '.$mock->getName();
|
|
|
|
if ($mock->isClosed()) {
|
|
|
|
$header = pht('%s (Closed)', $header);
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
$item = id(new PHUIPinboardItemView())
|
2014-05-19 20:33:34 +02:00
|
|
|
->setHeader($header)
|
2014-05-09 21:25:52 +02:00
|
|
|
->setURI('/M'.$mock->getID())
|
|
|
|
->setImageURI($mock->getCoverFile()->getThumb280x210URI())
|
|
|
|
->setImageSize(280, 210)
|
2014-05-12 19:08:32 +02:00
|
|
|
->addIconCount('fa-picture-o', count($mock->getImages()))
|
|
|
|
->addIconCount('fa-trophy', $mock->getTokenCount());
|
2014-05-09 21:25:52 +02:00
|
|
|
|
|
|
|
if ($mock->getAuthorPHID()) {
|
|
|
|
$author_handle = $handles[$mock->getAuthorPHID()];
|
|
|
|
$datetime = phabricator_date($mock->getDateCreated(), $viewer);
|
|
|
|
$item->appendChild(
|
|
|
|
pht('By %s on %s', $author_handle->renderLink(), $datetime));
|
|
|
|
}
|
|
|
|
|
|
|
|
$board->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $board;
|
|
|
|
}
|
|
|
|
|
2013-07-22 21:21:15 +02:00
|
|
|
}
|