2013-07-22 17:34:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorProjectSearchEngine
|
|
|
|
extends PhabricatorApplicationSearchEngine {
|
|
|
|
|
2014-06-12 22:22:20 +02:00
|
|
|
public function getResultTypeDescription() {
|
|
|
|
return pht('Projects');
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorProjectApplication';
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
public function getCustomFieldObject() {
|
|
|
|
return new PhabricatorProject();
|
|
|
|
}
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
public function buildSavedQueryFromRequest(AphrontRequest $request) {
|
|
|
|
$saved = new PhabricatorSavedQuery();
|
|
|
|
|
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
|
|
|
$saved->setParameter(
|
|
|
|
'memberPHIDs',
|
|
|
|
$this->readUsersFromRequest($request, 'members'));
|
2014-07-18 01:35:54 +02:00
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
$saved->setParameter('status', $request->getStr('status'));
|
2014-07-18 01:35:54 +02:00
|
|
|
$saved->setParameter('name', $request->getStr('name'));
|
2013-07-22 17:34:35 +02:00
|
|
|
|
2014-08-12 17:04:38 +02:00
|
|
|
$saved->setParameter(
|
|
|
|
'icons',
|
|
|
|
$this->readListFromRequest($request, 'icons'));
|
|
|
|
|
|
|
|
$saved->setParameter(
|
|
|
|
'colors',
|
|
|
|
$this->readListFromRequest($request, 'colors'));
|
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
$this->readCustomFieldsFromRequest($request, $saved);
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
return $saved;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
|
2014-03-20 03:27:37 +01:00
|
|
|
$query = id(new PhabricatorProjectQuery())
|
|
|
|
->needImages(true);
|
2013-07-22 17:34:35 +02:00
|
|
|
|
|
|
|
$member_phids = $saved->getParameter('memberPHIDs', array());
|
|
|
|
if ($member_phids && is_array($member_phids)) {
|
|
|
|
$query->withMemberPHIDs($member_phids);
|
|
|
|
}
|
|
|
|
|
|
|
|
$status = $saved->getParameter('status');
|
|
|
|
$status = idx($this->getStatusValues(), $status);
|
|
|
|
if ($status) {
|
|
|
|
$query->withStatus($status);
|
|
|
|
}
|
|
|
|
|
2014-07-18 01:35:54 +02:00
|
|
|
$name = $saved->getParameter('name');
|
|
|
|
if (strlen($name)) {
|
|
|
|
$query->withDatasourceQuery($name);
|
|
|
|
}
|
|
|
|
|
2014-08-12 17:04:38 +02:00
|
|
|
$icons = $saved->getParameter('icons');
|
|
|
|
if ($icons) {
|
|
|
|
$query->withIcons($icons);
|
|
|
|
}
|
|
|
|
|
|
|
|
$colors = $saved->getParameter('colors');
|
|
|
|
if ($colors) {
|
|
|
|
$query->withColors($colors);
|
|
|
|
}
|
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
$this->applyCustomFieldsToQuery($query, $saved);
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
return $query;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSearchForm(
|
|
|
|
AphrontFormView $form,
|
2014-02-10 23:31:34 +01:00
|
|
|
PhabricatorSavedQuery $saved) {
|
2013-07-22 17:34:35 +02:00
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
$phids = $saved->getParameter('memberPHIDs', array());
|
2013-10-07 21:51:24 +02:00
|
|
|
$member_handles = id(new PhabricatorHandleQuery())
|
2013-07-22 17:34:35 +02:00
|
|
|
->setViewer($this->requireViewer())
|
2013-09-11 21:27:28 +02:00
|
|
|
->withPHIDs($phids)
|
|
|
|
->execute();
|
2013-07-22 17:34:35 +02:00
|
|
|
|
2014-02-10 23:31:34 +01:00
|
|
|
$status = $saved->getParameter('status');
|
2014-08-12 17:04:38 +02:00
|
|
|
$name_match = $saved->getParameter('name');
|
|
|
|
|
|
|
|
$icons = array_fuse($saved->getParameter('icons', array()));
|
|
|
|
$colors = array_fuse($saved->getParameter('colors', array()));
|
|
|
|
|
|
|
|
$icon_control = id(new AphrontFormCheckboxControl())
|
|
|
|
->setLabel(pht('Icons'));
|
|
|
|
foreach (PhabricatorProjectIcon::getIconMap() as $icon => $name) {
|
|
|
|
$image = id(new PHUIIconView())
|
|
|
|
->setIconFont($icon);
|
|
|
|
|
|
|
|
$icon_control->addCheckbox(
|
|
|
|
'icons[]',
|
|
|
|
$icon,
|
|
|
|
array($image, ' ', $name),
|
|
|
|
isset($icons[$icon]));
|
|
|
|
}
|
|
|
|
|
|
|
|
$color_control = id(new AphrontFormCheckboxControl())
|
|
|
|
->setLabel(pht('Colors'));
|
|
|
|
foreach (PhabricatorProjectIcon::getColorMap() as $color => $name) {
|
|
|
|
$tag = id(new PHUITagView())
|
|
|
|
->setType(PHUITagView::TYPE_SHADE)
|
|
|
|
->setShade($color)
|
|
|
|
->setName($name);
|
|
|
|
|
|
|
|
$color_control->addCheckbox(
|
|
|
|
'colors[]',
|
|
|
|
$color,
|
|
|
|
$tag,
|
|
|
|
isset($colors[$color]));
|
|
|
|
}
|
2013-07-22 17:34:35 +02:00
|
|
|
|
|
|
|
$form
|
2014-07-18 01:35:54 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTextControl())
|
|
|
|
->setName('name')
|
|
|
|
->setLabel(pht('Name'))
|
2014-08-12 17:04:38 +02:00
|
|
|
->setValue($name_match))
|
2013-07-22 17:34:35 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormTokenizerControl())
|
2014-07-18 00:44:18 +02:00
|
|
|
->setDatasource(new PhabricatorPeopleDatasource())
|
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
|
|
|
->setName('members')
|
2013-07-22 17:34:35 +02:00
|
|
|
->setLabel(pht('Members'))
|
2013-10-07 21:51:24 +02:00
|
|
|
->setValue($member_handles))
|
2013-07-22 17:34:35 +02:00
|
|
|
->appendChild(
|
|
|
|
id(new AphrontFormSelectControl())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setName('status')
|
|
|
|
->setOptions($this->getStatusOptions())
|
2014-08-12 17:04:38 +02:00
|
|
|
->setValue($status))
|
|
|
|
->appendChild($icon_control)
|
|
|
|
->appendChild($color_control);
|
2014-02-10 23:31:34 +01:00
|
|
|
|
|
|
|
$this->appendCustomFieldsToForm($form, $saved);
|
2013-07-22 17:34:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/project/'.$path;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getBuiltinQueryNames() {
|
|
|
|
$names = array();
|
|
|
|
|
|
|
|
if ($this->requireViewer()->isLoggedIn()) {
|
|
|
|
$names['joined'] = pht('Joined');
|
|
|
|
}
|
|
|
|
|
|
|
|
$names['active'] = pht('Active');
|
|
|
|
$names['all'] = pht('All');
|
|
|
|
|
|
|
|
return $names;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function buildSavedQueryFromBuiltin($query_key) {
|
|
|
|
$query = $this->newSavedQuery();
|
|
|
|
$query->setQueryKey($query_key);
|
|
|
|
|
|
|
|
$viewer_phid = $this->requireViewer()->getPHID();
|
|
|
|
|
|
|
|
switch ($query_key) {
|
|
|
|
case 'all':
|
|
|
|
return $query;
|
|
|
|
case 'active':
|
|
|
|
return $query
|
|
|
|
->setParameter('status', 'active');
|
|
|
|
case 'joined':
|
|
|
|
return $query
|
|
|
|
->setParameter('memberPHIDs', array($viewer_phid))
|
|
|
|
->setParameter('status', 'active');
|
|
|
|
}
|
|
|
|
|
|
|
|
return parent::buildSavedQueryFromBuiltin($query_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusOptions() {
|
|
|
|
return array(
|
|
|
|
'active' => pht('Show Only Active Projects'),
|
|
|
|
'all' => pht('Show All Projects'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusValues() {
|
|
|
|
return array(
|
|
|
|
'active' => PhabricatorProjectQuery::STATUS_ACTIVE,
|
|
|
|
'all' => PhabricatorProjectQuery::STATUS_ANY,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2014-09-09 22:49:56 +02:00
|
|
|
private function getColorValues() {}
|
2014-08-12 17:04:38 +02:00
|
|
|
|
2014-09-09 22:49:56 +02:00
|
|
|
private function getIconValues() {}
|
2014-08-12 17:04:38 +02:00
|
|
|
|
|
|
|
protected function getRequiredHandlePHIDsForResultList(
|
|
|
|
array $projects,
|
|
|
|
PhabricatorSavedQuery $query) {
|
|
|
|
return mpull($projects, 'getPHID');
|
|
|
|
}
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
protected function renderResultList(
|
|
|
|
array $projects,
|
|
|
|
PhabricatorSavedQuery $query,
|
|
|
|
array $handles) {
|
|
|
|
assert_instances_of($projects, 'PhabricatorProject');
|
|
|
|
$viewer = $this->requireViewer();
|
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
$list->setUser($viewer);
|
|
|
|
foreach ($projects as $project) {
|
|
|
|
$id = $project->getID();
|
2014-06-13 00:25:04 +02:00
|
|
|
$workboards_uri = $this->getApplicationURI("board/{$id}/");
|
|
|
|
$members_uri = $this->getApplicationURI("members/{$id}/");
|
|
|
|
$workboards_url = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'href' => $workboards_uri,
|
2014-06-13 00:25:04 +02:00
|
|
|
),
|
|
|
|
pht('Workboards'));
|
|
|
|
|
|
|
|
$members_url = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2014-10-07 15:01:04 +02:00
|
|
|
'href' => $members_uri,
|
2014-06-13 00:25:04 +02:00
|
|
|
),
|
|
|
|
pht('Members'));
|
2014-05-09 21:25:52 +02:00
|
|
|
|
2014-08-12 17:04:38 +02:00
|
|
|
$tag_list = id(new PHUIHandleTagListView())
|
|
|
|
->setSlim(true)
|
|
|
|
->setHandles(array($handles[$project->getPHID()]));
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
$item = id(new PHUIObjectItemView())
|
|
|
|
->setHeader($project->getName())
|
|
|
|
->setHref($this->getApplicationURI("view/{$id}/"))
|
2014-06-13 00:25:04 +02:00
|
|
|
->setImageURI($project->getProfileImageURI())
|
2014-08-12 17:04:38 +02:00
|
|
|
->addAttribute($tag_list)
|
2014-06-13 00:25:04 +02:00
|
|
|
->addAttribute($workboards_url)
|
|
|
|
->addAttribute($members_url);
|
2014-05-09 21:25:52 +02:00
|
|
|
|
|
|
|
if ($project->getStatus() == PhabricatorProjectStatus::STATUS_ARCHIVED) {
|
|
|
|
$item->addIcon('delete-grey', pht('Archived'));
|
|
|
|
$item->setDisabled(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
$list->addItem($item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $list;
|
|
|
|
}
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
}
|