1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-18 12:52:42 +01:00

Allow projects to be filtered by icon and color

Summary: Ref T5819. Implements basic icon and color filtering for projects.

Test Plan: {F189350}

Reviewers: btrahan, chad

Reviewed By: chad

Subscribers: epriestley

Maniphest Tasks: T5819

Differential Revision: https://secure.phabricator.com/D10230
This commit is contained in:
epriestley 2014-08-12 08:04:38 -07:00
parent 9309723ac4
commit 94389fcd9f
6 changed files with 120 additions and 14 deletions

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_project.project
ADD KEY `key_icon` (icon);

View file

@ -0,0 +1,2 @@
ALTER TABLE {$NAMESPACE}_project.project
ADD KEY `key_color` (color);

View file

@ -144,11 +144,7 @@ final class PhabricatorProjectEditDetailsController
->setError($e_name)); ->setError($e_name));
$field_list->appendFieldsToForm($form); $field_list->appendFieldsToForm($form);
$shades = PHUITagView::getShadeMap(); $shades = PhabricatorProjectIcon::getColorMap();
$shades = array_select_keys(
$shades,
array(PhabricatorProject::DEFAULT_COLOR)) + $shades;
unset($shades[PHUITagView::COLOR_DISABLED]);
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/'); $icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
$icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon); $icon_display = PhabricatorProjectIcon::renderIconForChooser($v_icon);

View file

@ -24,6 +24,16 @@ final class PhabricatorProjectIcon extends Phobject {
); );
} }
public static function getColorMap() {
$shades = PHUITagView::getShadeMap();
$shades = array_select_keys(
$shades,
array(PhabricatorProject::DEFAULT_COLOR)) + $shades;
unset($shades[PHUITagView::COLOR_DISABLED]);
return $shades;
}
public static function getLabel($key) { public static function getLabel($key) {
$map = self::getIconMap(); $map = self::getIconMap();
return $map[$key]; return $map[$key];

View file

@ -10,6 +10,8 @@ final class PhabricatorProjectQuery
private $phrictionSlugs; private $phrictionSlugs;
private $names; private $names;
private $datasourceQuery; private $datasourceQuery;
private $icons;
private $colors;
private $status = 'status-any'; private $status = 'status-any';
const STATUS_ANY = 'status-any'; const STATUS_ANY = 'status-any';
@ -63,6 +65,16 @@ final class PhabricatorProjectQuery
return $this; return $this;
} }
public function withIcons(array $icons) {
$this->icons = $icons;
return $this;
}
public function withColors(array $colors) {
$this->colors = $colors;
return $this;
}
public function needMembers($need_members) { public function needMembers($need_members) {
$this->needMembers = $need_members; $this->needMembers = $need_members;
return $this; return $this;
@ -244,28 +256,28 @@ final class PhabricatorProjectQuery
$filter); $filter);
} }
if ($this->ids) { if ($this->ids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'id IN (%Ld)', 'id IN (%Ld)',
$this->ids); $this->ids);
} }
if ($this->phids) { if ($this->phids !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phid IN (%Ls)', 'phid IN (%Ls)',
$this->phids); $this->phids);
} }
if ($this->memberPHIDs) { if ($this->memberPHIDs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'e.dst IN (%Ls)', 'e.dst IN (%Ls)',
$this->memberPHIDs); $this->memberPHIDs);
} }
if ($this->slugs) { if ($this->slugs !== null) {
$slugs = array(); $slugs = array();
foreach ($this->slugs as $slug) { foreach ($this->slugs as $slug) {
$slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/'); $slugs[] = rtrim(PhabricatorSlug::normalize($slug), '/');
@ -277,20 +289,34 @@ final class PhabricatorProjectQuery
$slugs); $slugs);
} }
if ($this->phrictionSlugs) { if ($this->phrictionSlugs !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'phrictionSlug IN (%Ls)', 'phrictionSlug IN (%Ls)',
$this->phrictionSlugs); $this->phrictionSlugs);
} }
if ($this->names) { if ($this->names !== null) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'name IN (%Ls)', 'name IN (%Ls)',
$this->names); $this->names);
} }
if ($this->icons !== null) {
$where[] = qsprintf(
$conn_r,
'icon IN (%Ls)',
$this->icons);
}
if ($this->colors !== null) {
$where[] = qsprintf(
$conn_r,
'color IN (%Ls)',
$this->colors);
}
$where[] = $this->buildPagingClause($conn_r); $where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where); return $this->formatWhereClause($where);

View file

@ -25,6 +25,14 @@ final class PhabricatorProjectSearchEngine
$saved->setParameter('status', $request->getStr('status')); $saved->setParameter('status', $request->getStr('status'));
$saved->setParameter('name', $request->getStr('name')); $saved->setParameter('name', $request->getStr('name'));
$saved->setParameter(
'icons',
$this->readListFromRequest($request, 'icons'));
$saved->setParameter(
'colors',
$this->readListFromRequest($request, 'colors'));
$this->readCustomFieldsFromRequest($request, $saved); $this->readCustomFieldsFromRequest($request, $saved);
return $saved; return $saved;
@ -50,6 +58,16 @@ final class PhabricatorProjectSearchEngine
$query->withDatasourceQuery($name); $query->withDatasourceQuery($name);
} }
$icons = $saved->getParameter('icons');
if ($icons) {
$query->withIcons($icons);
}
$colors = $saved->getParameter('colors');
if ($colors) {
$query->withColors($colors);
}
$this->applyCustomFieldsToQuery($query, $saved); $this->applyCustomFieldsToQuery($query, $saved);
return $query; return $query;
@ -66,14 +84,45 @@ final class PhabricatorProjectSearchEngine
->execute(); ->execute();
$status = $saved->getParameter('status'); $status = $saved->getParameter('status');
$name = $saved->getParameter('name'); $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]));
}
$form $form
->appendChild( ->appendChild(
id(new AphrontFormTextControl()) id(new AphrontFormTextControl())
->setName('name') ->setName('name')
->setLabel(pht('Name')) ->setLabel(pht('Name'))
->setValue($name)) ->setValue($name_match))
->appendChild( ->appendChild(
id(new AphrontFormTokenizerControl()) id(new AphrontFormTokenizerControl())
->setDatasource(new PhabricatorPeopleDatasource()) ->setDatasource(new PhabricatorPeopleDatasource())
@ -85,7 +134,9 @@ final class PhabricatorProjectSearchEngine
->setLabel(pht('Status')) ->setLabel(pht('Status'))
->setName('status') ->setName('status')
->setOptions($this->getStatusOptions()) ->setOptions($this->getStatusOptions())
->setValue($status)); ->setValue($status))
->appendChild($icon_control)
->appendChild($color_control);
$this->appendCustomFieldsToForm($form, $saved); $this->appendCustomFieldsToForm($form, $saved);
} }
@ -142,6 +193,20 @@ final class PhabricatorProjectSearchEngine
); );
} }
private function getColorValues() {
}
private function getIconValues() {
}
protected function getRequiredHandlePHIDsForResultList(
array $projects,
PhabricatorSavedQuery $query) {
return mpull($projects, 'getPHID');
}
protected function renderResultList( protected function renderResultList(
array $projects, array $projects,
PhabricatorSavedQuery $query, PhabricatorSavedQuery $query,
@ -169,10 +234,15 @@ final class PhabricatorProjectSearchEngine
), ),
pht('Members')); pht('Members'));
$tag_list = id(new PHUIHandleTagListView())
->setSlim(true)
->setHandles(array($handles[$project->getPHID()]));
$item = id(new PHUIObjectItemView()) $item = id(new PHUIObjectItemView())
->setHeader($project->getName()) ->setHeader($project->getName())
->setHref($this->getApplicationURI("view/{$id}/")) ->setHref($this->getApplicationURI("view/{$id}/"))
->setImageURI($project->getProfileImageURI()) ->setImageURI($project->getProfileImageURI())
->addAttribute($tag_list)
->addAttribute($workboards_url) ->addAttribute($workboards_url)
->addAttribute($members_url); ->addAttribute($members_url);