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

Add basic NUX support to SearchEngines

Summary:
This is just putting a hook in that pretty much works. Behavior:

- If you visit `/maniphest/?nux=true`, it always shows NUX for testing.
- Otherwise, it shows NUX if there are no objects in the application yet.

Test Plan: {F1031846}

Reviewers: chad

Reviewed By: chad

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

+127 -40
+103 -40
src/applications/search/controller/PhabricatorApplicationSearchController.php
··· 107 107 // URIs like "/query/?users=a,b". 108 108 $pt_data = $request->getPassthroughRequestData(); 109 109 110 + $exempt = array( 111 + 'before' => true, 112 + 'after' => true, 113 + 'nux' => true, 114 + ); 115 + 110 116 foreach ($pt_data as $pt_key => $pt_value) { 111 - if ($pt_key != 'before' && $pt_key != 'after') { 112 - $found_query_data = true; 113 - break; 117 + if (isset($exempt[$pt_key])) { 118 + continue; 114 119 } 120 + 121 + $found_query_data = true; 122 + break; 115 123 } 116 124 } 117 125 ··· 203 211 204 212 $body[] = $box; 205 213 214 + 206 215 if ($run_query) { 207 216 $box->setAnchor( 208 217 id(new PhabricatorAnchorView()) 209 218 ->setAnchorName('R')); 210 219 211 220 try { 221 + $engine->setRequest($request); 222 + 212 223 $query = $engine->buildQueryFromSavedQuery($saved_query); 213 224 214 225 $pager = $engine->newPagerForSavedQuery($saved_query); ··· 216 227 217 228 $objects = $engine->executeQuery($query, $pager); 218 229 219 - $engine->setRequest($request); 220 - $list = $engine->renderResults($objects, $saved_query); 230 + $force_nux = $request->getBool('nux'); 231 + if (!$objects || $force_nux) { 232 + $nux_view = $this->renderNewUserView($engine, $force_nux); 233 + } else { 234 + $nux_view = null; 235 + } 221 236 222 - if (!($list instanceof PhabricatorApplicationSearchResultView)) { 223 - throw new Exception( 224 - pht( 225 - 'SearchEngines must render a "%s" object, but this engine '. 226 - '(of class "%s") rendered something else.', 227 - 'PhabricatorApplicationSearchResultView', 228 - get_class($engine))); 229 - } 237 + if ($nux_view) { 238 + $box->appendChild($nux_view); 239 + } else { 240 + $list = $engine->renderResults($objects, $saved_query); 230 241 231 - if ($list->getActions()) { 232 - foreach ($list->getActions() as $action) { 233 - $header->addActionLink($action); 242 + if (!($list instanceof PhabricatorApplicationSearchResultView)) { 243 + throw new Exception( 244 + pht( 245 + 'SearchEngines must render a "%s" object, but this engine '. 246 + '(of class "%s") rendered something else.', 247 + 'PhabricatorApplicationSearchResultView', 248 + get_class($engine))); 234 249 } 235 - } 250 + 251 + if ($list->getActions()) { 252 + foreach ($list->getActions() as $action) { 253 + $header->addActionLink($action); 254 + } 255 + } 236 256 237 - if ($list->getObjectList()) { 238 - $box->setObjectList($list->getObjectList()); 239 - } 240 - if ($list->getTable()) { 241 - $box->setTable($list->getTable()); 242 - } 243 - if ($list->getInfoView()) { 244 - $box->setInfoView($list->getInfoView()); 245 - } 246 - if ($list->getContent()) { 247 - $box->appendChild($list->getContent()); 248 - } 249 - if ($list->getCollapsed()) { 250 - $box->setCollapsed(true); 251 - } 257 + if ($list->getObjectList()) { 258 + $box->setObjectList($list->getObjectList()); 259 + } 260 + if ($list->getTable()) { 261 + $box->setTable($list->getTable()); 262 + } 263 + if ($list->getInfoView()) { 264 + $box->setInfoView($list->getInfoView()); 265 + } 266 + if ($list->getContent()) { 267 + $box->appendChild($list->getContent()); 268 + } 269 + if ($list->getCollapsed()) { 270 + $box->setCollapsed(true); 271 + } 252 272 253 - if ($pager->willShowPagingControls()) { 254 - $pager_box = id(new PHUIBoxView()) 255 - ->addPadding(PHUI::PADDING_MEDIUM) 256 - ->addMargin(PHUI::MARGIN_LARGE) 257 - ->setBorder(true) 258 - ->appendChild($pager); 259 - $body[] = $pager_box; 273 + if ($pager->willShowPagingControls()) { 274 + $pager_box = id(new PHUIBoxView()) 275 + ->addPadding(PHUI::PADDING_MEDIUM) 276 + ->addMargin(PHUI::MARGIN_LARGE) 277 + ->setBorder(true) 278 + ->appendChild($pager); 279 + $body[] = $pager_box; 280 + } 260 281 } 261 - 262 282 } catch (PhabricatorTypeaheadInvalidTokenException $ex) { 263 283 $errors[] = pht( 264 284 'This query specifies an invalid parameter. Review the '. ··· 395 415 396 416 return $nav; 397 417 } 418 + 419 + private function renderNewUserView( 420 + PhabricatorApplicationSearchEngine $engine, 421 + $force_nux) { 422 + 423 + // Don't render NUX if the user has clicked away from the default page. 424 + if (strlen($this->getQueryKey())) { 425 + return null; 426 + } 427 + 428 + // Don't put NUX in panels because it would be weird. 429 + if ($engine->isPanelContext()) { 430 + return null; 431 + } 432 + 433 + // Try to render the view itself first, since this should be very cheap 434 + // (just returning some text). 435 + $nux_view = $engine->renderNewUserView(); 436 + 437 + if (!$nux_view) { 438 + return null; 439 + } 440 + 441 + $query = $engine->newQuery(); 442 + if (!$query) { 443 + return null; 444 + } 445 + 446 + // Try to load any object at all. If we can, the application has seen some 447 + // use so we just render the normal view. 448 + if (!$force_nux) { 449 + $object = $query 450 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 451 + ->setLimit(1) 452 + ->execute(); 453 + if ($object) { 454 + return null; 455 + } 456 + } 457 + 458 + return $nux_view; 459 + } 460 + 398 461 399 462 }
+24
src/applications/search/engine/PhabricatorApplicationSearchEngine.php
··· 1354 1354 return $attachments; 1355 1355 } 1356 1356 1357 + final public function renderNewUserView() { 1358 + $head = $this->getNewUserHeader(); 1359 + $body = $this->getNewUserBody(); 1360 + 1361 + if (!strlen($head) && !strlen($body)) { 1362 + return null; 1363 + } 1364 + 1365 + $viewer = $this->requireViewer(); 1366 + 1367 + return id(new PHUIBoxView()) 1368 + ->addMargin(PHUI::MARGIN_LARGE) 1369 + ->appendChild($head) 1370 + ->appendChild(new PHUIRemarkupView($viewer, $body)); 1371 + } 1372 + 1373 + protected function getNewUserHeader() { 1374 + return null; 1375 + } 1376 + 1377 + protected function getNewUserBody() { 1378 + return null; 1379 + } 1380 + 1357 1381 }