@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 recaptime-dev/main 151 lines 4.1 kB view raw
1<?php 2 3final class AlmanacServiceSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Almanac Services'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorAlmanacApplication::class; 12 } 13 14 public function newQuery() { 15 return new AlmanacServiceQuery(); 16 } 17 18 protected function buildQueryFromParameters(array $map) { 19 $query = $this->newQuery(); 20 21 if ($map['match'] !== null) { 22 $query->withNameNgrams($map['match']); 23 } 24 25 if ($map['names']) { 26 $query->withNames($map['names']); 27 } 28 29 if ($map['devicePHIDs']) { 30 $query->withDevicePHIDs($map['devicePHIDs']); 31 } 32 33 if ($map['serviceTypes']) { 34 $query->withServiceTypes($map['serviceTypes']); 35 } 36 37 return $query; 38 } 39 40 41 protected function buildCustomSearchFields() { 42 return array( 43 id(new PhabricatorSearchTextField()) 44 ->setLabel(pht('Name Contains')) 45 ->setKey('match') 46 ->setDescription(pht('Search for services by name substring.')), 47 id(new PhabricatorSearchStringListField()) 48 ->setLabel(pht('Exact Names')) 49 ->setKey('names') 50 ->setDescription(pht('Search for services with specific names.')), 51 id(new PhabricatorSearchDatasourceField()) 52 ->setLabel(pht('Service Types')) 53 ->setKey('serviceTypes') 54 ->setDescription(pht('Find services by type.')) 55 ->setDatasource(id(new AlmanacServiceTypeDatasource())), 56 id(new PhabricatorPHIDsSearchField()) 57 ->setLabel(pht('Devices')) 58 ->setKey('devicePHIDs') 59 ->setDescription( 60 pht('Search for services bound to particular devices.')), 61 ); 62 } 63 64 protected function getURI($path) { 65 return '/almanac/service/'.$path; 66 } 67 68 protected function getBuiltinQueryNames() { 69 $names = array( 70 'all' => pht('All Services'), 71 ); 72 73 return $names; 74 } 75 76 public function buildSavedQueryFromBuiltin($query_key) { 77 78 $query = $this->newSavedQuery(); 79 $query->setQueryKey($query_key); 80 81 switch ($query_key) { 82 case 'all': 83 return $query; 84 } 85 86 return parent::buildSavedQueryFromBuiltin($query_key); 87 } 88 89 /** 90 * @param array<AlmanacService> $services 91 * @param PhabricatorSavedQuery $query 92 * @param array<PhabricatorObjectHandle> $handles 93 */ 94 protected function renderResultList( 95 array $services, 96 PhabricatorSavedQuery $query, 97 array $handles) { 98 assert_instances_of($services, AlmanacService::class); 99 100 $viewer = $this->requireViewer(); 101 102 $list = new PHUIObjectItemListView(); 103 $list->setUser($viewer); 104 foreach ($services as $service) { 105 $item = id(new PHUIObjectItemView()) 106 ->setObjectName(pht('Service %d', $service->getID())) 107 ->setHeader($service->getName()) 108 ->setHref($service->getURI()) 109 ->setObject($service) 110 ->addIcon( 111 $service->getServiceImplementation()->getServiceTypeIcon(), 112 $service->getServiceImplementation()->getServiceTypeShortName()); 113 114 $list->addItem($item); 115 } 116 117 $result = new PhabricatorApplicationSearchResultView(); 118 $result->setObjectList($list); 119 $result->setNoDataString(pht('No Almanac Services found.')); 120 121 return $result; 122 } 123 124 protected function getNewUserBody() { 125 $see_devices = id(new PHUIButtonView()) 126 ->setTag('a') 127 ->setText(pht('See Devices')) 128 ->setHref('/almanac/device/'); 129 130 $create_button = id(new PHUIButtonView()) 131 ->setTag('a') 132 ->setText(pht('Create a Service')) 133 ->setHref('/almanac/service/edit/') 134 ->setIcon('fa-plus') 135 ->setColor(PHUIButtonView::GREEN); 136 137 138 $app_name = pht('Services'); 139 $view = id(new PHUIBigInfoView()) 140 ->setIcon('fa-plug') 141 ->setTitle(pht('Welcome to %s', $app_name)) 142 ->setDescription( 143 pht( 144 'Services describe pools of devices, and '. 145 'they are available to Drydock for CI/CD, and more.')) 146 ->addAction($see_devices) 147 ->addAction($create_button); 148 149 return $view; 150 } 151}