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

at recaptime-dev/main 175 lines 4.9 kB view raw
1<?php 2 3final class DrydockBlueprintSearchEngine 4 extends PhabricatorApplicationSearchEngine { 5 6 public function getResultTypeDescription() { 7 return pht('Drydock Blueprints'); 8 } 9 10 public function getApplicationClassName() { 11 return PhabricatorDrydockApplication::class; 12 } 13 14 public function newQuery() { 15 return id(new DrydockBlueprintQuery()); 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['isDisabled'] !== null) { 26 $query->withDisabled($map['isDisabled']); 27 } 28 29 return $query; 30 } 31 32 protected function buildCustomSearchFields() { 33 return array( 34 id(new PhabricatorSearchTextField()) 35 ->setLabel(pht('Name Contains')) 36 ->setKey('match') 37 ->setDescription(pht('Search for blueprints by name substring.')), 38 id(new PhabricatorSearchThreeStateField()) 39 ->setLabel(pht('Disabled')) 40 ->setKey('isDisabled') 41 ->setDescription(pht('Search for disabled or enabled blueprints.')) 42 ->setOptions( 43 pht('(Show All)'), 44 pht('Show Only Disabled Blueprints'), 45 pht('Hide Disabled Blueprints')), 46 ); 47 } 48 49 protected function getURI($path) { 50 return '/drydock/blueprint/'.$path; 51 } 52 53 protected function getBuiltinQueryNames() { 54 return array( 55 'active' => pht('Active Blueprints'), 56 'all' => pht('All Blueprints'), 57 ); 58 } 59 60 public function buildSavedQueryFromBuiltin($query_key) { 61 $query = $this->newSavedQuery(); 62 $query->setQueryKey($query_key); 63 64 switch ($query_key) { 65 case 'active': 66 return $query->setParameter('isDisabled', false); 67 case 'all': 68 return $query; 69 } 70 71 return parent::buildSavedQueryFromBuiltin($query_key); 72 } 73 74 /** 75 * @param array<DrydockBlueprint> $blueprints 76 * @param PhabricatorSavedQuery $query 77 * @param array<PhabricatorObjectHandle> $handles 78 */ 79 protected function renderResultList( 80 array $blueprints, 81 PhabricatorSavedQuery $query, 82 array $handles) { 83 assert_instances_of($blueprints, DrydockBlueprint::class); 84 85 $viewer = $this->requireViewer(); 86 87 if ($blueprints) { 88 $edge_query = id(new PhabricatorEdgeQuery()) 89 ->withSourcePHIDs(mpull($blueprints, 'getPHID')) 90 ->withEdgeTypes( 91 array( 92 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST, 93 )); 94 95 $edge_query->execute(); 96 } 97 98 $view = new PHUIObjectItemListView(); 99 100 foreach ($blueprints as $blueprint) { 101 $impl = $blueprint->getImplementation(); 102 103 $item = id(new PHUIObjectItemView()) 104 ->setHeader($blueprint->getBlueprintName()) 105 ->setHref($blueprint->getURI()) 106 ->setObjectName(pht('Blueprint %d', $blueprint->getID())); 107 108 if (!$impl->isEnabled()) { 109 $item->setDisabled(true); 110 $item->addIcon('fa-chain-broken grey', pht('Implementation')); 111 } 112 113 if ($blueprint->getIsDisabled()) { 114 $item->setDisabled(true); 115 $item->addIcon('fa-ban grey', pht('Disabled')); 116 } 117 118 $impl_icon = $impl->getBlueprintIcon(); 119 $impl_name = $impl->getBlueprintName(); 120 121 $impl_icon = id(new PHUIIconView()) 122 ->setIcon($impl_icon, 'lightgreytext'); 123 124 $item->addAttribute(array($impl_icon, ' ', $impl_name)); 125 126 $phid = $blueprint->getPHID(); 127 $project_phids = $edge_query->getDestinationPHIDs(array($phid)); 128 if ($project_phids) { 129 $project_handles = $viewer->loadHandles($project_phids); 130 $item->addAttribute( 131 id(new PHUIHandleTagListView()) 132 ->setLimit(4) 133 ->setSlim(true) 134 ->setHandles($project_handles)); 135 } 136 137 $view->addItem($item); 138 } 139 140 $result = new PhabricatorApplicationSearchResultView(); 141 $result->setObjectList($view); 142 $result->setNoDataString(pht('No blueprints found.')); 143 144 return $result; 145 } 146 147 protected function getNewUserBody() { 148 $see_almanac_button = id(new PHUIButtonView()) 149 ->setTag('a') 150 ->setText(pht('See Almanac services')) 151 ->setHref('/almanac/service/'); 152 153 $create_button = id(new PHUIButtonView()) 154 ->setTag('a') 155 ->setText(pht('Create a Blueprint')) 156 ->setHref('/drydock/blueprint/edit/') 157 ->setIcon('fa-plus') 158 ->setColor(PHUIButtonView::GREEN); 159 160 $app_name = pht('Blueprints'); 161 $view = id(new PHUIBigInfoView()) 162 ->setIcon('fa-map-o') 163 ->setTitle(pht('Welcome to %s', $app_name)) 164 ->setDescription( 165 pht( 166 'Blueprints allow to lease fresh working copies of repositories, '. 167 'on your Drydock devices, when needed by CI/CD workflows, and more. '. 168 'Blueprints lease services defined in your Almanac.')) 169 ->addAction($see_almanac_button) 170 ->addAction($create_button); 171 172 return $view; 173 } 174 175}