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:
@@ -39,4 +39,31 @@ abstract class PhabricatorPasteController extends PhabricatorController {
|
|||||||
return $crumbs;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,17 +76,32 @@ final class PhabricatorPasteListController extends PhabricatorPasteController {
|
|||||||
|
|
||||||
$this->loadHandles(mpull($pastes, 'getAuthorPHID'));
|
$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 = new PhabricatorObjectItemListView();
|
||||||
$list->setViewer($user);
|
$list->setViewer($user);
|
||||||
foreach ($pastes as $paste) {
|
foreach ($pastes as $paste) {
|
||||||
$created = phabricator_date($paste->getDateCreated(), $user);
|
$created = phabricator_date($paste->getDateCreated(), $user);
|
||||||
$author = $this->getHandle($paste->getAuthorPHID())->renderLink();
|
$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())
|
$item = id(new PhabricatorObjectItemView())
|
||||||
->setHeader($paste->getFullName())
|
->setHeader($paste->getFullName())
|
||||||
->setHref('/P'.$paste->getID())
|
->setHref('/P'.$paste->getID())
|
||||||
->setObject($paste)
|
->setObject($paste)
|
||||||
->addAttribute(pht('Created %s by %s', $created, $author));
|
->addAttribute(pht('Created %s by %s', $created, $author))
|
||||||
|
->appendChild($source_code);
|
||||||
$list->addItem($item);
|
$list->addItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -152,27 +152,4 @@ final class PhabricatorPasteViewController extends PhabricatorPasteController {
|
|||||||
return $properties;
|
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -144,7 +144,7 @@ final class PhabricatorObjectItemView extends AphrontView {
|
|||||||
array(
|
array(
|
||||||
'class' => implode(' ', $classes),
|
'class' => implode(' ', $classes),
|
||||||
),
|
),
|
||||||
$icons.$header.$attrs);
|
$icons.$header.$attrs.$this->renderChildren());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user