2011-08-30 20:34:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class DifferentialLocalCommitsView extends AphrontView {
|
|
|
|
|
|
|
|
private $localCommits;
|
2014-04-02 22:18:11 +02:00
|
|
|
private $commitsForLinks = array();
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
public function setLocalCommits($local_commits) {
|
|
|
|
$this->localCommits = $local_commits;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2014-04-02 22:18:11 +02:00
|
|
|
public function setCommitsForLinks(array $commits) {
|
|
|
|
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
|
|
|
|
$this->commitsForLinks = $commits;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2011-08-30 20:34:07 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$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();
|
|
|
|
foreach ($local as $commit) {
|
|
|
|
$row = array();
|
|
|
|
if (idx($commit, 'commit')) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$commit_link = $this->buildCommitLink($commit['commit']);
|
2011-08-30 20:34:07 +02:00
|
|
|
} else if (isset($commit['rev'])) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$commit_link = $this->buildCommitLink($commit['rev']);
|
2011-08-30 20:34:07 +02:00
|
|
|
} else {
|
2014-04-02 22:18:11 +02:00
|
|
|
$commit_link = null;
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $commit_link;
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
if ($has_tree) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $this->buildCommitLink($commit['tree']);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ($has_local) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $this->buildCommitLink($commit['local']);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$parents = idx($commit, 'parents', array());
|
|
|
|
foreach ($parents as $k => $parent) {
|
|
|
|
if (is_array($parent)) {
|
|
|
|
$parent = idx($parent, 'rev');
|
|
|
|
}
|
2014-04-02 22:18:11 +02:00
|
|
|
$parents[$k] = $this->buildCommitLink($parent);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2013-02-13 23:50:15 +01:00
|
|
|
$parents = phutil_implode_html(phutil_tag('br'), $parents);
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $parents;
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$author = nonempty(
|
|
|
|
idx($commit, 'user'),
|
|
|
|
idx($commit, 'author'));
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $author;
|
2011-08-30 20:34:07 +02:00
|
|
|
|
2012-05-10 00:56:37 +02:00
|
|
|
$message = idx($commit, 'message');
|
|
|
|
|
2011-08-30 20:34:07 +02:00
|
|
|
$summary = idx($commit, 'summary');
|
2012-05-10 00:56:37 +02:00
|
|
|
$summary = phutil_utf8_shorten($summary, 80);
|
|
|
|
|
|
|
|
$view = new AphrontMoreView();
|
2013-01-31 18:08:02 +01:00
|
|
|
$view->setSome($summary);
|
2012-05-10 00:56:37 +02:00
|
|
|
|
|
|
|
if ($message && (trim($summary) != trim($message))) {
|
2013-01-31 18:08:02 +01:00
|
|
|
$view->setMore(phutil_escape_html_newlines($message));
|
2012-05-10 00:56:37 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $view->render();
|
2011-08-30 20:34:07 +02:00
|
|
|
|
|
|
|
$date = nonempty(
|
|
|
|
idx($commit, 'date'),
|
|
|
|
idx($commit, 'time'));
|
|
|
|
if ($date) {
|
|
|
|
$date = phabricator_datetime($date, $user);
|
|
|
|
}
|
2014-04-02 22:18:11 +02:00
|
|
|
$row[] = $date;
|
2011-08-30 20:34:07 +02:00
|
|
|
|
2014-04-02 22:18:11 +02:00
|
|
|
$rows[] = $row;
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
|
2014-04-02 22:18:11 +02:00
|
|
|
$column_classes = array('');
|
|
|
|
if ($has_tree) {
|
|
|
|
$column_classes[] = '';
|
|
|
|
}
|
|
|
|
if ($has_local) {
|
|
|
|
$column_classes[] = '';
|
|
|
|
}
|
|
|
|
$column_classes[] = '';
|
|
|
|
$column_classes[] = '';
|
|
|
|
$column_classes[] = 'wide';
|
|
|
|
$column_classes[] = 'date';
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setColumnClasses($column_classes);
|
2011-08-30 20:34:07 +02:00
|
|
|
$headers = array();
|
2014-04-02 22:18:11 +02:00
|
|
|
$headers[] = pht('Commit');
|
2011-08-30 20:34:07 +02:00
|
|
|
if ($has_tree) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$headers[] = pht('Tree');
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
|
|
|
if ($has_local) {
|
2014-04-02 22:18:11 +02:00
|
|
|
$headers[] = pht('Local');
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2014-04-02 22:18:11 +02:00
|
|
|
$headers[] = pht('Parents');
|
|
|
|
$headers[] = pht('Author');
|
|
|
|
$headers[] = pht('Summary');
|
|
|
|
$headers[] = pht('Date');
|
|
|
|
$table->setHeaders($headers);
|
2013-09-29 00:55:38 +02:00
|
|
|
|
|
|
|
return id(new PHUIObjectBoxView())
|
Provide more structure to PHUIObjectBoxView
Summary:
Three changes here.
- Add `setActionList()`, and use that to set the action list.
- Add `setPropertyList()`, and use that to set the property list.
These will let us add some apropriate CSS so we can fix the border issue, and get rid of a bunch of goofy `.x + .y` selectors.
- Replace `addContent()` with `appendChild()`.
This is just a consistency thing; `AphrontView` already provides `appendChild()`, and `addContent()` did the same thing.
Test Plan:
- Viewed "All Config".
- Viewed a countdown.
- Viewed a revision (add comment, change list, table of contents, comment, local commits, open revisions affecting these files, update history).
- Viewed Diffusion (browse, change, history, repository, lint).
- Viewed Drydock (resource, lease).
- Viewed Files.
- Viewed Herald.
- Viewed Legalpad.
- Viewed macro (edit, edit audio, view).
- Viewed Maniphest.
- Viewed Applications.
- Viewed Paste.
- Viewed People.
- Viewed Phulux.
- Viewed Pholio.
- Viewed Phame (blog, post).
- Viewed Phortune (account, product).
- Viewed Ponder (questions, answers, comments).
- Viewed Releeph.
- Viewed Projects.
- Viewed Slowvote.
NOTE: Images in Files aren't on a black background anymore -- I assume that's on purpose?
NOTE: Some jankiness in Phortune, I'll clean that up when I get back to it. Not related to this diff.
Reviewers: chad
Reviewed By: chad
CC: aran
Differential Revision: https://secure.phabricator.com/D7174
2013-09-30 18:36:04 +02:00
|
|
|
->setHeaderText(pht('Local Commits'))
|
2014-04-02 22:18:11 +02:00
|
|
|
->appendChild($table);
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|
2013-01-18 23:43:34 +01:00
|
|
|
|
|
|
|
private static function formatCommit($commit) {
|
|
|
|
return substr($commit, 0, 12);
|
|
|
|
}
|
|
|
|
|
2014-04-02 22:18:11 +02:00
|
|
|
private function buildCommitLink($hash) {
|
|
|
|
$commit_for_link = idx($this->commitsForLinks, $hash);
|
|
|
|
$commit_hash = self::formatCommit($hash);
|
|
|
|
if ($commit_for_link) {
|
|
|
|
$link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $commit_for_link->getURI()),
|
|
|
|
$commit_hash);
|
|
|
|
} else {
|
|
|
|
$link = $commit_hash;
|
|
|
|
}
|
|
|
|
return $link;
|
|
|
|
}
|
|
|
|
|
2011-08-30 20:34:07 +02:00
|
|
|
}
|