Something went wrong. Try again.
@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
Something went wrong. Try again.
5.4 kB · 242 lines
PHP
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243<?php
final class PHUIDiffTableOfContentsItemView extends AphrontView {
private $changeset; private $isVisible = true; private $anchor; private $coverage; private $coverageID; private $context; private $packages;
public function setChangeset(DifferentialChangeset $changeset) { $this->changeset = $changeset; return $this; }
public function getChangeset() { return $this->changeset; }
public function setIsVisible($is_visible) { $this->isVisible = $is_visible; return $this; }
public function getIsVisible() { return $this->isVisible; }
public function setAnchor($anchor) { $this->anchor = $anchor; return $this; }
public function getAnchor() { return $this->anchor; }
public function setCoverage($coverage) { $this->coverage = $coverage; return $this; }
/** * Get the Coverage, expressed as a string, each letter with this meaning: * N: Not Executable, C: Covered, U: Uncovered. * @return string|null */ public function getCoverage() { return $this->coverage; }
public function setCoverageID($coverage_id) { $this->coverageID = $coverage_id; return $this; }
public function getCoverageID() { return $this->coverageID; }
public function setContext($context) { $this->context = $context; return $this; }
public function getContext() { return $this->context; }
/** * @param array<PhabricatorOwnersPackage> $packages */ public function setPackages(array $packages) { assert_instances_of($packages, PhabricatorOwnersPackage::class); $this->packages = mpull($packages, null, 'getPHID'); return $this; }
public function getPackages() { return $this->packages; }
public function render() { $changeset = $this->getChangeset();
$cells = array();
$cells[] = $this->getContext();
$cells[] = $changeset->newFileTreeIcon();
$link = $this->renderChangesetLink(); $lines = $this->renderChangesetLines(); $meta = $this->renderChangesetMetadata();
$cells[] = array( $link, $lines, $meta, );
$cells[] = $this->renderCoverage(); $cells[] = $this->renderModifiedCoverage();
$cells[] = $this->renderPackages();
return $cells; }
public function newLink() { $anchor = $this->getAnchor();
$changeset = $this->getChangeset(); $name = $changeset->getDisplayFilename(); $name = basename($name);
return javelin_tag( 'a', array( 'href' => '#'.$anchor, 'sigil' => 'differential-load', 'meta' => array( 'id' => 'diff-'.$anchor, ), ), $name); }
public function renderChangesetLines() { $changeset = $this->getChangeset();
if ($changeset->getIsLowImportanceChangeset()) { return null; }
$line_count = $changeset->getAffectedLineCount(); if (!$line_count) { return null; }
return pht('%s line(s)', new PhutilNumber($line_count)); }
public function renderCoverage() { $not_applicable = '-';
$coverage = $this->getCoverage(); if (!phutil_nonempty_string($coverage)) { return $not_applicable; }
$covered = substr_count($coverage, 'C'); $not_covered = substr_count($coverage, 'U');
if (!$not_covered && !$covered) { return $not_applicable; }
return sprintf('%d%%', 100 * ($covered / ($covered + $not_covered))); }
public function renderModifiedCoverage() { $not_applicable = '-';
$coverage = $this->getCoverage(); if (!phutil_nonempty_string($coverage)) { return $not_applicable; }
if ($this->getIsVisible()) { $label = pht('Loading...'); } else { $label = pht('?'); }
return phutil_tag( 'div', array( 'id' => $this->getCoverageID(), 'class' => 'differential-mcoverage-loading', ), $label); }
private function renderChangesetMetadata() { $changeset = $this->getChangeset(); $type = $changeset->getChangeType();
$meta = array(); if (DifferentialChangeType::isOldLocationChangeType($type)) { $away = $changeset->getAwayPaths(); if (count($away) > 1) { if ($type == DifferentialChangeType::TYPE_MULTICOPY) { $meta[] = pht('Deleted after being copied to multiple locations:'); } else { $meta[] = pht('Copied to multiple locations:'); } foreach ($away as $path) { $meta[] = $path; } } else { if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) { // This case is handled when we render the path. } else { $meta[] = pht('Copied to %s', head($away)); } } } else if ($type == DifferentialChangeType::TYPE_COPY_HERE) { $meta[] = pht('Copied from %s', $changeset->getOldFile()); }
if (!$meta) { return null; }
$meta = phutil_implode_html(phutil_tag('br'), $meta);
return phutil_tag( 'div', array( 'class' => 'differential-toc-meta', ), $meta); }
public function renderPackages() { $packages = $this->getPackages();
if (!$packages) { return null; }
$viewer = $this->getViewer(); $package_phids = mpull($packages, 'getPHID');
return $viewer->renderHandleList($package_phids) ->setGlyphLimit(48); }
}