@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.

Convert Macro to SearchFields

Summary: Ref T8441. Ref T7715. I'm primarily clearing callers to `saveQueryOrder()` so I can get rid of it.

Test Plan: Used all Macro search features.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T7715, T8441

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

+81 -129
+17 -26
src/applications/macro/query/PhabricatorMacroQuery.php
··· 5 5 6 6 private $ids; 7 7 private $phids; 8 - private $authors; 8 + private $authorPHIDs; 9 9 private $names; 10 10 private $nameLike; 11 11 private $namePrefix; ··· 51 51 return $this; 52 52 } 53 53 54 - public function withAuthorPHIDs(array $authors) { 55 - $this->authors = $authors; 54 + public function withAuthorPHIDs(array $author_phids) { 55 + $this->authorPHIDs = $author_phids; 56 56 return $this; 57 57 } 58 58 ··· 96 96 return $this; 97 97 } 98 98 99 - protected function loadPage() { 100 - $macro_table = new PhabricatorFileImageMacro(); 101 - $conn = $macro_table->establishConnection('r'); 102 - 103 - $rows = queryfx_all( 104 - $conn, 105 - 'SELECT m.* FROM %T m %Q %Q %Q', 106 - $macro_table->getTableName(), 107 - $this->buildWhereClause($conn), 108 - $this->buildOrderClause($conn), 109 - $this->buildLimitClause($conn)); 99 + public function newResultObject() { 100 + return new PhabricatorFileImageMacro(); 101 + } 110 102 111 - return $macro_table->loadAllFromArray($rows); 103 + protected function loadPage() { 104 + return $this->loadStandardPage(new PhabricatorFileImageMacro()); 112 105 } 113 106 114 - protected function buildWhereClause(AphrontDatabaseConnection $conn) { 115 - $where = array(); 107 + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 108 + $where = parent::buildWhereClauseParts($conn); 116 109 117 - if ($this->ids) { 110 + if ($this->ids !== null) { 118 111 $where[] = qsprintf( 119 112 $conn, 120 113 'm.id IN (%Ld)', 121 114 $this->ids); 122 115 } 123 116 124 - if ($this->phids) { 117 + if ($this->phids !== null) { 125 118 $where[] = qsprintf( 126 119 $conn, 127 120 'm.phid IN (%Ls)', 128 121 $this->phids); 129 122 } 130 123 131 - if ($this->authors) { 124 + if ($this->authorPHIDs !== null) { 132 125 $where[] = qsprintf( 133 126 $conn, 134 127 'm.authorPHID IN (%Ls)', 135 - $this->authors); 128 + $this->authorPHIDs); 136 129 } 137 130 138 - if ($this->nameLike) { 131 + if (strlen($this->nameLike)) { 139 132 $where[] = qsprintf( 140 133 $conn, 141 134 'm.name LIKE %~', 142 135 $this->nameLike); 143 136 } 144 137 145 - if ($this->names) { 138 + if ($this->names !== null) { 146 139 $where[] = qsprintf( 147 140 $conn, 148 141 'm.name IN (%Ls)', ··· 210 203 } 211 204 } 212 205 213 - $where[] = $this->buildPagingClause($conn); 214 - 215 - return $this->formatWhereClause($where); 206 + return $where; 216 207 } 217 208 218 209 protected function didFilterPage(array $macros) {
+57 -102
src/applications/macro/query/PhabricatorMacroSearchEngine.php
··· 11 11 return 'PhabricatorMacroApplication'; 12 12 } 13 13 14 - public function buildSavedQueryFromRequest(AphrontRequest $request) { 15 - $saved = new PhabricatorSavedQuery(); 16 - $saved->setParameter( 17 - 'authorPHIDs', 18 - $this->readUsersFromRequest($request, 'authors')); 19 - 20 - $saved->setParameter('status', $request->getStr('status')); 21 - $saved->setParameter('names', $request->getStrList('names')); 22 - $saved->setParameter('nameLike', $request->getStr('nameLike')); 23 - $saved->setParameter('createdStart', $request->getStr('createdStart')); 24 - $saved->setParameter('createdEnd', $request->getStr('createdEnd')); 25 - $saved->setParameter('flagColor', $request->getStr('flagColor', '-1')); 14 + public function newQuery() { 15 + return id(new PhabricatorMacroQuery()) 16 + ->needFiles(true); 17 + } 26 18 27 - $this->saveQueryOrder($saved, $request); 19 + protected function buildCustomSearchFields() { 20 + return array( 21 + id(new PhabricatorSearchSelectField()) 22 + ->setLabel(pht('Status')) 23 + ->setKey('status') 24 + ->setOptions(PhabricatorMacroQuery::getStatusOptions()), 25 + id(new PhabricatorSearchUsersField()) 26 + ->setLabel(pht('Authors')) 27 + ->setKey('authorPHIDs') 28 + ->setAliases(array('author', 'authors')), 29 + id(new PhabricatorSearchTextField()) 30 + ->setLabel(pht('Name Contains')) 31 + ->setKey('nameLike'), 32 + id(new PhabricatorSearchStringListField()) 33 + ->setLabel(pht('Exact Names')) 34 + ->setKey('names'), 35 + id(new PhabricatorSearchSelectField()) 36 + ->setLabel(pht('Marked with Flag')) 37 + ->setKey('flagColor') 38 + ->setDefault('-1') 39 + ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()), 40 + id(new PhabricatorSearchDateField()) 41 + ->setLabel(pht('Created After')) 42 + ->setKey('createdStart'), 43 + id(new PhabricatorSearchDateField()) 44 + ->setLabel(pht('Created Before')) 45 + ->setKey('createdEnd'), 46 + ); 47 + } 28 48 29 - return $saved; 49 + protected function getDefaultFieldOrder() { 50 + return array( 51 + '...', 52 + 'createdStart', 53 + 'createdEnd', 54 + ); 30 55 } 31 56 32 - public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) { 33 - $query = id(new PhabricatorMacroQuery()) 34 - ->needFiles(true) 35 - ->withIDs($saved->getParameter('ids', array())) 36 - ->withPHIDs($saved->getParameter('phids', array())) 37 - ->withAuthorPHIDs($saved->getParameter('authorPHIDs', array())); 57 + public function buildQueryFromParameters(array $map) { 58 + $query = $this->newQuery(); 38 59 39 - $this->setQueryOrder($query, $saved); 60 + if ($map['authorPHIDs']) { 61 + $query->withAuthorPHIDs($map['authorPHIDs']); 62 + } 40 63 41 - $status = $saved->getParameter('status'); 42 - $options = PhabricatorMacroQuery::getStatusOptions(); 43 - if (empty($options[$status])) { 44 - $status = head_key($options); 64 + if ($map['status']) { 65 + $query->withStatus($map['status']); 45 66 } 46 - $query->withStatus($status); 47 67 48 - $names = $saved->getParameter('names', array()); 49 - if ($names) { 50 - $query->withNames($names); 68 + if ($map['names']) { 69 + $query->withNames($map['names']); 51 70 } 52 71 53 - $like = $saved->getParameter('nameLike'); 54 - if (strlen($like)) { 55 - $query->withNameLike($like); 72 + if (strlen($map['nameLike'])) { 73 + $query->withNameLike($map['nameLike']); 56 74 } 57 75 58 - $start = $this->parseDateTime($saved->getParameter('createdStart')); 59 - $end = $this->parseDateTime($saved->getParameter('createdEnd')); 60 - 61 - if ($start) { 62 - $query->withDateCreatedAfter($start); 76 + if ($map['createdStart']) { 77 + $query->withDateCreatedAfter($map['createdStart']); 63 78 } 64 79 65 - if ($end) { 66 - $query->withDateCreatedBefore($end); 80 + if ($map['createdEnd']) { 81 + $query->withDateCreatedBefore($map['createdEnd']); 67 82 } 68 83 69 - $color = $saved->getParameter('flagColor'); 70 - if (strlen($color)) { 71 - $query->withFlagColor($color); 84 + if ($map['flagColor'] !== null) { 85 + $query->withFlagColor($map['flagColor']); 72 86 } 73 87 74 88 return $query; 75 89 } 76 90 77 - public function buildSearchForm( 78 - AphrontFormView $form, 79 - PhabricatorSavedQuery $saved) { 80 - 81 - $author_phids = $saved->getParameter('authorPHIDs', array()); 82 - $status = $saved->getParameter('status'); 83 - $names = implode(', ', $saved->getParameter('names', array())); 84 - $like = $saved->getParameter('nameLike'); 85 - $color = $saved->getParameter('flagColor', '-1'); 86 - 87 - $form 88 - ->appendChild( 89 - id(new AphrontFormSelectControl()) 90 - ->setName('status') 91 - ->setLabel(pht('Status')) 92 - ->setOptions(PhabricatorMacroQuery::getStatusOptions()) 93 - ->setValue($status)) 94 - ->appendControl( 95 - id(new AphrontFormTokenizerControl()) 96 - ->setDatasource(new PhabricatorPeopleDatasource()) 97 - ->setName('authors') 98 - ->setLabel(pht('Authors')) 99 - ->setValue($author_phids)) 100 - ->appendChild( 101 - id(new AphrontFormTextControl()) 102 - ->setName('nameLike') 103 - ->setLabel(pht('Name Contains')) 104 - ->setValue($like)) 105 - ->appendChild( 106 - id(new AphrontFormTextControl()) 107 - ->setName('names') 108 - ->setLabel(pht('Exact Names')) 109 - ->setValue($names)) 110 - ->appendChild( 111 - id(new AphrontFormSelectControl()) 112 - ->setName('flagColor') 113 - ->setLabel(pht('Marked with Flag')) 114 - ->setOptions(PhabricatorMacroQuery::getFlagColorsOptions()) 115 - ->setValue($color)); 116 - 117 - $this->buildDateRange( 118 - $form, 119 - $saved, 120 - 'createdStart', 121 - pht('Created After'), 122 - 'createdEnd', 123 - pht('Created Before')); 124 - 125 - $this->appendOrderFieldsToForm( 126 - $form, 127 - $saved, 128 - new PhabricatorMacroQuery()); 129 - } 130 - 131 91 protected function getURI($path) { 132 92 return '/macro/'.$path; 133 93 } ··· 165 125 return parent::buildSavedQueryFromBuiltin($query_key); 166 126 } 167 127 168 - protected function getRequiredHandlePHIDsForResultList( 169 - array $macros, 170 - PhabricatorSavedQuery $query) { 171 - return mpull($macros, 'getAuthorPHID'); 172 - } 173 - 174 128 protected function renderResultList( 175 129 array $macros, 176 130 PhabricatorSavedQuery $query, ··· 178 132 179 133 assert_instances_of($macros, 'PhabricatorFileImageMacro'); 180 134 $viewer = $this->requireViewer(); 135 + $handles = $viewer->loadHandles(mpull($macros, 'getAuthorPHID')); 181 136 182 137 $xform = PhabricatorFileTransform::getTransformByKey( 183 138 PhabricatorFileThumbnailTransform::TRANSFORM_PINBOARD);
+7 -1
src/applications/search/field/PhabricatorSearchSelectField.php
··· 4 4 extends PhabricatorSearchField { 5 5 6 6 private $options; 7 + private $default; 7 8 8 9 public function setOptions(array $options) { 9 10 $this->options = $options; ··· 15 16 } 16 17 17 18 protected function getDefaultValue() { 18 - return null; 19 + return $this->default; 20 + } 21 + 22 + public function setDefault($default) { 23 + $this->default = $default; 24 + return $this; 19 25 } 20 26 21 27 protected function getValueFromRequest(AphrontRequest $request, $key) {