Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/view/DifferentialChangesetListView.php
12256 views
1
<?php
2
3
final class DifferentialChangesetListView extends AphrontView {
4
5
private $changesets = array();
6
private $visibleChangesets = array();
7
private $references = array();
8
private $inlineURI;
9
private $renderURI = '/differential/changeset/';
10
private $background;
11
private $header;
12
private $isStandalone;
13
14
private $standaloneURI;
15
private $leftRawFileURI;
16
private $rightRawFileURI;
17
private $inlineListURI;
18
19
private $symbolIndexes = array();
20
private $repository;
21
private $branch;
22
private $diff;
23
private $vsMap = array();
24
25
private $title;
26
private $parser;
27
private $formationView;
28
29
public function setParser(DifferentialChangesetParser $parser) {
30
$this->parser = $parser;
31
return $this;
32
}
33
34
public function getParser() {
35
return $this->parser;
36
}
37
38
public function setTitle($title) {
39
$this->title = $title;
40
return $this;
41
}
42
private function getTitle() {
43
return $this->title;
44
}
45
46
public function setBranch($branch) {
47
$this->branch = $branch;
48
return $this;
49
}
50
private function getBranch() {
51
return $this->branch;
52
}
53
54
public function setChangesets($changesets) {
55
$this->changesets = $changesets;
56
return $this;
57
}
58
59
public function setVisibleChangesets($visible_changesets) {
60
$this->visibleChangesets = $visible_changesets;
61
return $this;
62
}
63
64
public function setInlineCommentControllerURI($uri) {
65
$this->inlineURI = $uri;
66
return $this;
67
}
68
69
public function setInlineListURI($uri) {
70
$this->inlineListURI = $uri;
71
return $this;
72
}
73
74
public function getInlineListURI() {
75
return $this->inlineListURI;
76
}
77
78
public function setRepository(PhabricatorRepository $repository) {
79
$this->repository = $repository;
80
return $this;
81
}
82
83
public function getRepository() {
84
return $this->repository;
85
}
86
87
public function setDiff(DifferentialDiff $diff) {
88
$this->diff = $diff;
89
return $this;
90
}
91
92
public function getDiff() {
93
return $this->diff;
94
}
95
96
public function setRenderingReferences(array $references) {
97
$this->references = $references;
98
return $this;
99
}
100
101
public function setSymbolIndexes(array $indexes) {
102
$this->symbolIndexes = $indexes;
103
return $this;
104
}
105
106
public function setRenderURI($render_uri) {
107
$this->renderURI = $render_uri;
108
return $this;
109
}
110
111
public function setVsMap(array $vs_map) {
112
$this->vsMap = $vs_map;
113
return $this;
114
}
115
116
public function getVsMap() {
117
return $this->vsMap;
118
}
119
120
public function setStandaloneURI($uri) {
121
$this->standaloneURI = $uri;
122
return $this;
123
}
124
125
public function setRawFileURIs($l, $r) {
126
$this->leftRawFileURI = $l;
127
$this->rightRawFileURI = $r;
128
return $this;
129
}
130
131
public function setIsStandalone($is_standalone) {
132
$this->isStandalone = $is_standalone;
133
return $this;
134
}
135
136
public function getIsStandalone() {
137
return $this->isStandalone;
138
}
139
140
public function setBackground($background) {
141
$this->background = $background;
142
return $this;
143
}
144
145
public function setHeader($header) {
146
$this->header = $header;
147
return $this;
148
}
149
150
public function setFormationView(PHUIFormationView $formation_view) {
151
$this->formationView = $formation_view;
152
return $this;
153
}
154
155
public function getFormationView() {
156
return $this->formationView;
157
}
158
159
public function render() {
160
$viewer = $this->getViewer();
161
162
$this->requireResource('differential-changeset-view-css');
163
164
$changesets = $this->changesets;
165
166
$repository = $this->getRepository();
167
$diff = $this->getDiff();
168
169
$output = array();
170
$ids = array();
171
foreach ($changesets as $key => $changeset) {
172
173
$file = $changeset->getFilename();
174
$ref = $this->references[$key];
175
176
$detail = id(new DifferentialChangesetDetailView())
177
->setViewer($viewer);
178
179
if ($repository) {
180
$detail->setRepository($repository);
181
}
182
183
if ($diff) {
184
$detail->setDiff($diff);
185
}
186
187
$uniq_id = 'diff-'.$changeset->getAnchorName();
188
$detail->setID($uniq_id);
189
190
$view_options = $this->renderViewOptionsDropdown(
191
$detail,
192
$ref,
193
$changeset);
194
195
$detail->setChangeset($changeset);
196
$detail->addButton($view_options);
197
$detail->setSymbolIndex(idx($this->symbolIndexes, $key));
198
$detail->setVsChangesetID(idx($this->vsMap, $changeset->getID()));
199
$detail->setEditable(true);
200
$detail->setRenderingRef($ref);
201
$detail->setBranch($this->getBranch());
202
203
$detail->setRenderURI($this->renderURI);
204
205
$parser = $this->getParser();
206
if ($parser) {
207
$response = $parser->newChangesetResponse();
208
$detail->setChangesetResponse($response);
209
} else {
210
$detail->setAutoload(isset($this->visibleChangesets[$key]));
211
if (isset($this->visibleChangesets[$key])) {
212
$load = pht('Loading...');
213
} else {
214
$load = javelin_tag(
215
'a',
216
array(
217
'class' => 'button button-grey',
218
'href' => '#'.$uniq_id,
219
'sigil' => 'differential-load',
220
'meta' => array(
221
'id' => $detail->getID(),
222
'kill' => true,
223
),
224
'mustcapture' => true,
225
),
226
pht('Load File'));
227
}
228
$detail->appendChild(
229
phutil_tag(
230
'div',
231
array(
232
'id' => $uniq_id,
233
),
234
phutil_tag(
235
'div',
236
array('class' => 'differential-loading'),
237
$load)));
238
}
239
240
$output[] = $detail->render();
241
$ids[] = $detail->getID();
242
}
243
244
$this->requireResource('aphront-tooltip-css');
245
246
$formation_id = null;
247
$formation_view = $this->getFormationView();
248
if ($formation_view) {
249
$formation_id = $formation_view->getID();
250
}
251
252
$this->initBehavior(
253
'differential-populate',
254
array(
255
'changesetViewIDs' => $ids,
256
'formationViewID' => $formation_id,
257
'inlineURI' => $this->inlineURI,
258
'inlineListURI' => $this->inlineListURI,
259
'isStandalone' => $this->getIsStandalone(),
260
'pht' => array(
261
'Open in Editor' => pht('Open in Editor'),
262
'Show All Context' => pht('Show All Context'),
263
'All Context Shown' => pht('All Context Shown'),
264
'Expand File' => pht('Expand File'),
265
'Hide Changeset' => pht('Hide Changeset'),
266
'Show Path in Repository' => pht('Show Path in Repository'),
267
'Show Directory in Repository' => pht('Show Directory in Repository'),
268
'View Standalone' => pht('View Standalone'),
269
'Show Raw File (Left)' => pht('Show Raw File (Left)'),
270
'Show Raw File (Right)' => pht('Show Raw File (Right)'),
271
'Configure Editor' => pht('Configure Editor'),
272
'Load Changes' => pht('Load Changes'),
273
'View Side-by-Side Diff' => pht('View Side-by-Side Diff'),
274
'View Unified Diff' => pht('View Unified Diff'),
275
'Change Text Encoding...' => pht('Change Text Encoding...'),
276
'Highlight As...' => pht('Highlight As...'),
277
'View As Document Type...' => pht('View As Document Type...'),
278
279
'Loading...' => pht('Loading...'),
280
281
'Editing Comment' => pht('Editing Comment'),
282
283
'Jump to next change.' => pht('Jump to next change.'),
284
'Jump to previous change.' => pht('Jump to previous change.'),
285
'Jump to next file.' => pht('Jump to next file.'),
286
'Jump to previous file.' => pht('Jump to previous file.'),
287
'Jump to next inline comment.' => pht('Jump to next inline comment.'),
288
'Jump to previous inline comment.' =>
289
pht('Jump to previous inline comment.'),
290
'Jump to the table of contents.' =>
291
pht('Jump to the table of contents.'),
292
293
'Edit selected inline comment.' =>
294
pht('Edit selected inline comment.'),
295
'You must select a comment to edit.' =>
296
pht('You must select a comment to edit.'),
297
298
'Reply to selected inline comment or change.' =>
299
pht('Reply to selected inline comment or change.'),
300
'You must select a comment or change to reply to.' =>
301
pht('You must select a comment or change to reply to.'),
302
'Reply and quote selected inline comment.' =>
303
pht('Reply and quote selected inline comment.'),
304
305
'Mark or unmark selected inline comment as done.' =>
306
pht('Mark or unmark selected inline comment as done.'),
307
'You must select a comment to mark done.' =>
308
pht('You must select a comment to mark done.'),
309
310
'Collapse or expand inline comment.' =>
311
pht('Collapse or expand inline comment.'),
312
'You must select a comment to hide.' =>
313
pht('You must select a comment to hide.'),
314
315
'Jump to next inline comment, including collapsed comments.' =>
316
pht('Jump to next inline comment, including collapsed comments.'),
317
'Jump to previous inline comment, including collapsed comments.' =>
318
pht('Jump to previous inline comment, including collapsed comments.'),
319
320
'Hide or show the current changeset.' =>
321
pht('Hide or show the current changeset.'),
322
'You must select a file to hide or show.' =>
323
pht('You must select a file to hide or show.'),
324
325
'Unsaved' => pht('Unsaved'),
326
'Unsubmitted' => pht('Unsubmitted'),
327
'Comments' => pht('Comments'),
328
329
'Hide "Done" Inlines' => pht('Hide "Done" Inlines'),
330
'Hide Collapsed Inlines' => pht('Hide Collapsed Inlines'),
331
'Hide Older Inlines' => pht('Hide Older Inlines'),
332
'Hide All Inlines' => pht('Hide All Inlines'),
333
'Show All Inlines' => pht('Show All Inlines'),
334
335
'List Inline Comments' => pht('List Inline Comments'),
336
'Display Options' => pht('Display Options'),
337
338
'Hide or show all inline comments.' =>
339
pht('Hide or show all inline comments.'),
340
341
'Finish editing inline comments before changing display modes.' =>
342
pht('Finish editing inline comments before changing display modes.'),
343
344
'Open file in external editor.' =>
345
pht('Open file in external editor.'),
346
347
'You must select a file to edit.' =>
348
pht('You must select a file to edit.'),
349
350
'You must select a file to open.' =>
351
pht('You must select a file to open.'),
352
353
'No external editor is configured.' =>
354
pht('No external editor is configured.'),
355
356
'Hide or show the paths panel.' =>
357
pht('Hide or show the paths panel.'),
358
359
'Show path in repository.' =>
360
pht('Show path in repository.'),
361
'Show directory in repository.' =>
362
pht('Show directory in repository.'),
363
364
'Jump to the comment area.' =>
365
pht('Jump to the comment area.'),
366
367
'Show Changeset' => pht('Show Changeset'),
368
369
'You must select source text to create a new inline comment.' =>
370
pht('You must select source text to create a new inline comment.'),
371
372
'New Inline Comment' => pht('New Inline Comment'),
373
374
'Add new inline comment on selected source text.' =>
375
pht('Add new inline comment on selected source text.'),
376
377
'Suggest Edit' => pht('Suggest Edit'),
378
'Discard Edit' => pht('Discard Edit'),
379
),
380
));
381
382
if ($this->header) {
383
$header = $this->header;
384
} else {
385
$header = id(new PHUIHeaderView())
386
->setHeader($this->getTitle());
387
}
388
389
$content = phutil_tag(
390
'div',
391
array(
392
'class' => 'differential-review-stage',
393
'id' => 'differential-review-stage',
394
),
395
$output);
396
397
$object_box = id(new PHUIObjectBoxView())
398
->setHeader($header)
399
->setBackground($this->background)
400
->setCollapsed(true)
401
->appendChild($content);
402
403
return $object_box;
404
}
405
406
private function renderViewOptionsDropdown(
407
DifferentialChangesetDetailView $detail,
408
$ref,
409
DifferentialChangeset $changeset) {
410
$viewer = $this->getViewer();
411
412
$meta = array();
413
414
$qparams = array(
415
'ref' => $ref,
416
);
417
418
if ($this->standaloneURI) {
419
$uri = new PhutilURI($this->standaloneURI);
420
$uri = $this->appendDefaultQueryParams($uri, $qparams);
421
$meta['standaloneURI'] = (string)$uri;
422
}
423
424
$change = $changeset->getChangeType();
425
426
if ($this->leftRawFileURI) {
427
if ($change != DifferentialChangeType::TYPE_ADD) {
428
$uri = new PhutilURI($this->leftRawFileURI);
429
$uri = $this->appendDefaultQueryParams($uri, $qparams);
430
$meta['leftURI'] = (string)$uri;
431
}
432
}
433
434
if ($this->rightRawFileURI) {
435
if ($change != DifferentialChangeType::TYPE_DELETE &&
436
$change != DifferentialChangeType::TYPE_MULTICOPY) {
437
$uri = new PhutilURI($this->rightRawFileURI);
438
$uri = $this->appendDefaultQueryParams($uri, $qparams);
439
$meta['rightURI'] = (string)$uri;
440
}
441
}
442
443
$meta['containerID'] = $detail->getID();
444
445
return id(new PHUIButtonView())
446
->setTag('a')
447
->setText(pht('View Options'))
448
->setIcon('fa-bars')
449
->setColor(PHUIButtonView::GREY)
450
->setHref(idx($meta, 'detailURI', '#'))
451
->setMetadata($meta)
452
->addSigil('differential-view-options');
453
}
454
455
private function appendDefaultQueryParams(PhutilURI $uri, array $params) {
456
// Add these default query parameters to the query string if they do not
457
// already exist.
458
459
$have = array();
460
foreach ($uri->getQueryParamsAsPairList() as $pair) {
461
list($key, $value) = $pair;
462
$have[$key] = true;
463
}
464
465
foreach ($params as $key => $value) {
466
if (!isset($have[$key])) {
467
$uri->appendQueryParam($key, $value);
468
}
469
}
470
471
return $uri;
472
}
473
474
}
475
476