Differential D16483 Diff 39675 src/applications/differential/view/DifferentialRevisionUpdateHistoryView.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/view/DifferentialRevisionUpdateHistoryView.php
<?php | <?php | ||||
final class DifferentialRevisionUpdateHistoryView extends AphrontView { | final class DifferentialRevisionUpdateHistoryView extends AphrontView { | ||||
private $diffs = array(); | private $diffs = array(); | ||||
private $selectedVersusDiffID; | private $selectedVersusDiffID; | ||||
private $selectedDiffID; | private $selectedDiffID; | ||||
private $selectedWhitespace; | private $selectedWhitespace; | ||||
private $commitsForLinks = array(); | private $commitsForLinks = array(); | ||||
private $unitStatus = array(); | |||||
public function setDiffs(array $diffs) { | public function setDiffs(array $diffs) { | ||||
assert_instances_of($diffs, 'DifferentialDiff'); | assert_instances_of($diffs, 'DifferentialDiff'); | ||||
$this->diffs = $diffs; | $this->diffs = $diffs; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setSelectedVersusDiffID($id) { | public function setSelectedVersusDiffID($id) { | ||||
Show All 12 Lines | final class DifferentialRevisionUpdateHistoryView extends AphrontView { | ||||
} | } | ||||
public function setCommitsForLinks(array $commits) { | public function setCommitsForLinks(array $commits) { | ||||
assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | assert_instances_of($commits, 'PhabricatorRepositoryCommit'); | ||||
$this->commitsForLinks = $commits; | $this->commitsForLinks = $commits; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setDiffUnitStatuses(array $unit_status) { | |||||
$this->unitStatus = $unit_status; | |||||
return $this; | |||||
} | |||||
public function render() { | public function render() { | ||||
$this->requireResource('differential-core-view-css'); | $this->requireResource('differential-core-view-css'); | ||||
$this->requireResource('differential-revision-history-css'); | $this->requireResource('differential-revision-history-css'); | ||||
$data = array( | $data = array( | ||||
array( | array( | ||||
'name' => pht('Base'), | 'name' => pht('Base'), | ||||
'id' => null, | 'id' => null, | ||||
▲ Show 20 Lines • Show All 88 Lines • ▼ Show 20 Lines | foreach ($data as $row) { | ||||
if ($row['age']) { | if ($row['age']) { | ||||
$age = phabricator_datetime($row['age'], $this->getUser()); | $age = phabricator_datetime($row['age'], $this->getUser()); | ||||
} else { | } else { | ||||
$age = null; | $age = null; | ||||
} | } | ||||
if ($diff) { | if ($diff) { | ||||
$unit_status = idx( | |||||
$this->unitStatus, | |||||
$diff->getPHID(), | |||||
$diff->getUnitStatus()); | |||||
$lint = self::renderDiffLintStar($row['obj']); | $lint = self::renderDiffLintStar($row['obj']); | ||||
$lint = phutil_tag( | $lint = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'lintunit-star', | 'class' => 'lintunit-star', | ||||
'title' => self::getDiffLintMessage($diff), | 'title' => self::getDiffLintMessage($diff), | ||||
), | ), | ||||
$lint); | $lint); | ||||
$unit = self::renderDiffUnitStar($row['obj']); | $unit = self::renderDiffUnitStar($unit_status); | ||||
$unit = phutil_tag( | $unit = phutil_tag( | ||||
'div', | 'div', | ||||
array( | array( | ||||
'class' => 'lintunit-star', | 'class' => 'lintunit-star', | ||||
'title' => self::getDiffUnitMessage($diff), | 'title' => self::getDiffUnitMessage($unit_status), | ||||
), | ), | ||||
$unit); | $unit); | ||||
$base = $this->renderBaseRevision($diff); | $base = $this->renderBaseRevision($diff); | ||||
} else { | } else { | ||||
$lint = null; | $lint = null; | ||||
$unit = null; | $unit = null; | ||||
$base = null; | $base = null; | ||||
▲ Show 20 Lines • Show All 142 Lines • ▼ Show 20 Lines | final class DifferentialRevisionUpdateHistoryView extends AphrontView { | ||||
} | } | ||||
const STAR_NONE = 'none'; | const STAR_NONE = 'none'; | ||||
const STAR_OKAY = 'okay'; | const STAR_OKAY = 'okay'; | ||||
const STAR_WARN = 'warn'; | const STAR_WARN = 'warn'; | ||||
const STAR_FAIL = 'fail'; | const STAR_FAIL = 'fail'; | ||||
const STAR_SKIP = 'skip'; | const STAR_SKIP = 'skip'; | ||||
public static function renderDiffLintStar(DifferentialDiff $diff) { | private static function renderDiffLintStar(DifferentialDiff $diff) { | ||||
static $map = array( | static $map = array( | ||||
DifferentialLintStatus::LINT_NONE => self::STAR_NONE, | DifferentialLintStatus::LINT_NONE => self::STAR_NONE, | ||||
DifferentialLintStatus::LINT_OKAY => self::STAR_OKAY, | DifferentialLintStatus::LINT_OKAY => self::STAR_OKAY, | ||||
DifferentialLintStatus::LINT_WARN => self::STAR_WARN, | DifferentialLintStatus::LINT_WARN => self::STAR_WARN, | ||||
DifferentialLintStatus::LINT_FAIL => self::STAR_FAIL, | DifferentialLintStatus::LINT_FAIL => self::STAR_FAIL, | ||||
DifferentialLintStatus::LINT_SKIP => self::STAR_SKIP, | DifferentialLintStatus::LINT_SKIP => self::STAR_SKIP, | ||||
DifferentialLintStatus::LINT_AUTO_SKIP => self::STAR_SKIP, | DifferentialLintStatus::LINT_AUTO_SKIP => self::STAR_SKIP, | ||||
); | ); | ||||
$star = idx($map, $diff->getLintStatus(), self::STAR_FAIL); | $star = idx($map, $diff->getLintStatus(), self::STAR_FAIL); | ||||
return self::renderDiffStar($star); | return self::renderDiffStar($star); | ||||
} | } | ||||
public static function renderDiffUnitStar(DifferentialDiff $diff) { | private static function renderDiffUnitStar($unit_status) { | ||||
static $map = array( | static $map = array( | ||||
DifferentialUnitStatus::UNIT_NONE => self::STAR_NONE, | DifferentialUnitStatus::UNIT_NONE => self::STAR_NONE, | ||||
DifferentialUnitStatus::UNIT_OKAY => self::STAR_OKAY, | DifferentialUnitStatus::UNIT_OKAY => self::STAR_OKAY, | ||||
DifferentialUnitStatus::UNIT_WARN => self::STAR_WARN, | DifferentialUnitStatus::UNIT_WARN => self::STAR_WARN, | ||||
DifferentialUnitStatus::UNIT_FAIL => self::STAR_FAIL, | DifferentialUnitStatus::UNIT_FAIL => self::STAR_FAIL, | ||||
DifferentialUnitStatus::UNIT_SKIP => self::STAR_SKIP, | DifferentialUnitStatus::UNIT_SKIP => self::STAR_SKIP, | ||||
DifferentialUnitStatus::UNIT_AUTO_SKIP => self::STAR_SKIP, | DifferentialUnitStatus::UNIT_AUTO_SKIP => self::STAR_SKIP, | ||||
); | ); | ||||
$star = idx($map, $unit_status, self::STAR_FAIL); | |||||
$star = idx($map, $diff->getUnitStatus(), self::STAR_FAIL); | |||||
return self::renderDiffStar($star); | return self::renderDiffStar($star); | ||||
} | } | ||||
public static function getDiffLintMessage(DifferentialDiff $diff) { | public static function getDiffLintMessage(DifferentialDiff $diff) { | ||||
switch ($diff->getLintStatus()) { | switch ($diff->getLintStatus()) { | ||||
case DifferentialLintStatus::LINT_NONE: | case DifferentialLintStatus::LINT_NONE: | ||||
return pht('No Linters Available'); | return pht('No Linters Available'); | ||||
case DifferentialLintStatus::LINT_OKAY: | case DifferentialLintStatus::LINT_OKAY: | ||||
return pht('Lint OK'); | return pht('Lint OK'); | ||||
case DifferentialLintStatus::LINT_WARN: | case DifferentialLintStatus::LINT_WARN: | ||||
return pht('Lint Warnings'); | return pht('Lint Warnings'); | ||||
case DifferentialLintStatus::LINT_FAIL: | case DifferentialLintStatus::LINT_FAIL: | ||||
return pht('Lint Errors'); | return pht('Lint Errors'); | ||||
case DifferentialLintStatus::LINT_SKIP: | case DifferentialLintStatus::LINT_SKIP: | ||||
return pht('Lint Skipped'); | return pht('Lint Skipped'); | ||||
case DifferentialLintStatus::LINT_AUTO_SKIP: | case DifferentialLintStatus::LINT_AUTO_SKIP: | ||||
return pht('Automatic diff as part of commit; lint not applicable.'); | return pht('Automatic diff as part of commit; lint not applicable.'); | ||||
} | } | ||||
return pht('Unknown'); | return pht('Unknown'); | ||||
} | } | ||||
public static function getDiffUnitMessage(DifferentialDiff $diff) { | public static function getDiffUnitMessage($unit_status) { | ||||
switch ($diff->getUnitStatus()) { | switch ($unit_status) { | ||||
case DifferentialUnitStatus::UNIT_NONE: | case DifferentialUnitStatus::UNIT_NONE: | ||||
return pht('No Unit Test Coverage'); | return pht('No Unit Test Coverage'); | ||||
case DifferentialUnitStatus::UNIT_OKAY: | case DifferentialUnitStatus::UNIT_OKAY: | ||||
return pht('Unit Tests OK'); | return pht('Unit Tests OK'); | ||||
case DifferentialUnitStatus::UNIT_WARN: | case DifferentialUnitStatus::UNIT_WARN: | ||||
return pht('Unit Test Warnings'); | return pht('Unit Test Warnings'); | ||||
case DifferentialUnitStatus::UNIT_FAIL: | case DifferentialUnitStatus::UNIT_FAIL: | ||||
return pht('Unit Test Errors'); | return pht('Unit Test Errors'); | ||||
case DifferentialUnitStatus::UNIT_SKIP: | case DifferentialUnitStatus::UNIT_SKIP: | ||||
return pht('Unit Tests Skipped'); | return pht('Unit Tests Skipped'); | ||||
case DifferentialUnitStatus::UNIT_AUTO_SKIP: | case DifferentialUnitStatus::UNIT_AUTO_SKIP: | ||||
return pht( | return pht( | ||||
'Automatic diff as part of commit; unit tests not applicable.'); | 'Automatic diff as part of commit; unit tests not applicable.'); | ||||
} | } | ||||
return pht('Unknown'); | return pht('Unknown'); | ||||
} | } | ||||
private static function renderDiffStar($star) { | private static function renderDiffStar($star) { | ||||
$class = 'diff-star-'.$star; | $class = 'diff-star-'.$star; | ||||
return phutil_tag( | return phutil_tag( | ||||
'span', | 'span', | ||||
array('class' => $class), | array('class' => $class), | ||||
"\xE2\x98\x85"); | "\xE2\x98\x85"); | ||||
epriestley: (Is this a stray typo, or does it fix a display issue?) | |||||
Not Done Inline ActionsTypo... avivey: Typo... | |||||
} | } | ||||
private function renderBaseRevision(DifferentialDiff $diff) { | private function renderBaseRevision(DifferentialDiff $diff) { | ||||
switch ($diff->getSourceControlSystem()) { | switch ($diff->getSourceControlSystem()) { | ||||
case 'git': | case 'git': | ||||
$base = $diff->getSourceControlBaseRevision(); | $base = $diff->getSourceControlBaseRevision(); | ||||
if (strpos($base, '@') === false) { | if (strpos($base, '@') === false) { | ||||
$label = substr($base, 0, 7); | $label = substr($base, 0, 7); | ||||
Show All 34 Lines |
(Is this a stray typo, or does it fix a display issue?)