2015-06-21 19:37:55 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HarbormasterUnitPropertyView extends AphrontView {
|
|
|
|
|
2015-06-21 23:37:34 +02:00
|
|
|
private $pathURIMap = array();
|
2015-06-21 19:37:55 +02:00
|
|
|
private $unitMessages = array();
|
2015-06-23 22:34:25 +02:00
|
|
|
private $limit;
|
2016-02-29 15:15:13 +01:00
|
|
|
private $fullResultsURI;
|
2015-06-21 19:37:55 +02:00
|
|
|
|
|
|
|
public function setPathURIMap(array $map) {
|
|
|
|
$this->pathURIMap = $map;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setUnitMessages(array $messages) {
|
|
|
|
assert_instances_of($messages, 'HarbormasterBuildUnitMessage');
|
|
|
|
$this->unitMessages = $messages;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-23 22:34:25 +02:00
|
|
|
public function setLimit($limit) {
|
|
|
|
$this->limit = $limit;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2016-02-29 15:15:13 +01:00
|
|
|
public function setFullResultsURI($full_results_uri) {
|
|
|
|
$this->fullResultsURI = $full_results_uri;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
public function render() {
|
2016-02-29 15:26:01 +01:00
|
|
|
require_celerity_resource('harbormaster-css');
|
|
|
|
|
2015-06-23 22:34:25 +02:00
|
|
|
$messages = $this->unitMessages;
|
|
|
|
$messages = msort($messages, 'getSortKey');
|
|
|
|
|
2016-02-29 15:15:13 +01:00
|
|
|
$limit = $this->limit;
|
|
|
|
|
2015-06-23 22:34:25 +02:00
|
|
|
if ($this->limit) {
|
2016-02-29 15:15:13 +01:00
|
|
|
$display_messages = array_slice($messages, 0, $limit);
|
|
|
|
} else {
|
|
|
|
$display_messages = $messages;
|
2015-06-23 22:34:25 +02:00
|
|
|
}
|
2015-06-21 19:37:55 +02:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
$any_duration = false;
|
2016-02-29 15:15:13 +01:00
|
|
|
foreach ($display_messages as $message) {
|
|
|
|
$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,
|
|
|
|
));
|
2015-06-21 19:37:55 +02:00
|
|
|
|
|
|
|
$duration = $message->getDuration();
|
|
|
|
if ($duration !== null) {
|
|
|
|
$any_duration = true;
|
|
|
|
$duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration)));
|
|
|
|
}
|
|
|
|
|
2016-02-29 15:26:01 +01:00
|
|
|
$name = $message->getUnitMessageDisplayName();
|
|
|
|
$id = $message->getID();
|
2015-06-21 19:37:55 +02:00
|
|
|
|
2016-02-29 15:26:01 +01:00
|
|
|
$name = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => "/harbormaster/unit/view/{$id}/",
|
|
|
|
),
|
|
|
|
$name);
|
|
|
|
|
|
|
|
$details = $message->getUnitMessageDetails();
|
|
|
|
if (strlen($details)) {
|
|
|
|
$name = array(
|
|
|
|
$name,
|
|
|
|
$this->renderUnitTestDetails($details),
|
|
|
|
);
|
2015-06-21 19:37:55 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
$rows[] = array(
|
2016-02-29 15:15:13 +01:00
|
|
|
$result_icon,
|
2015-06-21 19:37:55 +02:00
|
|
|
$duration,
|
|
|
|
$name,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2016-02-29 15:15:13 +01:00
|
|
|
$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);
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
2016-02-29 15:15:13 +01:00
|
|
|
null,
|
2015-06-21 19:37:55 +02:00
|
|
|
pht('Time'),
|
|
|
|
pht('Test'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
2016-02-29 15:26:01 +01:00
|
|
|
'top',
|
|
|
|
'top',
|
|
|
|
'top wide',
|
|
|
|
))
|
|
|
|
->setColumnWidths(
|
|
|
|
array(
|
|
|
|
'32px',
|
|
|
|
'64px',
|
2015-06-21 19:37:55 +02:00
|
|
|
))
|
|
|
|
->setColumnVisibility(
|
|
|
|
array(
|
|
|
|
true,
|
|
|
|
$any_duration,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $table;
|
|
|
|
}
|
|
|
|
|
2016-02-29 15:26:01 +01:00
|
|
|
private function renderUnitTestDetails($full_details) {
|
|
|
|
$details = id(new PhutilUTF8StringTruncator())
|
|
|
|
->setMaximumBytes(2048)
|
|
|
|
->truncateString($full_details);
|
|
|
|
$details = phutil_split_lines($details);
|
|
|
|
|
|
|
|
$limit = 3;
|
|
|
|
if (count($details) > $limit) {
|
|
|
|
$details = array_slice($details, 0, $limit);
|
|
|
|
}
|
|
|
|
|
|
|
|
$details = implode('', $details);
|
|
|
|
|
|
|
|
return phutil_tag(
|
|
|
|
'div',
|
|
|
|
array(
|
|
|
|
'class' => 'PhabricatorMonospaced harbormaster-unit-details',
|
|
|
|
),
|
|
|
|
$details);
|
|
|
|
}
|
|
|
|
|
2015-06-21 19:37:55 +02:00
|
|
|
}
|