Flags - add ability to group by color
Summary: I use color to convey meaning like "good resource to keep handy for a bit on new way of doing things" or "snipe this task". Now the list can be grouped by these colors. Note I do this in PHP 'cuz color isn't part of any index AFAIK and pragmatically speaking this dataset should be tiny in the context of "user flags". Ref T1809 Test Plan: selected group by color and observed the flags were indeed grouped by color Reviewers: epriestley Reviewed By: epriestley CC: Korvin, aran Maniphest Tasks: T1809 Differential Revision: https://secure.phabricator.com/D7188
This commit is contained in:
		@@ -3,10 +3,14 @@
 | 
			
		||||
final class PhabricatorFlagQuery
 | 
			
		||||
  extends PhabricatorCursorPagedPolicyAwareQuery {
 | 
			
		||||
 | 
			
		||||
  const GROUP_COLOR = 'color';
 | 
			
		||||
  const GROUP_NONE  = 'none';
 | 
			
		||||
 | 
			
		||||
  private $ownerPHIDs;
 | 
			
		||||
  private $types;
 | 
			
		||||
  private $objectPHIDs;
 | 
			
		||||
  private $colors;
 | 
			
		||||
  private $groupBy = self::GROUP_NONE;
 | 
			
		||||
 | 
			
		||||
  private $needHandles;
 | 
			
		||||
  private $needObjects;
 | 
			
		||||
@@ -31,6 +35,16 @@ final class PhabricatorFlagQuery
 | 
			
		||||
    return $this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
   * Note this is done in php and not in mySQL, which means its inappropriate
 | 
			
		||||
   * for large datasets. Pragmatically, this is fine for user flags which are
 | 
			
		||||
   * typically well under 100 flags per user.
 | 
			
		||||
   */
 | 
			
		||||
  public function setGroupBy($group) {
 | 
			
		||||
    $this->groupBy = $group;
 | 
			
		||||
    return $this;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  public function needHandles($need) {
 | 
			
		||||
    $this->needHandles = $need;
 | 
			
		||||
    return $this;
 | 
			
		||||
@@ -96,6 +110,17 @@ final class PhabricatorFlagQuery
 | 
			
		||||
      }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    switch ($this->groupBy) {
 | 
			
		||||
      case self::GROUP_COLOR:
 | 
			
		||||
        $flags = msort($flags, 'getColor');
 | 
			
		||||
        break;
 | 
			
		||||
      case self::GROUP_NONE:
 | 
			
		||||
        break;
 | 
			
		||||
      default:
 | 
			
		||||
        throw new Exception("Unknown groupBy parameter: $this->groupBy");
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $flags;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -6,6 +6,7 @@ final class PhabricatorFlagSearchEngine
 | 
			
		||||
  public function buildSavedQueryFromRequest(AphrontRequest $request) {
 | 
			
		||||
    $saved = new PhabricatorSavedQuery();
 | 
			
		||||
    $saved->setParameter('colors', $request->getArr('colors'));
 | 
			
		||||
    $saved->setParameter('group', $request->getStr('group'));
 | 
			
		||||
    return $saved;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -18,6 +19,11 @@ final class PhabricatorFlagSearchEngine
 | 
			
		||||
    if ($colors) {
 | 
			
		||||
      $query->withColors($colors);
 | 
			
		||||
    }
 | 
			
		||||
    $group = $saved->getParameter('group');
 | 
			
		||||
    $options = $this->getGroupOptions();
 | 
			
		||||
    if ($group && isset($options[$group])) {
 | 
			
		||||
      $query->setGroupBy($group);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return $query;
 | 
			
		||||
  }
 | 
			
		||||
@@ -26,11 +32,18 @@ final class PhabricatorFlagSearchEngine
 | 
			
		||||
    AphrontFormView $form,
 | 
			
		||||
    PhabricatorSavedQuery $saved_query) {
 | 
			
		||||
 | 
			
		||||
    $form->appendChild(
 | 
			
		||||
      id(new PhabricatorFlagSelectControl())
 | 
			
		||||
    $form
 | 
			
		||||
      ->appendChild(
 | 
			
		||||
        id(new PhabricatorFlagSelectControl())
 | 
			
		||||
        ->setName('colors')
 | 
			
		||||
        ->setLabel(pht('Colors'))
 | 
			
		||||
        ->setValue($saved_query->getParameter('colors', array())));
 | 
			
		||||
        ->setValue($saved_query->getParameter('colors', array())))
 | 
			
		||||
      ->appendChild(
 | 
			
		||||
        id(new AphrontFormSelectControl())
 | 
			
		||||
        ->setName('group')
 | 
			
		||||
        ->setLabel(pht('Group By'))
 | 
			
		||||
        ->setValue($saved_query->getParameter('group'))
 | 
			
		||||
        ->setOptions($this->getGroupOptions()));
 | 
			
		||||
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
@@ -59,4 +72,11 @@ final class PhabricatorFlagSearchEngine
 | 
			
		||||
    return parent::buildSavedQueryFromBuiltin($query_key);
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  private function getGroupOptions() {
 | 
			
		||||
    return array(
 | 
			
		||||
      PhabricatorFlagQuery::GROUP_NONE => pht('None'),
 | 
			
		||||
      PhabricatorFlagQuery::GROUP_COLOR => pht('Color'),
 | 
			
		||||
    );
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user