Generate file attachment transactions for explicit Remarkup attachments on common...
[phabricator.git] / src / applications / differential / view / DifferentialRevisionUpdateHistoryView.php
blob2e074a2f7e7c218df9e8ae398eca09a77d013c35
1 <?php
3 final class DifferentialRevisionUpdateHistoryView extends AphrontView {
5 private $diffs = array();
6 private $selectedVersusDiffID;
7 private $selectedDiffID;
8 private $commitsForLinks = array();
9 private $unitStatus = array();
11 public function setDiffs(array $diffs) {
12 assert_instances_of($diffs, 'DifferentialDiff');
13 $this->diffs = $diffs;
14 return $this;
17 public function setSelectedVersusDiffID($id) {
18 $this->selectedVersusDiffID = $id;
19 return $this;
22 public function setSelectedDiffID($id) {
23 $this->selectedDiffID = $id;
24 return $this;
27 public function setCommitsForLinks(array $commits) {
28 assert_instances_of($commits, 'PhabricatorRepositoryCommit');
29 $this->commitsForLinks = $commits;
30 return $this;
33 public function setDiffUnitStatuses(array $unit_status) {
34 $this->unitStatus = $unit_status;
35 return $this;
38 public function render() {
39 $this->requireResource('differential-core-view-css');
40 $this->requireResource('differential-revision-history-css');
42 $data = array(
43 array(
44 'name' => pht('Base'),
45 'id' => null,
46 'desc' => pht('Base'),
47 'age' => null,
48 'obj' => null,
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,
63 $max_id = $diff->getID();
64 $revision_id = $diff->getRevisionID();
66 $idx = 0;
67 $rows = array();
68 $disable = false;
69 $radios = array();
70 $last_base = null;
71 $rowc = array();
72 foreach ($data as $row) {
74 $diff = $row['obj'];
75 $name = $row['name'];
76 $id = $row['id'];
78 $old_class = false;
79 $new_class = false;
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;
96 $new = phutil_tag(
97 'div',
98 array(
99 'class' => 'differential-update-history-radio',
101 $new);
102 } else {
103 $new = null;
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,
119 $radios[] = $uniq;
120 if ($old_checked) {
121 $old_class = true;
123 $old = phutil_tag(
124 'div',
125 array(
126 'class' => 'differential-update-history-radio',
128 $old);
129 } else {
130 $old = null;
133 $desc = $row['desc'];
135 if ($row['age']) {
136 $age = phabricator_datetime($row['age'], $this->getUser());
137 } else {
138 $age = null;
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;
151 if ($last_base !== null && $base !== $last_base) {
152 // TODO: Render some kind of notice about rebases.
154 $last_base = $base;
156 if ($revision_id) {
157 $id_link = phutil_tag(
158 'a',
159 array(
160 'href' => '/D'.$revision_id.'?id='.$id,
162 $id);
163 } else {
164 $id_link = phutil_tag(
165 'a',
166 array(
167 'href' => '/differential/diff/'.$id.'/',
169 $id);
172 $rows[] = array(
173 $name,
174 $id_link,
175 $base,
176 $desc,
177 $age,
178 $lint,
179 $unit,
180 $old,
181 $new,
184 $classes = array();
185 if ($old_class) {
186 $classes[] = 'differential-update-history-old-now';
188 if ($new_class) {
189 $classes[] = 'differential-update-history-new-now';
191 $rowc[] = nonempty(implode(' ', $classes), null);
194 Javelin::initBehavior(
195 'differential-diff-radios',
196 array(
197 'radios' => $radios,
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'),
213 $table->setColumnClasses(
214 array(
215 'pri',
218 'wide',
219 'date',
220 'center',
221 'center',
222 'center differential-update-history-old',
223 'center differential-update-history-new',
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,
239 $show_diff = phutil_tag(
240 'div',
241 array(
242 'class' => 'differential-update-history-footer',
244 array(
245 phutil_tag(
246 'button',
247 array(),
248 pht('Show Diff')),
251 $content = phabricator_form(
252 $this->getUser(),
253 array(
254 'action' => '/D'.$revision_id.'#toc',
256 array(
257 $table,
258 $show_diff,
261 return $content;
264 private function renderBaseRevision(DifferentialDiff $diff) {
265 switch ($diff->getSourceControlSystem()) {
266 case 'git':
267 $base = $diff->getSourceControlBaseRevision();
268 if (strpos($base, '@') === false) {
269 $label = substr($base, 0, 7);
270 } else {
271 // The diff is from git-svn
272 $base = explode('@', $base);
273 $base = last($base);
274 $label = $base;
276 break;
277 case 'svn':
278 $base = $diff->getSourceControlBaseRevision();
279 $base = explode('@', $base);
280 $base = last($base);
281 $label = $base;
282 break;
283 default:
284 $label = null;
285 break;
287 $link = null;
288 if ($label) {
289 $commit_for_link = idx(
290 $this->commitsForLinks,
291 $diff->getSourceControlBaseRevision());
292 if ($commit_for_link) {
293 $link = phutil_tag(
294 'a',
295 array('href' => $commit_for_link->getURI()),
296 $label);
297 } else {
298 $link = $label;
301 return $link;
304 private function newLintStatusView(DifferentialDiff $diff) {
305 $value = $diff->getLintStatus();
306 $status = DifferentialLintStatus::newStatusFromValue($value);
308 $icon = $status->getIconIcon();
309 $color = $status->getIconColor();
310 $name = $status->getName();
312 return $this->newDiffStatusIconView($icon, $color, $name);
315 private function newUnitStatusView(DifferentialDiff $diff) {
316 $value = $diff->getUnitStatus();
318 // NOTE: We may be overriding the value on the diff with a value from
319 // Harbormaster.
320 $value = idx($this->unitStatus, $diff->getPHID(), $value);
322 $status = DifferentialUnitStatus::newStatusFromValue($value);
324 $icon = $status->getIconIcon();
325 $color = $status->getIconColor();
326 $name = $status->getName();
328 return $this->newDiffStatusIconView($icon, $color, $name);
331 private function newDiffStatusIconView($icon, $color, $name) {
332 return id(new PHUIIconView())
333 ->setIcon($icon, $color)
334 ->addSigil('has-tooltip')
335 ->setMetadata(
336 array(
337 'tip' => $name,