Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/view/HarbormasterUnitPropertyView.php
12256 views
1
<?php
2
3
final class HarbormasterUnitPropertyView extends AphrontView {
4
5
private $pathURIMap = array();
6
private $unitMessages = array();
7
private $limit;
8
private $fullResultsURI;
9
private $notice;
10
11
public function setPathURIMap(array $map) {
12
$this->pathURIMap = $map;
13
return $this;
14
}
15
16
public function setUnitMessages(array $messages) {
17
assert_instances_of($messages, 'HarbormasterBuildUnitMessage');
18
$this->unitMessages = $messages;
19
return $this;
20
}
21
22
public function setLimit($limit) {
23
$this->limit = $limit;
24
return $this;
25
}
26
27
public function setFullResultsURI($full_results_uri) {
28
$this->fullResultsURI = $full_results_uri;
29
return $this;
30
}
31
32
public function setNotice($notice) {
33
$this->notice = $notice;
34
return $this;
35
}
36
37
public function render() {
38
$viewer = $this->getViewer();
39
40
$messages = $this->unitMessages;
41
$messages = msort($messages, 'getSortKey');
42
43
$limit = $this->limit;
44
45
if ($this->limit) {
46
$display_messages = array_slice($messages, 0, $limit);
47
} else {
48
$display_messages = $messages;
49
}
50
51
$rows = array();
52
$any_duration = false;
53
foreach ($display_messages as $message) {
54
$status = $message->getResult();
55
56
$icon_icon = HarbormasterUnitStatus::getUnitStatusIcon($status);
57
$icon_color = HarbormasterUnitStatus::getUnitStatusColor($status);
58
$icon_label = HarbormasterUnitStatus::getUnitStatusLabel($status);
59
60
$result_icon = id(new PHUIIconView())
61
->setIcon("{$icon_icon} {$icon_color}")
62
->addSigil('has-tooltip')
63
->setMetadata(
64
array(
65
'tip' => $icon_label,
66
));
67
68
$duration = $message->getDuration();
69
if ($duration !== null) {
70
$any_duration = true;
71
$duration = pht('%s ms', new PhutilNumber((int)(1000 * $duration)));
72
}
73
74
$name = $message->getUnitMessageDisplayName();
75
$uri = $message->getURI();
76
77
if ($uri) {
78
$name = phutil_tag(
79
'a',
80
array(
81
'href' => $uri,
82
),
83
$name);
84
}
85
86
$name = array(
87
$name,
88
$message->newUnitMessageDetailsView($viewer, true),
89
);
90
91
$rows[] = array(
92
$result_icon,
93
$duration,
94
$name,
95
);
96
}
97
98
$full_uri = $this->fullResultsURI;
99
if ($full_uri && (count($messages) > $limit)) {
100
$counts = array();
101
102
$groups = mgroup($messages, 'getResult');
103
foreach ($groups as $status => $group) {
104
$counts[] = HarbormasterUnitStatus::getUnitStatusCountLabel(
105
$status,
106
count($group));
107
}
108
109
$link_text = pht(
110
'View Full Test Results (%s)',
111
implode(" \xC2\xB7 ", $counts));
112
113
$full_link = phutil_tag(
114
'a',
115
array(
116
'href' => $full_uri,
117
),
118
$link_text);
119
120
$link_icon = id(new PHUIIconView())
121
->setIcon('fa-ellipsis-h lightgreytext');
122
123
$rows[] = array($link_icon, null, $full_link);
124
}
125
126
$table = id(new AphrontTableView($rows))
127
->setHeaders(
128
array(
129
null,
130
pht('Time'),
131
pht('Test'),
132
))
133
->setColumnClasses(
134
array(
135
'top center',
136
'top right',
137
'top wide',
138
))
139
->setColumnWidths(
140
array(
141
'32px',
142
'64px',
143
))
144
->setColumnVisibility(
145
array(
146
true,
147
$any_duration,
148
));
149
150
if ($this->notice) {
151
$table->setNotice($this->notice);
152
}
153
154
return $table;
155
}
156
157
}
158
159