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');
|
|
|
|
}
|
|
|
|
|
2015-02-05 00:47:48 +01:00
|
|
|
public function getApplicationClassName() {
|
2014-07-23 02:03:09 +02:00
|
|
|
return 'PhabricatorProjectApplication';
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:21:48 +02:00
|
|
|
public function newQuery() {
|
|
|
|
return id(new PhabricatorProjectQuery())
|
|
|
|
->needImages(true);
|
2014-02-10 23:31:34 +01:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
protected function buildCustomSearchFields() {
|
|
|
|
return array(
|
|
|
|
id(new PhabricatorSearchTextField())
|
|
|
|
->setLabel(pht('Name'))
|
|
|
|
->setKey('name'),
|
|
|
|
id(new PhabricatorSearchUsersField())
|
|
|
|
->setLabel(pht('Members'))
|
|
|
|
->setKey('memberPHIDs')
|
|
|
|
->setAliases(array('member', 'members')),
|
|
|
|
id(new PhabricatorSearchSelectField())
|
|
|
|
->setLabel(pht('Status'))
|
|
|
|
->setKey('status')
|
|
|
|
->setOptions($this->getStatusOptions()),
|
|
|
|
id(new PhabricatorSearchCheckboxesField())
|
|
|
|
->setLabel(pht('Icons'))
|
|
|
|
->setKey('icons')
|
|
|
|
->setOptions($this->getIconOptions()),
|
|
|
|
id(new PhabricatorSearchCheckboxesField())
|
|
|
|
->setLabel(pht('Colors'))
|
|
|
|
->setKey('colors')
|
|
|
|
->setOptions($this->getColorOptions()),
|
|
|
|
);
|
2013-07-22 17:34:35 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
|
|
|
|
public function buildQueryFromParameters(array $map) {
|
2015-06-08 21:21:48 +02:00
|
|
|
$query = $this->newQuery();
|
2013-07-22 17:34:35 +02:00
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
if (strlen($map['name'])) {
|
|
|
|
$tokens = PhabricatorTypeaheadDatasource::tokenizeString($map['name']);
|
2015-04-15 20:49:07 +02:00
|
|
|
$query->withNameTokens($tokens);
|
2014-07-18 01:35:54 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
if ($map['memberPHIDs']) {
|
|
|
|
$query->withMemberPHIDs($map['memberPHIDs']);
|
2014-08-12 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
if ($map['status']) {
|
|
|
|
$status = idx($this->getStatusValues(), $map['status']);
|
|
|
|
if ($status) {
|
|
|
|
$query->withStatus($status);
|
|
|
|
}
|
2014-08-12 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
if ($map['icons']) {
|
|
|
|
$query->withIcons($map['icons']);
|
2014-08-12 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
if ($map['colors']) {
|
|
|
|
$query->withColors($map['colors']);
|
2014-08-12 17:04:38 +02:00
|
|
|
}
|
2013-07-22 17:34:35 +02:00
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
return $query;
|
2013-07-22 17:34:35 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getURI($path) {
|
|
|
|
return '/project/'.$path;
|
|
|
|
}
|
|
|
|
|
2015-01-06 21:34:51 +01:00
|
|
|
protected function getBuiltinQueryNames() {
|
2013-07-22 17:34:35 +02:00
|
|
|
$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(
|
2015-05-01 01:06:59 +02:00
|
|
|
'active' => pht('Show Only Active Projects'),
|
|
|
|
'archived' => pht('Show Only Archived Projects'),
|
|
|
|
'all' => pht('Show All Projects'),
|
2013-07-22 17:34:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getStatusValues() {
|
|
|
|
return array(
|
2015-05-01 01:06:59 +02:00
|
|
|
'active' => PhabricatorProjectQuery::STATUS_ACTIVE,
|
|
|
|
'archived' => PhabricatorProjectQuery::STATUS_ARCHIVED,
|
|
|
|
'all' => PhabricatorProjectQuery::STATUS_ANY,
|
2013-07-22 17:34:35 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
private function getIconOptions() {
|
|
|
|
$options = array();
|
2014-08-12 17:04:38 +02:00
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
foreach (PhabricatorProjectIcon::getIconMap() as $icon => $name) {
|
|
|
|
$options[$icon] = array(
|
|
|
|
id(new PHUIIconView())
|
|
|
|
->setIconFont($icon),
|
|
|
|
' ',
|
|
|
|
$name,
|
|
|
|
);
|
|
|
|
}
|
2014-08-12 17:04:38 +02:00
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getColorOptions() {
|
|
|
|
$options = array();
|
|
|
|
|
|
|
|
foreach (PhabricatorProjectIcon::getColorMap() as $color => $name) {
|
|
|
|
$options[$color] = array(
|
|
|
|
id(new PHUITagView())
|
|
|
|
->setType(PHUITagView::TYPE_SHADE)
|
|
|
|
->setShade($color)
|
|
|
|
->setName($name),
|
|
|
|
' ',
|
|
|
|
$name,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $options;
|
2014-08-12 17:04:38 +02:00
|
|
|
}
|
|
|
|
|
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();
|
2015-06-08 21:20:16 +02:00
|
|
|
$handles = $viewer->loadHandles(mpull($projects, 'getPHID'));
|
2014-05-09 21:25:52 +02:00
|
|
|
|
|
|
|
$list = new PHUIObjectItemListView();
|
|
|
|
$list->setUser($viewer);
|
2015-01-06 00:39:44 +01:00
|
|
|
$can_edit_projects = id(new PhabricatorPolicyFilter())
|
|
|
|
->setViewer($viewer)
|
|
|
|
->requireCapabilities(array(PhabricatorPolicyCapability::CAN_EDIT))
|
|
|
|
->apply($projects);
|
|
|
|
|
|
|
|
foreach ($projects as $key => $project) {
|
2014-05-09 21:25:52 +02:00
|
|
|
$id = $project->getID();
|
|
|
|
|
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())
|
2015-01-26 21:44:09 +01:00
|
|
|
->addAttribute($tag_list);
|
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
|
|
|
}
|