@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Implement macros search by flags.

Summary: Reuse the existing flags functionality for searching macros. Currently implemented as a simple select element (for color).

Test Plan: Flagged some macros and tried searching by them.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D6709

authored by

Tarmo Lehtpuu and committed by
epriestley
8c01cc97 399c3e4e

+61 -1
+13
src/applications/flag/query/PhabricatorFlagQuery.php
··· 5 5 private $ownerPHIDs; 6 6 private $types; 7 7 private $objectPHIDs; 8 + private $color; 8 9 9 10 private $limit; 10 11 private $offset; ··· 36 37 37 38 public function withObjectPHIDs(array $object_phids) { 38 39 $this->objectPHIDs = $object_phids; 40 + return $this; 41 + } 42 + 43 + public function withColor($color) { 44 + $this->color = $color; 39 45 return $this; 40 46 } 41 47 ··· 144 150 $conn_r, 145 151 'flag.objectPHID IN (%Ls)', 146 152 $this->objectPHIDs); 153 + } 154 + 155 + if (strlen($this->color)) { 156 + $where[] = qsprintf( 157 + $conn_r, 158 + 'flag.color = %d', 159 + $this->color); 147 160 } 148 161 149 162 if ($where) {
+34
src/applications/macro/query/PhabricatorMacroQuery.php
··· 13 13 private $nameLike; 14 14 private $dateCreatedAfter; 15 15 private $dateCreatedBefore; 16 + private $flagColor; 16 17 17 18 private $status = 'status-any'; 18 19 const STATUS_ANY = 'status-any'; ··· 25 26 self::STATUS_DISABLED => pht('Disabled Macros'), 26 27 self::STATUS_ANY => pht('Active and Disabled Macros'), 27 28 ); 29 + } 30 + 31 + public static function getFlagColorsOptions() { 32 + 33 + $options = array('-1' => pht('(No Filtering)')); 34 + 35 + foreach (PhabricatorFlagColor::getColorNameMap() as $color => $name) { 36 + $options[$color] = $name; 37 + } 38 + 39 + return $options; 28 40 } 29 41 30 42 public function withIDs(array $ids) { ··· 64 76 65 77 public function withDateCreatedAfter($date_created_after) { 66 78 $this->dateCreatedAfter = $date_created_after; 79 + return $this; 80 + } 81 + 82 + public function withFlagColor($flag_color) { 83 + $this->flagColor = $flag_color; 67 84 return $this; 68 85 } 69 86 ··· 149 166 $conn, 150 167 'm.dateCreated <= %d', 151 168 $this->dateCreatedBefore); 169 + } 170 + 171 + if ($this->flagColor != '-1' && $this->flagColor !== null) { 172 + $flags = id(new PhabricatorFlagQuery()) 173 + ->withTypes(array(PhabricatorMacroPHIDTypeMacro::TYPECONST)) 174 + ->withColor($this->flagColor) 175 + ->setViewer($this->getViewer()) 176 + ->execute(); 177 + 178 + if (empty($flags)) { 179 + throw new PhabricatorEmptyQueryException('No matching flags.'); 180 + } else { 181 + $where[] = qsprintf( 182 + $conn, 183 + 'm.phid IN (%Ls)', 184 + mpull($flags, 'getObjectPHID')); 185 + } 152 186 } 153 187 154 188 $where[] = $this->buildPagingClause($conn);
+14 -1
src/applications/macro/query/PhabricatorMacroSearchEngine.php
··· 14 14 $saved->setParameter('nameLike', $request->getStr('nameLike')); 15 15 $saved->setParameter('createdStart', $request->getStr('createdStart')); 16 16 $saved->setParameter('createdEnd', $request->getStr('createdEnd')); 17 + $saved->setParameter('flagColor', $request->getStr('flagColor')); 17 18 18 19 return $saved; 19 20 } ··· 52 53 $query->withDateCreatedBefore($end); 53 54 } 54 55 56 + $color = $saved->getParameter('flagColor'); 57 + if (strlen($color)) { 58 + $query->withFlagColor($color); 59 + } 60 + 55 61 return $query; 56 62 } 57 63 ··· 68 74 $status = $saved_query->getParameter('status'); 69 75 $names = implode(', ', $saved_query->getParameter('names', array())); 70 76 $like = $saved_query->getParameter('nameLike'); 77 + $color = $saved_query->getParameter('flagColor', "-1"); 71 78 72 79 $form 73 80 ->appendChild( ··· 91 98 id(new AphrontFormTextControl()) 92 99 ->setName('names') 93 100 ->setLabel(pht('Exact Names')) 94 - ->setValue($names)); 101 + ->setValue($names)) 102 + ->appendChild( 103 + id(new AphrontFormSelectControl()) 104 + ->setName('flagColor') 105 + ->setLabel(pht('Marked with Flag')) 106 + ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()) 107 + ->setValue($color)); 95 108 96 109 $this->buildDateRange( 97 110 $form,