1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 08:52:39 +01:00

Move paste rendering into SearchEngine

Summary:
Ref T4986. One note:

  - I've disabled syntax highlighting in the previews. When we miss caches this is just way way too slow and has frustrated me several times in the past. The value of syntax highlighting these snippets is not huge. We could maybe ajax this in or use it //if// we get a cache hit in the future, but just kill it for the moment.

Test Plan: Viewed pastes. Created a paste panel.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4986

Differential Revision: https://secure.phabricator.com/D9138
This commit is contained in:
epriestley 2014-05-15 19:17:22 -07:00
parent 5b3ccfd95f
commit d653fa13de
2 changed files with 65 additions and 61 deletions

View file

@ -1,10 +1,6 @@
<?php
/**
* @group paste
*/
final class PhabricatorPasteListController extends PhabricatorPasteController
implements PhabricatorApplicationSearchResultsControllerInterface {
final class PhabricatorPasteListController extends PhabricatorPasteController {
private $queryKey;
@ -26,57 +22,5 @@ final class PhabricatorPasteListController extends PhabricatorPasteController
return $this->delegateToController($controller);
}
public function renderResultsList(
array $pastes,
PhabricatorSavedQuery $query) {
assert_instances_of($pastes, 'PhabricatorPaste');
$user = $this->getRequest()->getUser();
$this->loadHandles(mpull($pastes, 'getAuthorPHID'));
$lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
$list = new PHUIObjectItemListView();
$list->setUser($user);
foreach ($pastes as $paste) {
$created = phabricator_date($paste->getDateCreated(), $user);
$author = $this->getHandle($paste->getAuthorPHID())->renderLink();
$source_code = $this->buildSourceCodeView($paste, 5)->render();
$source_code = phutil_tag(
'div',
array(
'class' => 'phabricator-source-code-summary',
),
$source_code);
$line_count = count(explode("\n", $paste->getContent()));
$line_count = pht(
'%s Line(s)',
new PhutilNumber($line_count));
$title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)'));
$item = id(new PHUIObjectItemView())
->setObjectName('P'.$paste->getID())
->setHeader($title)
->setHref('/P'.$paste->getID())
->setObject($paste)
->addByline(pht('Author: %s', $author))
->addIcon('none', $line_count)
->appendChild($source_code);
$lang_name = $paste->getLanguage();
if ($lang_name) {
$lang_name = idx($lang_map, $lang_name, $lang_name);
$item->addIcon('none', $lang_name);
}
$list->addItem($item);
}
return $list;
}
}

View file

@ -1,8 +1,5 @@
<?php
/**
* @group paste
*/
final class PhabricatorPasteSearchEngine
extends PhabricatorApplicationSearchEngine {
@ -26,7 +23,7 @@ final class PhabricatorPasteSearchEngine
public function buildQueryFromSavedQuery(PhabricatorSavedQuery $saved) {
$query = id(new PhabricatorPasteQuery())
->needContent(true)
->needRawContent(true)
->withAuthorPHIDs($saved->getParameter('authorPHIDs', array()))
->withLanguages($saved->getParameter('languages', array()));
@ -126,4 +123,67 @@ final class PhabricatorPasteSearchEngine
return parent::buildSavedQueryFromBuiltin($query_key);
}
protected function getRequiredHandlePHIDsForResultList(
array $pastes,
PhabricatorSavedQuery $query) {
return mpull($pastes, 'getAuthorPHID');
}
protected function renderResultList(
array $pastes,
PhabricatorSavedQuery $query,
array $handles) {
assert_instances_of($pastes, 'PhabricatorPaste');
$viewer = $this->requireViewer();
$lang_map = PhabricatorEnv::getEnvConfig('pygments.dropdown-choices');
$list = new PHUIObjectItemListView();
$list->setUser($viewer);
foreach ($pastes as $paste) {
$created = phabricator_date($paste->getDateCreated(), $viewer);
$author = $handles[$paste->getAuthorPHID()]->renderLink();
$lines = phutil_split_lines($paste->getRawContent());
$preview = id(new PhabricatorSourceCodeView())
->setLimit(5)
->setLines($lines)
->setURI(new PhutilURI($paste->getURI()));
$source_code = phutil_tag(
'div',
array(
'class' => 'phabricator-source-code-summary',
),
$preview);
$line_count = count($lines);
$line_count = pht(
'%s Line(s)',
new PhutilNumber($line_count));
$title = nonempty($paste->getTitle(), pht('(An Untitled Masterwork)'));
$item = id(new PHUIObjectItemView())
->setObjectName('P'.$paste->getID())
->setHeader($title)
->setHref('/P'.$paste->getID())
->setObject($paste)
->addByline(pht('Author: %s', $author))
->addIcon('none', $line_count)
->appendChild($source_code);
$lang_name = $paste->getLanguage();
if ($lang_name) {
$lang_name = idx($lang_map, $lang_name, $lang_name);
$item->addIcon('none', $lang_name);
}
$list->addItem($item);
}
return $list;
}
}