Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/view/HarbormasterUnitPropertyView.php
<?php | <?php | ||||
final class HarbormasterUnitPropertyView extends AphrontView { | final class HarbormasterUnitPropertyView extends AphrontView { | ||||
private $pathURIMap = array(); | private $pathURIMap = array(); | ||||
private $unitMessages = array(); | private $unitMessages = array(); | ||||
private $limit; | private $limit; | ||||
private $fullResultsURI; | |||||
public function setPathURIMap(array $map) { | public function setPathURIMap(array $map) { | ||||
$this->pathURIMap = $map; | $this->pathURIMap = $map; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setUnitMessages(array $messages) { | public function setUnitMessages(array $messages) { | ||||
assert_instances_of($messages, 'HarbormasterBuildUnitMessage'); | assert_instances_of($messages, 'HarbormasterBuildUnitMessage'); | ||||
$this->unitMessages = $messages; | $this->unitMessages = $messages; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setLimit($limit) { | public function setLimit($limit) { | ||||
$this->limit = $limit; | $this->limit = $limit; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function setFullResultsURI($full_results_uri) { | |||||
$this->fullResultsURI = $full_results_uri; | |||||
return $this; | |||||
} | |||||
public function render() { | public function render() { | ||||
$messages = $this->unitMessages; | $messages = $this->unitMessages; | ||||
$messages = msort($messages, 'getSortKey'); | $messages = msort($messages, 'getSortKey'); | ||||
$limit = $this->limit; | |||||
if ($this->limit) { | if ($this->limit) { | ||||
$messages = array_slice($messages, 0, $this->limit); | $display_messages = array_slice($messages, 0, $limit); | ||||
} else { | |||||
$display_messages = $messages; | |||||
} | } | ||||
$rows = array(); | $rows = array(); | ||||
$any_duration = false; | $any_duration = false; | ||||
foreach ($messages as $message) { | foreach ($display_messages as $message) { | ||||
$result = $this->renderResult($message->getResult()); | $status = $message->getResult(); | ||||
$icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status); | |||||
$icon_color = HarbormasterUnitStatus::getUnitStatusColor($status); | |||||
$icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status); | |||||
$result_icon = id(new PHUIIconView()) | |||||
->setIcon("{$icon_icon} {$icon_color}") | |||||
->addSigil('has-tooltip') | |||||
->setMetadata( | |||||
array( | |||||
'tip' => $icon_label, | |||||
)); | |||||
$duration = $message->getDuration(); | $duration = $message->getDuration(); | ||||
if ($duration !== null) { | if ($duration !== null) { | ||||
$any_duration = true; | $any_duration = true; | ||||
$duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration))); | $duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration))); | ||||
} | } | ||||
$name = $message->getName(); | $name = $message->getName(); | ||||
$namespace = $message->getNamespace(); | $namespace = $message->getNamespace(); | ||||
if (strlen($namespace)) { | if (strlen($namespace)) { | ||||
$name = $namespace.'::'.$name; | $name = $namespace.'::'.$name; | ||||
} | } | ||||
$engine = $message->getEngine(); | $engine = $message->getEngine(); | ||||
if (strlen($engine)) { | if (strlen($engine)) { | ||||
$name = $engine.' > '.$name; | $name = $engine.' > '.$name; | ||||
} | } | ||||
$rows[] = array( | $rows[] = array( | ||||
$result, | $result_icon, | ||||
$duration, | $duration, | ||||
$name, | $name, | ||||
); | ); | ||||
} | } | ||||
$full_uri = $this->fullResultsURI; | |||||
if ($full_uri && (count($messages) > $limit)) { | |||||
$counts = array(); | |||||
$groups = mgroup($messages, 'getResult'); | |||||
foreach ($groups as $status => $group) { | |||||
$counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel( | |||||
$status, | |||||
count($group)); | |||||
} | |||||
$link_text = pht( | |||||
'View Full Test Results (%s)', | |||||
implode(" \xC2\xB7 ", $counts)); | |||||
$full_link = phutil_tag( | |||||
'a', | |||||
array( | |||||
'href' => $full_uri, | |||||
), | |||||
$link_text); | |||||
$link_icon = id(new PHUIIconView()) | |||||
->setIcon('fa-ellipsis-h lightgreytext'); | |||||
$rows[] = array($link_icon, null, $full_link); | |||||
} | |||||
$table = id(new AphrontTableView($rows)) | $table = id(new AphrontTableView($rows)) | ||||
->setHeaders( | ->setHeaders( | ||||
array( | array( | ||||
pht('Result'), | null, | ||||
pht('Time'), | pht('Time'), | ||||
pht('Test'), | pht('Test'), | ||||
)) | )) | ||||
->setColumnClasses( | ->setColumnClasses( | ||||
array( | array( | ||||
null, | null, | ||||
null, | null, | ||||
'pri wide', | 'pri wide', | ||||
)) | )) | ||||
->setColumnVisibility( | ->setColumnVisibility( | ||||
array( | array( | ||||
true, | true, | ||||
$any_duration, | $any_duration, | ||||
)); | )); | ||||
return $table; | return $table; | ||||
} | } | ||||
private function renderResult($result) { | |||||
$names = array( | |||||
ArcanistUnitTestResult::RESULT_BROKEN => pht('Broken'), | |||||
ArcanistUnitTestResult::RESULT_FAIL => pht('Failed'), | |||||
ArcanistUnitTestResult::RESULT_UNSOUND => pht('Unsound'), | |||||
ArcanistUnitTestResult::RESULT_SKIP => pht('Skipped'), | |||||
ArcanistUnitTestResult::RESULT_PASS => pht('Passed'), | |||||
); | |||||
$result = idx($names, $result, $result); | |||||
// TODO: Add some color. | |||||
return $result; | |||||
} | |||||
} | } |