1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-22 18:28:47 +02:00
phorge-phorge/src/applications/differential/view/DifferentialDiffTableOfContentsView.php

273 lines
7.7 KiB
PHP
Raw Normal View History

2011-01-24 22:18:41 +01:00
<?php
final class DifferentialDiffTableOfContentsView extends AphrontView {
private $changesets = array();
private $visibleChangesets = array();
private $references = array();
private $repository;
private $diff;
private $renderURI = '/differential/changeset/';
private $revisionID;
private $whitespace;
private $unitTestData;
2011-01-24 22:18:41 +01:00
public function setChangesets($changesets) {
$this->changesets = $changesets;
return $this;
}
public function setVisibleChangesets($visible_changesets) {
$this->visibleChangesets = $visible_changesets;
return $this;
}
public function setRenderingReferences(array $references) {
$this->references = $references;
return $this;
}
public function setRepository(PhabricatorRepository $repository) {
$this->repository = $repository;
return $this;
}
public function setDiff(DifferentialDiff $diff) {
$this->diff = $diff;
return $this;
}
public function setUnitTestData($unit_test_data) {
$this->unitTestData = $unit_test_data;
return $this;
}
public function setRevisionID($revision_id) {
$this->revisionID = $revision_id;
return $this;
}
public function setWhitespace($whitespace) {
$this->whitespace = $whitespace;
return $this;
}
2011-01-24 22:18:41 +01:00
public function render() {
2011-01-27 23:55:52 +01:00
require_celerity_resource('differential-core-view-css');
2011-01-25 20:57:47 +01:00
require_celerity_resource('differential-table-of-contents-css');
2011-01-24 22:18:41 +01:00
$rows = array();
$coverage = array();
if ($this->unitTestData) {
$coverage_by_file = array();
foreach ($this->unitTestData as $result) {
$test_coverage = idx($result, 'coverage');
if (!$test_coverage) {
continue;
}
foreach ($test_coverage as $file => $results) {
$coverage_by_file[$file][] = $results;
}
}
foreach ($coverage_by_file as $file => $coverages) {
$coverage[$file] = ArcanistUnitTestResult::mergeCoverage($coverages);
}
}
2011-01-24 22:18:41 +01:00
$changesets = $this->changesets;
$paths = array();
foreach ($changesets as $id => $changeset) {
2011-01-24 22:18:41 +01:00
$type = $changeset->getChangeType();
$ftype = $changeset->getFileType();
$ref = idx($this->references, $id);
$link = $this->renderChangesetLink($changeset, $ref);
2011-01-24 22:18:41 +01:00
if (DifferentialChangeType::isOldLocationChangeType($type)) {
$away = $changeset->getAwayPaths();
if (count($away) > 1) {
$meta = array();
if ($type == DifferentialChangeType::TYPE_MULTICOPY) {
$meta[] = pht('Deleted after being copied to multiple locations:');
2011-01-24 22:18:41 +01:00
} else {
$meta[] = pht('Copied to multiple locations:');
2011-01-24 22:18:41 +01:00
}
foreach ($away as $path) {
$meta[] = phutil_escape_html($path);
2011-01-24 22:18:41 +01:00
}
$meta = implode('<br />', $meta);
} else {
if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) {
$meta = pht('Moved to %s', phutil_escape_html(reset($away)));
2011-01-24 22:18:41 +01:00
} else {
$meta = pht('Copied to %s', phutil_escape_html(reset($away)));
2011-01-24 22:18:41 +01:00
}
}
} else if ($type == DifferentialChangeType::TYPE_MOVE_HERE) {
$meta = pht('Moved from %s',
phutil_escape_html($changeset->getOldFile()));
} else if ($type == DifferentialChangeType::TYPE_COPY_HERE) {
$meta = pht('Copied from %s',
phutil_escape_html($changeset->getOldFile()));
2011-01-24 22:18:41 +01:00
} else {
$meta = null;
2011-01-24 22:18:41 +01:00
}
$line_count = $changeset->getAffectedLineCount();
if ($line_count == 0) {
$lines = null;
} else {
$lines = ' '.pht('(%d line(s))', $line_count);
2011-01-24 22:18:41 +01:00
}
$char = DifferentialChangeType::getSummaryCharacterForChangeType($type);
$chartitle = DifferentialChangeType::getFullNameForChangeType($type);
$desc = DifferentialChangeType::getShortNameForFileType($ftype);
if ($desc) {
$desc = '('.$desc.')';
}
$pchar =
($changeset->getOldProperties() === $changeset->getNewProperties())
? null
: '<span title="'.pht('Properties Changed').'">M</span>';
2011-01-24 22:18:41 +01:00
$fname = $changeset->getFilename();
$cov = $this->renderCoverage($coverage, $fname);
if ($cov === null) {
$mcov = $cov = '<em>-</em>';
} else {
$mcov = phutil_tag(
'div',
array(
'id' => 'differential-mcoverage-'.md5($fname),
'class' => 'differential-mcoverage-loading',
),
(isset($this->visibleChangesets[$id]) ? 'Loading...' : '?'));
}
2011-01-24 22:18:41 +01:00
$rows[] =
'<tr>'.
phutil_render_tag(
'td',
array(
'class' => 'differential-toc-char',
'title' => $chartitle,
),
$char).
2011-01-24 22:18:41 +01:00
'<td class="differential-toc-prop">'.$pchar.'</td>'.
'<td class="differential-toc-ftype">'.$desc.'</td>'.
'<td class="differential-toc-file">'.$link.$lines.'</td>'.
'<td class="differential-toc-cov">'.$cov.'</td>'.
'<td class="differential-toc-mcov">'.$mcov.'</td>'.
2011-01-24 22:18:41 +01:00
'</tr>';
if ($meta) {
$rows[] =
'<tr>'.
2011-01-26 00:19:06 +01:00
'<td colspan="3"></td>'.
2011-01-24 22:18:41 +01:00
'<td class="differential-toc-meta">'.$meta.'</td>'.
'</tr>';
}
if ($this->diff && $this->repository) {
$paths[] =
$changeset->getAbsoluteRepositoryPath($this->repository, $this->diff);
}
}
$editor_link = null;
if ($paths && $this->user) {
$editor_link = $this->user->loadEditorLink(
$paths,
1, // line number
$this->repository->getCallsign());
if ($editor_link) {
$editor_link =
phutil_tag(
'a',
array(
'href' => $editor_link,
'class' => 'button differential-toc-edit-all',
),
pht('Open All in Editor'));
}
2011-01-24 22:18:41 +01:00
}
$reveal_link =
javelin_render_tag(
'a',
array(
'sigil' => 'differential-reveal-all',
'mustcapture' => true,
'class' => 'button differential-toc-reveal-all',
),
pht('Show All Context')
);
$buttons =
'<tr><td colspan="7">'.
$editor_link.$reveal_link.
'</td></tr>';
2011-01-24 22:18:41 +01:00
return
id(new PhabricatorAnchorView())
->setAnchorName('toc')
->setNavigationMarker(true)
->render().
id(new PhabricatorHeaderView())
->setHeader(pht('Table of Contents'))
->render().
'<div class="differential-toc differential-panel">'.
2011-01-24 22:18:41 +01:00
'<table>'.
'<tr>'.
'<th></th>'.
'<th></th>'.
'<th></th>'.
'<th>Path</th>'.
'<th class="differential-toc-cov">'.
pht('Coverage (All)').
'</th>'.
'<th class="differential-toc-mcov">'.
pht('Coverage (Touched)').
'</th>'.
'</tr>'.
2011-01-24 22:18:41 +01:00
implode("\n", $rows).
$buttons.
2011-01-24 22:18:41 +01:00
'</table>'.
'</div>';
}
private function renderCoverage(array $coverage, $file) {
$info = idx($coverage, $file);
if (!$info) {
return null;
}
$not_covered = substr_count($info, 'U');
$covered = substr_count($info, 'C');
if (!$not_covered && !$covered) {
return null;
}
return sprintf('%d%%', 100 * ($covered / ($covered + $not_covered)));
}
private function renderChangesetLink(DifferentialChangeset $changeset, $ref) {
$display_file = $changeset->getDisplayFilename();
return javelin_render_tag(
'a',
array(
'href' => '#'.$changeset->getAnchorName(),
'meta' => array(
'id' => 'diff-'.$changeset->getAnchorName(),
'ref' => $ref,
),
'sigil' => 'differential-load',
),
phutil_escape_html($display_file));
}
2011-01-24 22:18:41 +01:00
}