Path: blob/master/src/infrastructure/diff/view/PHUIDiffTableOfContentsItemView.php
12242 views
<?php12final class PHUIDiffTableOfContentsItemView extends AphrontView {34private $changeset;5private $isVisible = true;6private $anchor;7private $coverage;8private $coverageID;9private $context;10private $packages;1112public function setChangeset(DifferentialChangeset $changeset) {13$this->changeset = $changeset;14return $this;15}1617public function getChangeset() {18return $this->changeset;19}2021public function setIsVisible($is_visible) {22$this->isVisible = $is_visible;23return $this;24}2526public function getIsVisible() {27return $this->isVisible;28}2930public function setAnchor($anchor) {31$this->anchor = $anchor;32return $this;33}3435public function getAnchor() {36return $this->anchor;37}3839public function setCoverage($coverage) {40$this->coverage = $coverage;41return $this;42}4344public function getCoverage() {45return $this->coverage;46}4748public function setCoverageID($coverage_id) {49$this->coverageID = $coverage_id;50return $this;51}5253public function getCoverageID() {54return $this->coverageID;55}5657public function setContext($context) {58$this->context = $context;59return $this;60}6162public function getContext() {63return $this->context;64}6566public function setPackages(array $packages) {67assert_instances_of($packages, 'PhabricatorOwnersPackage');68$this->packages = mpull($packages, null, 'getPHID');69return $this;70}7172public function getPackages() {73return $this->packages;74}7576public function render() {77$changeset = $this->getChangeset();7879$cells = array();8081$cells[] = $this->getContext();8283$cells[] = $changeset->newFileTreeIcon();8485$link = $this->renderChangesetLink();86$lines = $this->renderChangesetLines();87$meta = $this->renderChangesetMetadata();8889$cells[] = array(90$link,91$lines,92$meta,93);9495$cells[] = $this->renderCoverage();96$cells[] = $this->renderModifiedCoverage();9798$cells[] = $this->renderPackages();99100return $cells;101}102103public function newLink() {104$anchor = $this->getAnchor();105106$changeset = $this->getChangeset();107$name = $changeset->getDisplayFilename();108$name = basename($name);109110return javelin_tag(111'a',112array(113'href' => '#'.$anchor,114'sigil' => 'differential-load',115'meta' => array(116'id' => 'diff-'.$anchor,117),118),119$name);120}121122public function renderChangesetLines() {123$changeset = $this->getChangeset();124125if ($changeset->getIsLowImportanceChangeset()) {126return null;127}128129$line_count = $changeset->getAffectedLineCount();130if (!$line_count) {131return null;132}133134return pht('%d line(s)', $line_count);135}136137public function renderCoverage() {138$not_applicable = '-';139140$coverage = $this->getCoverage();141if ($coverage === null || !strlen($coverage)) {142return $not_applicable;143}144145$covered = substr_count($coverage, 'C');146$not_covered = substr_count($coverage, 'U');147148if (!$not_covered && !$covered) {149return $not_applicable;150}151152return sprintf('%d%%', 100 * ($covered / ($covered + $not_covered)));153}154155public function renderModifiedCoverage() {156$not_applicable = '-';157158$coverage = $this->getCoverage();159if ($coverage === null || !strlen($coverage)) {160return $not_applicable;161}162163if ($this->getIsVisible()) {164$label = pht('Loading...');165} else {166$label = pht('?');167}168169return phutil_tag(170'div',171array(172'id' => $this->getCoverageID(),173'class' => 'differential-mcoverage-loading',174),175$label);176}177178private function renderChangesetMetadata() {179$changeset = $this->getChangeset();180$type = $changeset->getChangeType();181182$meta = array();183if (DifferentialChangeType::isOldLocationChangeType($type)) {184$away = $changeset->getAwayPaths();185if (count($away) > 1) {186if ($type == DifferentialChangeType::TYPE_MULTICOPY) {187$meta[] = pht('Deleted after being copied to multiple locations:');188} else {189$meta[] = pht('Copied to multiple locations:');190}191foreach ($away as $path) {192$meta[] = $path;193}194} else {195if ($type == DifferentialChangeType::TYPE_MOVE_AWAY) {196// This case is handled when we render the path.197} else {198$meta[] = pht('Copied to %s', head($away));199}200}201} else if ($type == DifferentialChangeType::TYPE_COPY_HERE) {202$meta[] = pht('Copied from %s', $changeset->getOldFile());203}204205if (!$meta) {206return null;207}208209$meta = phutil_implode_html(phutil_tag('br'), $meta);210211return phutil_tag(212'div',213array(214'class' => 'differential-toc-meta',215),216$meta);217}218219public function renderPackages() {220$packages = $this->getPackages();221222if (!$packages) {223return null;224}225226$viewer = $this->getViewer();227$package_phids = mpull($packages, 'getPHID');228229return $viewer->renderHandleList($package_phids)230->setGlyphLimit(48);231}232233}234235236