From 94389fcd9f58d044ceed687ef3ebfcdb86b003af Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 12 Aug 2014 08:04:38 -0700 Subject: [PATCH] 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 --- .../sql/autopatches/20140812.projkey.1.sql | 2 + .../sql/autopatches/20140812.projkey.2.sql | 2 + ...habricatorProjectEditDetailsController.php | 6 +- .../project/icon/PhabricatorProjectIcon.php | 10 +++ .../project/query/PhabricatorProjectQuery.php | 38 ++++++++-- .../query/PhabricatorProjectSearchEngine.php | 76 ++++++++++++++++++- 6 files changed, 120 insertions(+), 14 deletions(-) create mode 100644 resources/sql/autopatches/20140812.projkey.1.sql create mode 100644 resources/sql/autopatches/20140812.projkey.2.sql diff --git a/resources/sql/autopatches/20140812.projkey.1.sql b/resources/sql/autopatches/20140812.projkey.1.sql new file mode 100644 index 0000000000..c1726843ad --- /dev/null +++ b/resources/sql/autopatches/20140812.projkey.1.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_project.project + ADD KEY `key_icon` (icon); diff --git a/resources/sql/autopatches/20140812.projkey.2.sql b/resources/sql/autopatches/20140812.projkey.2.sql new file mode 100644 index 0000000000..c48a54d4d8 --- /dev/null +++ b/resources/sql/autopatches/20140812.projkey.2.sql @@ -0,0 +1,2 @@ +ALTER TABLE {$NAMESPACE}_project.project + ADD KEY `key_color` (color); diff --git a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php index 3852f7dee6..9732ff59aa 100644 --- a/src/applications/project/controller/PhabricatorProjectEditDetailsController.php +++ b/src/applications/project/controller/PhabricatorProjectEditDetailsController.php @@ -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); diff --git a/src/applications/project/icon/PhabricatorProjectIcon.php b/src/applications/project/icon/PhabricatorProjectIcon.php index 6f4e6d2925..7ed9d1c535 100644 --- a/src/applications/project/icon/PhabricatorProjectIcon.php +++ b/src/applications/project/icon/PhabricatorProjectIcon.php @@ -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]; diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index bb2d280ef3..bf2ec81461 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -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); diff --git a/src/applications/project/query/PhabricatorProjectSearchEngine.php b/src/applications/project/query/PhabricatorProjectSearchEngine.php index 0b0f94ba0c..dab0526739 100644 --- a/src/applications/project/query/PhabricatorProjectSearchEngine.php +++ b/src/applications/project/query/PhabricatorProjectSearchEngine.php @@ -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);