1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Add paste samples to list view.

Summary:
This adds a "body" field to `PhabricatorObjectItemView` which lets you optionally
add more information to the list view. It then uses this new field to show
samples of pastes in the paste list view.

Test Plan:
{F27147}

{F27148}

Reviewers: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D4188
This commit is contained in:
Ricky Elrod 2012-12-16 12:02:34 -08:00 committed by epriestley
parent 4c7c518c63
commit 6f9683dc90
4 changed files with 44 additions and 25 deletions

View file

@ -39,4 +39,31 @@ abstract class PhabricatorPasteController extends PhabricatorController {
return $crumbs;
}
public function buildSourceCodeView(
PhabricatorPaste $paste,
PhabricatorFile $file,
$max_lines = null) {
$language = $paste->getLanguage();
$source = $file->loadFileData();
if (empty($language)) {
$source = PhabricatorSyntaxHighlighter::highlightWithFilename(
$paste->getTitle(),
$source);
} else {
$source = PhabricatorSyntaxHighlighter::highlightWithLanguage(
$language,
$source);
}
$lines = explode("\n", $source);
if ($max_lines) {
$lines = array_slice($lines, 0, $max_lines);
}
return id(new PhabricatorSourceCodeView())
->setLines($lines);
}
}

View file

@ -76,17 +76,32 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
$this->loadHandles(mpull($pastes, 'getAuthorPHID'));
$file_phids = mpull($pastes, 'getFilePHID');
$files = array();
if ($file_phids) {
$files = id(new PhabricatorFile())->loadAllWhere(
"phid IN (%Ls)",
$file_phids);
}
$files_map = mpull($files, null, 'getPHID');
$list = new PhabricatorObjectItemListView();
$list->setViewer($user);
foreach ($pastes as $paste) {
$created = phabricator_date($paste->getDateCreated(), $user);
$author = $this->getHandle($paste->getAuthorPHID())->renderLink();
$file_phid = $paste->getFilePHID();
$file = idx($files_map, $file_phid);
$source_code = $this->buildSourceCodeView($paste, $file, 5)->render();
$item = id(new PhabricatorObjectItemView())
->setHeader($paste->getFullName())
->setHref('/P'.$paste->getID())
->setObject($paste)
->addAttribute(pht('Created %s by %s', $created, $author));
->addAttribute(pht('Created %s by %s', $created, $author))
->appendChild($source_code);
$list->addItem($item);
}

View file

@ -152,27 +152,4 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
return $properties;
}
private function buildSourceCodeView(
PhabricatorPaste $paste,
PhabricatorFile $file) {
$language = $paste->getLanguage();
$source = $file->loadFileData();
if (empty($language)) {
$source = PhabricatorSyntaxHighlighter::highlightWithFilename(
$paste->getTitle(),
$source);
} else {
$source = PhabricatorSyntaxHighlighter::highlightWithLanguage(
$language,
$source);
}
$lines = explode("\n", $source);
return id(new PhabricatorSourceCodeView())
->setLines($lines);
}
}

View file

@ -144,7 +144,7 @@ final class PhabricatorObjectItemView extends AphrontView {
array(
'class' => implode(' ', $classes),
),
$icons.$header.$attrs);
$icons.$header.$attrs.$this->renderChildren());
}
}