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

Make typeahead results more structured

Summary: Get rid of this positional array garbage.

Test Plan: Used typeaheads in menu, herald, maniphest, differential, repository/projects.

Reviewers: vrana, btrahan

Reviewed By: vrana

CC: aran

Maniphest Tasks: T1569

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

+145 -81
+1
src/__phutil_library_map__.php
··· 1013 1013 'PhabricatorTrivialTestCase' => 'infrastructure/testing/__tests__/PhabricatorTrivialTestCase.php', 1014 1014 'PhabricatorTypeaheadCommonDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php', 1015 1015 'PhabricatorTypeaheadDatasourceController' => 'applications/typeahead/controller/PhabricatorTypeaheadDatasourceController.php', 1016 + 'PhabricatorTypeaheadResult' => 'applications/typeahead/storage/PhabricatorTypeaheadResult.php', 1016 1017 'PhabricatorUIExample' => 'applications/uiexample/examples/PhabricatorUIExample.php', 1017 1018 'PhabricatorUIExampleController' => 'applications/uiexample/controller/PhabricatorUIExampleController.php', 1018 1019 'PhabricatorUIExampleRenderController' => 'applications/uiexample/controller/PhabricatorUIExampleRenderController.php',
+56 -81
src/applications/typeahead/controller/PhabricatorTypeaheadCommonDatasourceController.php
··· 88 88 break; 89 89 } 90 90 91 - // TODO: We transfer these fields without keys as an opitimization, but this 92 - // function is hard to read as a result. Until we can sort it out, here's 93 - // what the position arguments mean: 94 - // 95 - // 0: (required) name to match against what the user types 96 - // 1: (optional) URI 97 - // 2: (required) PHID 98 - // 3: (optional) priority matching string 99 - // 4: (optional) display name [overrides position 0] 100 - // 5: (optional) display type 101 - // 6: (optional) image URI 102 - 103 - $data = array(); 91 + $results = array(); 104 92 105 93 if ($need_upforgrabs) { 106 - $data[] = array( 107 - 'upforgrabs (Up For Grabs)', 108 - null, 109 - ManiphestTaskOwner::OWNER_UP_FOR_GRABS, 110 - ); 94 + $results[] = id(new PhabricatorTypeaheadResult()) 95 + ->setName('upforgrabs (Up For Grabs)') 96 + ->setPHID(ManiphestTaskOwner::OWNER_UP_FOR_GRABS); 111 97 } 112 98 113 99 if ($need_noproject) { 114 - $data[] = array( 115 - 'noproject (No Project)', 116 - null, 117 - ManiphestTaskOwner::PROJECT_NO_PROJECT, 118 - ); 100 + $results[] = id(new PhabricatorTypeaheadResult()) 101 + ->setName('noproject (No Project)') 102 + ->setPHID(ManiphestTaskOwner::PROJECT_NO_PROJECT); 119 103 } 120 104 121 105 if ($need_users) { 122 106 $columns = array( 123 107 'isSystemAgent', 108 + 'isAdmin', 124 109 'isDisabled', 125 110 'userName', 126 111 'realName', 127 112 'phid'); 128 - 129 - if ($need_rich_data) { 130 - $columns[] = 'profileImagePHID'; 131 - } 132 113 133 114 if ($query) { 134 115 $conn_r = id(new PhabricatorUser())->establishConnection('r'); ··· 164 145 continue; 165 146 } 166 147 } 167 - $spec = array( 168 - $user->getUsername().' ('.$user->getRealName().')', 169 - '/p/'.$user->getUsername(), 170 - $user->getPHID(), 171 - $user->getUsername(), 172 - null, 173 - 'User', 174 - ); 148 + 149 + $result = id(new PhabricatorTypeaheadResult()) 150 + ->setName($user->getFullName()) 151 + ->setURI('/p/'.$user->getUsername()) 152 + ->setPHID($user->getPHID()) 153 + ->setPriorityString($user->getUsername()); 154 + 175 155 if ($need_rich_data) { 176 - $spec[] = $handles[$user->getPHID()]->getImageURI(); 156 + $display_type = 'User'; 157 + if ($user->getIsAdmin()) { 158 + $display_type = 'Administrator'; 159 + } 160 + $result->setDisplayType($display_type); 161 + $result->setImageURI($handles[$user->getPHID()]->getImageURI()); 162 + $result->setPriorityType('user'); 177 163 } 178 - $data[] = $spec; 164 + $results[] = $result; 179 165 } 180 166 } 181 167 182 168 if ($need_lists) { 183 169 $lists = id(new PhabricatorMetaMTAMailingList())->loadAll(); 184 170 foreach ($lists as $list) { 185 - $data[] = array( 186 - $list->getName(), 187 - $list->getURI(), 188 - $list->getPHID(), 189 - ); 171 + $results[] = id(new PhabricatorTypeaheadResult()) 172 + ->setName($list->getName()) 173 + ->setURI($list->getURI()) 174 + ->setPHID($list->getPHID()); 190 175 } 191 176 } 192 177 ··· 195 180 'status != %d', 196 181 PhabricatorProjectStatus::STATUS_ARCHIVED); 197 182 foreach ($projs as $proj) { 198 - $data[] = array( 199 - $proj->getName(), 200 - '/project/view/'.$proj->getID().'/', 201 - $proj->getPHID(), 202 - ); 183 + $results[] = id(new PhabricatorTypeaheadResult()) 184 + ->setName($proj->getName()) 185 + ->setURI('/project/view/'.$proj->getID().'/') 186 + ->setPHID($proj->getPHID()); 203 187 } 204 188 } 205 189 206 190 if ($need_repos) { 207 191 $repos = id(new PhabricatorRepository())->loadAll(); 208 192 foreach ($repos as $repo) { 209 - $data[] = array( 210 - 'r'.$repo->getCallsign().' ('.$repo->getName().')', 211 - '/diffusion/'.$repo->getCallsign().'/', 212 - $repo->getPHID(), 213 - 'r'.$repo->getCallsign(), 214 - ); 193 + $results[] = id(new PhabricatorTypeaheadResult()) 194 + ->setName('r'.$repo->getCallsign().' ('.$repo->getName().')') 195 + ->setURI('/diffusion/'.$repo->getCallsign().'/') 196 + ->setPHID($repo->getPHID()) 197 + ->setPriorityString('r'.$repo->getCallsign()); 215 198 } 216 199 } 217 200 218 201 if ($need_packages) { 219 202 $packages = id(new PhabricatorOwnersPackage())->loadAll(); 220 203 foreach ($packages as $package) { 221 - $data[] = array( 222 - $package->getName(), 223 - '/owners/package/'.$package->getID().'/', 224 - $package->getPHID(), 225 - ); 204 + $results[] = id(new PhabricatorTypeaheadResult()) 205 + ->setName($package->getName()) 206 + ->setURI('/owners/package/'.$package->getID().'/') 207 + ->setPHID($package->getPHID()); 226 208 } 227 209 } 228 210 229 211 if ($need_arcanist_projects) { 230 212 $arcprojs = id(new PhabricatorRepositoryArcanistProject())->loadAll(); 231 213 foreach ($arcprojs as $proj) { 232 - $data[] = array( 233 - $proj->getName(), 234 - null, 235 - $proj->getPHID(), 236 - ); 214 + $results[] = id(new PhabricatorTypeaheadResult()) 215 + ->setName($proj->getName()) 216 + ->setPHID($proj->getPHID()); 237 217 } 238 218 } 239 219 ··· 244 224 if (!$uri) { 245 225 continue; 246 226 } 247 - $data[] = array( 248 - $application->getName().' '.$application->getShortDescription(), 249 - $uri, 250 - $application->getPHID(), 251 - $application->getName(), 252 - $application->getName(), 253 - $application->getShortDescription(), 254 - $application->getIconURI(), 255 - ); 256 - } 257 - } 227 + $name = $application->getName().' '.$application->getShortDescription(); 258 228 259 - if (!$need_rich_data) { 260 - foreach ($data as $key => $info) { 261 - unset($data[$key][4]); 262 - unset($data[$key][5]); 263 - unset($data[$key][6]); 229 + $results[] = id(new PhabricatorTypeaheadResult()) 230 + ->setName($name) 231 + ->setURI($uri) 232 + ->setPHID($application->getPHID()) 233 + ->setPriorityString($application->getName()) 234 + ->setDisplayName($application->getName()) 235 + ->setDisplayType($application->getShortDescription()) 236 + ->setImageuRI($application->getIconURI()) 237 + ->setPriorityType('apps'); 264 238 } 265 239 } 266 240 267 - return id(new AphrontAjaxResponse()) 268 - ->setContent($data); 241 + $content = mpull($results, 'getWireFormat'); 242 + 243 + return id(new AphrontAjaxResponse())->setContent($content); 269 244 } 270 245 271 246 }
+88
src/applications/typeahead/storage/PhabricatorTypeaheadResult.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class PhabricatorTypeaheadResult { 20 + 21 + private $name; 22 + private $uri; 23 + private $phid; 24 + private $priorityString; 25 + private $displayName; 26 + private $displayType; 27 + private $imageURI; 28 + private $priorityType; 29 + 30 + public function setName($name) { 31 + $this->name = $name; 32 + return $this; 33 + } 34 + 35 + public function setURI($uri) { 36 + $this->uri = $uri; 37 + return $this; 38 + } 39 + 40 + public function setPHID($phid) { 41 + $this->phid = $phid; 42 + return $this; 43 + } 44 + 45 + public function setPriorityString($priority_string) { 46 + $this->priorityString = $priority_string; 47 + return $this; 48 + } 49 + 50 + public function setDisplayName($display_name) { 51 + $this->displayName = $display_name; 52 + return $this; 53 + } 54 + 55 + public function setDisplayType($display_type) { 56 + $this->displayType = $display_type; 57 + return $this; 58 + } 59 + 60 + public function setImageURI($image_uri) { 61 + $this->imageURI = $image_uri; 62 + return $this; 63 + } 64 + 65 + public function setPriorityType($priority_type) { 66 + $this->priorityType = $priority_type; 67 + return $this; 68 + } 69 + 70 + public function getWireFormat() { 71 + $data = array( 72 + $this->name, 73 + $this->uri, 74 + $this->phid, 75 + $this->priorityString, 76 + $this->displayName, 77 + $this->displayType, 78 + $this->imageURI, 79 + $this->priorityType, 80 + ); 81 + while (end($data) === null) { 82 + array_pop($data); 83 + } 84 + return $data; 85 + } 86 + 87 + } 88 +