Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/view/DifferentialRevisionUpdateHistoryView.php
12256 views
1
<?php
2
3
final class DifferentialRevisionUpdateHistoryView extends AphrontView {
4
5
private $diffs = array();
6
private $selectedVersusDiffID;
7
private $selectedDiffID;
8
private $commitsForLinks = array();
9
private $unitStatus = array();
10
11
public function setDiffs(array $diffs) {
12
assert_instances_of($diffs, 'DifferentialDiff');
13
$this->diffs = $diffs;
14
return $this;
15
}
16
17
public function setSelectedVersusDiffID($id) {
18
$this->selectedVersusDiffID = $id;
19
return $this;
20
}
21
22
public function setSelectedDiffID($id) {
23
$this->selectedDiffID = $id;
24
return $this;
25
}
26
27
public function setCommitsForLinks(array $commits) {
28
assert_instances_of($commits, 'PhabricatorRepositoryCommit');
29
$this->commitsForLinks = $commits;
30
return $this;
31
}
32
33
public function setDiffUnitStatuses(array $unit_status) {
34
$this->unitStatus = $unit_status;
35
return $this;
36
}
37
38
public function render() {
39
$this->requireResource('differential-core-view-css');
40
$this->requireResource('differential-revision-history-css');
41
42
$data = array(
43
array(
44
'name' => pht('Base'),
45
'id' => null,
46
'desc' => pht('Base'),
47
'age' => null,
48
'obj' => null,
49
),
50
);
51
52
$seq = 0;
53
foreach ($this->diffs as $diff) {
54
$data[] = array(
55
'name' => pht('Diff %d', ++$seq),
56
'id' => $diff->getID(),
57
'desc' => $diff->getDescription(),
58
'age' => $diff->getDateCreated(),
59
'obj' => $diff,
60
);
61
}
62
63
$max_id = $diff->getID();
64
$revision_id = $diff->getRevisionID();
65
66
$idx = 0;
67
$rows = array();
68
$disable = false;
69
$radios = array();
70
$last_base = null;
71
$rowc = array();
72
foreach ($data as $row) {
73
74
$diff = $row['obj'];
75
$name = $row['name'];
76
$id = $row['id'];
77
78
$old_class = false;
79
$new_class = false;
80
81
if ($id) {
82
$new_checked = ($this->selectedDiffID == $id);
83
$new = javelin_tag(
84
'input',
85
array(
86
'type' => 'radio',
87
'name' => 'id',
88
'value' => $id,
89
'checked' => $new_checked ? 'checked' : null,
90
'sigil' => 'differential-new-radio',
91
));
92
if ($new_checked) {
93
$new_class = true;
94
$disable = true;
95
}
96
$new = phutil_tag(
97
'div',
98
array(
99
'class' => 'differential-update-history-radio',
100
),
101
$new);
102
} else {
103
$new = null;
104
}
105
106
if ($max_id != $id) {
107
$uniq = celerity_generate_unique_node_id();
108
$old_checked = ($this->selectedVersusDiffID == $id);
109
$old = phutil_tag(
110
'input',
111
array(
112
'type' => 'radio',
113
'name' => 'vs',
114
'value' => $id,
115
'id' => $uniq,
116
'checked' => $old_checked ? 'checked' : null,
117
'disabled' => $disable ? 'disabled' : null,
118
));
119
$radios[] = $uniq;
120
if ($old_checked) {
121
$old_class = true;
122
}
123
$old = phutil_tag(
124
'div',
125
array(
126
'class' => 'differential-update-history-radio',
127
),
128
$old);
129
} else {
130
$old = null;
131
}
132
133
$desc = $row['desc'];
134
135
if ($row['age']) {
136
$age = phabricator_datetime($row['age'], $this->getUser());
137
} else {
138
$age = null;
139
}
140
141
if ($diff) {
142
$lint = $this->newLintStatusView($diff);
143
$unit = $this->newUnitStatusView($diff);
144
$base = $this->renderBaseRevision($diff);
145
} else {
146
$lint = null;
147
$unit = null;
148
$base = null;
149
}
150
151
if ($last_base !== null && $base !== $last_base) {
152
// TODO: Render some kind of notice about rebases.
153
}
154
$last_base = $base;
155
156
if ($revision_id) {
157
$id_link = phutil_tag(
158
'a',
159
array(
160
'href' => '/D'.$revision_id.'?id='.$id,
161
),
162
$id);
163
} else {
164
$id_link = phutil_tag(
165
'a',
166
array(
167
'href' => '/differential/diff/'.$id.'/',
168
),
169
$id);
170
}
171
172
$rows[] = array(
173
$name,
174
$id_link,
175
$base,
176
$desc,
177
$age,
178
$lint,
179
$unit,
180
$old,
181
$new,
182
);
183
184
$classes = array();
185
if ($old_class) {
186
$classes[] = 'differential-update-history-old-now';
187
}
188
if ($new_class) {
189
$classes[] = 'differential-update-history-new-now';
190
}
191
$rowc[] = nonempty(implode(' ', $classes), null);
192
}
193
194
Javelin::initBehavior(
195
'differential-diff-radios',
196
array(
197
'radios' => $radios,
198
));
199
200
$table = id(new AphrontTableView($rows));
201
$table->setHeaders(
202
array(
203
pht('Diff'),
204
pht('ID'),
205
pht('Base'),
206
pht('Description'),
207
pht('Created'),
208
pht('Lint'),
209
pht('Unit'),
210
'',
211
'',
212
));
213
$table->setColumnClasses(
214
array(
215
'pri',
216
'',
217
'',
218
'wide',
219
'date',
220
'center',
221
'center',
222
'center differential-update-history-old',
223
'center differential-update-history-new',
224
));
225
$table->setRowClasses($rowc);
226
$table->setDeviceVisibility(
227
array(
228
true,
229
true,
230
false,
231
true,
232
false,
233
false,
234
false,
235
true,
236
true,
237
));
238
239
$show_diff = phutil_tag(
240
'div',
241
array(
242
'class' => 'differential-update-history-footer',
243
),
244
array(
245
phutil_tag(
246
'button',
247
array(),
248
pht('Show Diff')),
249
));
250
251
$content = phabricator_form(
252
$this->getUser(),
253
array(
254
'method' => 'GET',
255
'action' => '/D'.$revision_id.'#toc',
256
),
257
array(
258
$table,
259
$show_diff,
260
));
261
262
return $content;
263
}
264
265
private function renderBaseRevision(DifferentialDiff $diff) {
266
switch ($diff->getSourceControlSystem()) {
267
case 'git':
268
$base = $diff->getSourceControlBaseRevision();
269
if (strpos($base, '@') === false) {
270
$label = substr($base, 0, 7);
271
} else {
272
// The diff is from git-svn
273
$base = explode('@', $base);
274
$base = last($base);
275
$label = $base;
276
}
277
break;
278
case 'svn':
279
$base = $diff->getSourceControlBaseRevision();
280
$base = explode('@', $base);
281
$base = last($base);
282
$label = $base;
283
break;
284
default:
285
$label = null;
286
break;
287
}
288
$link = null;
289
if ($label) {
290
$commit_for_link = idx(
291
$this->commitsForLinks,
292
$diff->getSourceControlBaseRevision());
293
if ($commit_for_link) {
294
$link = phutil_tag(
295
'a',
296
array('href' => $commit_for_link->getURI()),
297
$label);
298
} else {
299
$link = $label;
300
}
301
}
302
return $link;
303
}
304
305
private function newLintStatusView(DifferentialDiff $diff) {
306
$value = $diff->getLintStatus();
307
$status = DifferentialLintStatus::newStatusFromValue($value);
308
309
$icon = $status->getIconIcon();
310
$color = $status->getIconColor();
311
$name = $status->getName();
312
313
return $this->newDiffStatusIconView($icon, $color, $name);
314
}
315
316
private function newUnitStatusView(DifferentialDiff $diff) {
317
$value = $diff->getUnitStatus();
318
319
// NOTE: We may be overriding the value on the diff with a value from
320
// Harbormaster.
321
$value = idx($this->unitStatus, $diff->getPHID(), $value);
322
323
$status = DifferentialUnitStatus::newStatusFromValue($value);
324
325
$icon = $status->getIconIcon();
326
$color = $status->getIconColor();
327
$name = $status->getName();
328
329
return $this->newDiffStatusIconView($icon, $color, $name);
330
}
331
332
private function newDiffStatusIconView($icon, $color, $name) {
333
return id(new PHUIIconView())
334
->setIcon($icon, $color)
335
->addSigil('has-tooltip')
336
->setMetadata(
337
array(
338
'tip' => $name,
339
));
340
}
341
342
}
343
344