1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 11:30:55 +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));
$field_list->appendFieldsToForm($form);
$shades = PHUITagView::getShadeMap();
$shades = array_select_keys(
$shades,
array(PhabricatorProject::DEFAULT_COLOR)) + $shades;
unset($shades[PHUITagView::COLOR_DISABLED]);
$shades = PhabricatorProjectIcon::getColorMap();
$icon_uri = $this->getApplicationURI('icon/'.$project->getID().'/');
$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) {
$map = self::getIconMap();
return $map[$key];

View file

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

View file

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