@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
at upstream/main 170 lines 4.6 kB view raw
1<?php 2 3final class DiffusionRepositoryIdentitySearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Repository Identities'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorDiffusionApplication::class; 12 } 13 14 public function newQuery() { 15 return new PhabricatorRepositoryIdentityQuery(); 16 } 17 18 protected function buildCustomSearchFields() { 19 return array( 20 id(new PhabricatorUsersSearchField()) 21 ->setLabel(pht('Matching Users')) 22 ->setKey('effectivePHIDs') 23 ->setAliases( 24 array( 25 'effective', 26 'effectivePHID', 27 )) 28 ->setDescription(pht('Search for identities by effective user.')), 29 id(new DiffusionIdentityAssigneeSearchField()) 30 ->setLabel(pht('Assigned To')) 31 ->setKey('assignedPHIDs') 32 ->setAliases( 33 array( 34 'assigned', 35 'assignedPHID', 36 )) 37 ->setDescription(pht('Search for identities by explicit assignee.')), 38 id(new PhabricatorSearchTextField()) 39 ->setLabel(pht('Identity Contains')) 40 ->setKey('match') 41 ->setDescription(pht('Search for identities by substring.')), 42 id(new PhabricatorSearchThreeStateField()) 43 ->setLabel(pht('Has Matching User')) 44 ->setKey('hasEffectivePHID') 45 ->setOptions( 46 pht('(Show All)'), 47 pht('Show Identities With Matching Users'), 48 pht('Show Identities Without Matching Users')), 49 ); 50 } 51 52 protected function buildQueryFromParameters(array $map) { 53 $query = $this->newQuery(); 54 55 if ($map['hasEffectivePHID'] !== null) { 56 $query->withHasEffectivePHID($map['hasEffectivePHID']); 57 } 58 59 if ($map['match'] !== null) { 60 $query->withIdentityNameLike($map['match']); 61 } 62 63 if ($map['assignedPHIDs']) { 64 $query->withAssignedPHIDs($map['assignedPHIDs']); 65 } 66 67 if ($map['effectivePHIDs']) { 68 $query->withEffectivePHIDs($map['effectivePHIDs']); 69 } 70 71 return $query; 72 } 73 74 protected function getURI($path) { 75 return '/diffusion/identity/'.$path; 76 } 77 78 protected function getBuiltinQueryNames() { 79 $names = array( 80 'all' => pht('All Identities'), 81 ); 82 83 return $names; 84 } 85 86 public function buildSavedQueryFromBuiltin($query_key) { 87 88 $query = $this->newSavedQuery(); 89 $query->setQueryKey($query_key); 90 91 switch ($query_key) { 92 case 'all': 93 return $query; 94 } 95 96 return parent::buildSavedQueryFromBuiltin($query_key); 97 } 98 99 /** 100 * @param array<PhabricatorRepositoryIdentity> $identities 101 * @param PhabricatorSavedQuery $query 102 * @param array<PhabricatorObjectHandle> $handles 103 */ 104 protected function renderResultList( 105 array $identities, 106 PhabricatorSavedQuery $query, 107 array $handles) { 108 assert_instances_of($identities, PhabricatorRepositoryIdentity::class); 109 110 $viewer = $this->requireViewer(); 111 112 $list = id(new PHUIObjectItemListView()) 113 ->setViewer($viewer); 114 115 $phids = array(); 116 foreach ($identities as $identity) { 117 $phids[] = $identity->getCurrentEffectiveUserPHID(); 118 $phids[] = $identity->getManuallySetUserPHID(); 119 } 120 121 $handles = $viewer->loadHandles($phids); 122 123 $unassigned = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN; 124 125 foreach ($identities as $identity) { 126 $item = id(new PHUIObjectItemView()) 127 ->setObjectName($identity->getObjectName()) 128 ->setHeader($identity->getIdentityShortName()) 129 ->setHref($identity->getURI()) 130 ->setObject($identity); 131 132 $status_icon = 'fa-circle-o grey'; 133 134 $effective_phid = $identity->getCurrentEffectiveUserPHID(); 135 if ($effective_phid) { 136 $item->addIcon( 137 'fa-id-badge', 138 pht('Matches User: %s', $handles[$effective_phid]->getName())); 139 140 $status_icon = 'fa-id-badge'; 141 } 142 143 $assigned_phid = $identity->getManuallySetUserPHID(); 144 if ($assigned_phid) { 145 if ($assigned_phid === $unassigned) { 146 $item->addIcon( 147 'fa-ban', 148 pht('Explicitly Unassigned')); 149 $status_icon = 'fa-ban'; 150 } else { 151 $item->addIcon( 152 'fa-user', 153 pht('Assigned To: %s', $handles[$assigned_phid]->getName())); 154 $status_icon = 'fa-user'; 155 } 156 } 157 158 $item->setStatusIcon($status_icon); 159 160 $list->addItem($item); 161 } 162 163 $result = new PhabricatorApplicationSearchResultView(); 164 $result->setObjectList($list); 165 $result->setNoDataString(pht('No Identities found.')); 166 167 return $result; 168 } 169 170}