1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-11 17:32:41 +01:00
phorge-phorge/src/applications/differential/view/DifferentialLocalCommitsView.php
epriestley 31b6f69ff7 Allow CelerityResourceResponse to hold resources from multiple maps
Summary:
Ref T4222. Currently, CelerityResourceResponse holds response resources in flat maps. Instead, specify which map resources appear in.

Also, provide `requireResource()` and `initBehavior()` APIs on the Controller and View base classes. These provide a cleaner abstraction over `require_celerity_resource()` and `Javelin::initBehavior()`, but are otherwise the same. Move a few callsites over.

Test Plan:
  - Reloaded pages.
  - Browsed around Differential.

Reviewers: btrahan, hach-que

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T4222

Differential Revision: https://secure.phabricator.com/D7876
2014-01-02 11:59:35 -08:00

145 lines
3.7 KiB
PHP

<?php
final class DifferentialLocalCommitsView extends AphrontView {
private $localCommits;
public function setLocalCommits($local_commits) {
$this->localCommits = $local_commits;
return $this;
}
public function render() {
$user = $this->user;
if (!$user) {
throw new Exception("Call setUser() before render()-ing this view.");
}
$local = $this->localCommits;
if (!$local) {
return null;
}
$this->requireResource('differential-local-commits-view-css');
$has_tree = false;
$has_local = false;
foreach ($local as $commit) {
if (idx($commit, 'tree')) {
$has_tree = true;
}
if (idx($commit, 'local')) {
$has_local = true;
}
}
$rows = array();
$highlight = true;
foreach ($local as $commit) {
if ($highlight) {
$class = 'alt';
$highlight = false;
} else {
$class = '';
$highlight = true;
}
$row = array();
if (idx($commit, 'commit')) {
$commit_hash = self::formatCommit($commit['commit']);
} else if (isset($commit['rev'])) {
$commit_hash = self::formatCommit($commit['rev']);
} else {
$commit_hash = null;
}
$row[] = phutil_tag('td', array(), $commit_hash);
if ($has_tree) {
$tree = idx($commit, 'tree');
$tree = self::formatCommit($tree);
$row[] = phutil_tag('td', array(), $tree);
}
if ($has_local) {
$local_rev = idx($commit, 'local', null);
$row[] = phutil_tag('td', array(), $local_rev);
}
$parents = idx($commit, 'parents', array());
foreach ($parents as $k => $parent) {
if (is_array($parent)) {
$parent = idx($parent, 'rev');
}
$parents[$k] = self::formatCommit($parent);
}
$parents = phutil_implode_html(phutil_tag('br'), $parents);
$row[] = phutil_tag('td', array(), $parents);
$author = nonempty(
idx($commit, 'user'),
idx($commit, 'author'));
$row[] = phutil_tag('td', array(), $author);
$message = idx($commit, 'message');
$summary = idx($commit, 'summary');
$summary = phutil_utf8_shorten($summary, 80);
$view = new AphrontMoreView();
$view->setSome($summary);
if ($message && (trim($summary) != trim($message))) {
$view->setMore(phutil_escape_html_newlines($message));
}
$row[] = phutil_tag(
'td',
array(
'class' => 'summary',
),
$view->render());
$date = nonempty(
idx($commit, 'date'),
idx($commit, 'time'));
if ($date) {
$date = phabricator_datetime($date, $user);
}
$row[] = phutil_tag('td', array(), $date);
$rows[] = phutil_tag('tr', array('class' => $class), $row);
}
$headers = array();
$headers[] = phutil_tag('th', array(), pht('Commit'));
if ($has_tree) {
$headers[] = phutil_tag('th', array(), pht('Tree'));
}
if ($has_local) {
$headers[] = phutil_tag('th', array(), pht('Local'));
}
$headers[] = phutil_tag('th', array(), pht('Parents'));
$headers[] = phutil_tag('th', array(), pht('Author'));
$headers[] = phutil_tag('th', array(), pht('Summary'));
$headers[] = phutil_tag('th', array(), pht('Date'));
$headers = phutil_tag('tr', array(), $headers);
$content = phutil_tag_div('differential-panel', phutil_tag(
'table',
array('class' => 'differential-local-commits-table'),
array($headers, phutil_implode_html("\n", $rows))));
return id(new PHUIObjectBoxView())
->setHeaderText(pht('Local Commits'))
->appendChild($content);
}
private static function formatCommit($commit) {
return substr($commit, 0, 12);
}
}