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'),
|
2015-07-06 14:52:04 +02:00
|
|
|
id(new PhabricatorUsersSearchField())
|
2015-06-08 21:20:16 +02:00
|
|
|
->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
|
|
|
|
2015-06-08 23:09:58 +02:00
|
|
|
protected 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-12-16 16:53:13 +01:00
|
|
|
$set = new PhabricatorProjectIconSet();
|
|
|
|
foreach ($set->getIcons() as $icon) {
|
|
|
|
$options[$icon->getKey()] = array(
|
2015-06-08 21:20:16 +02:00
|
|
|
id(new PHUIIconView())
|
2015-12-16 16:53:13 +01:00
|
|
|
->setIconFont($icon->getIcon()),
|
2015-06-08 21:20:16 +02:00
|
|
|
' ',
|
2015-12-16 16:53:13 +01:00
|
|
|
$icon->getLabel(),
|
2015-06-08 21:20:16 +02:00
|
|
|
);
|
|
|
|
}
|
2014-08-12 17:04:38 +02:00
|
|
|
|
2015-06-08 21:20:16 +02:00
|
|
|
return $options;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function getColorOptions() {
|
|
|
|
$options = array();
|
|
|
|
|
2015-12-16 16:53:13 +01:00
|
|
|
foreach (PhabricatorProjectIconSet::getColorMap() as $color => $name) {
|
2015-06-08 21:20:16 +02:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2015-06-19 12:46:20 +02:00
|
|
|
$result = new PhabricatorApplicationSearchResultView();
|
|
|
|
$result->setObjectList($list);
|
|
|
|
$result->setNoDataString(pht('No projects found.'));
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
2014-05-09 21:25:52 +02:00
|
|
|
}
|
|
|
|
|
2015-12-21 20:15:44 +01:00
|
|
|
protected function getNewUserBody() {
|
|
|
|
$create_button = id(new PHUIButtonView())
|
|
|
|
->setTag('a')
|
|
|
|
->setText(pht('Create a Project'))
|
|
|
|
->setHref('/project/create/')
|
|
|
|
->setColor(PHUIButtonView::GREEN);
|
|
|
|
|
|
|
|
$icon = $this->getApplication()->getFontIcon();
|
|
|
|
$app_name = $this->getApplication()->getName();
|
|
|
|
$view = id(new PHUIBigInfoView())
|
|
|
|
->setIcon($icon)
|
|
|
|
->setTitle(pht('Welcome to %s', $app_name))
|
|
|
|
->setDescription(
|
|
|
|
pht('Projects are flexible storage containers used as '.
|
|
|
|
'tags, teams, projects, or anything you need to group.'))
|
|
|
|
->addAction($create_button);
|
|
|
|
|
|
|
|
return $view;
|
|
|
|
}
|
|
|
|
|
2013-07-22 17:34:35 +02:00
|
|
|
}
|