3 final class DifferentialChangesetOneUpRenderer
4 extends DifferentialChangesetHTMLRenderer
{
8 public function setSimpleMode($simple_mode) {
9 $this->simpleMode
= $simple_mode;
13 public function getSimpleMode() {
14 return $this->simpleMode
;
17 public function isOneUpRenderer() {
21 protected function getRendererTableClass() {
25 public function getRendererKey() {
29 protected function renderColgroup() {
30 return phutil_tag('colgroup', array(), array(
31 phutil_tag('col', array('class' => 'num')),
32 phutil_tag('col', array('class' => 'num')),
33 phutil_tag('col', array('class' => 'copy')),
34 phutil_tag('col', array('class' => 'unified')),
38 public function renderTextChange(
43 $primitives = $this->buildPrimitives($range_start, $range_len);
44 return $this->renderPrimitives($primitives, $rows);
47 protected function renderPrimitives(array $primitives, $rows) {
48 list($left_prefix, $right_prefix) = $this->getLineIDPrefixes();
50 $is_simple = $this->getSimpleMode();
52 $no_copy = phutil_tag('td', array('class' => 'copy'));
57 $aural_minus = javelin_tag(
65 $aural_plus = javelin_tag(
74 foreach ($primitives as $k => $p) {
81 $is_old = ($type == 'old' ||
$type == 'old-file');
86 if ($p['htype'] === '\\') {
88 } else if (empty($p['oline'])) {
89 $class = 'left old old-full';
93 $aural = $aural_minus;
99 if ($type == 'old-file') {
100 $class = "{$class} differential-old-image";
104 $left_id = $left_prefix.$p['line'];
111 $cells[] = phutil_tag(
115 'class' => $class.' n',
119 $render = $p['render'];
120 if ($aural !== null) {
121 $render = array($aural, $render);
124 $cells[] = phutil_tag(
127 'class' => $class.' n',
130 $cells[] = phutil_tag('td', array('class' => $class), $render);
131 $cells[] = $no_coverage;
134 if ($p['htype'] === '\\') {
136 } else if (empty($p['oline'])) {
137 $class = 'right new new-full';
139 $class = 'right new';
141 $cells[] = phutil_tag(
144 'class' => $class.' n',
146 $aural = $aural_plus;
150 $left_id = $left_prefix.$p['oline'];
155 $oline = $p['oline'];
157 $cells[] = phutil_tag(
167 if ($type == 'new-file') {
168 $class = "{$class} differential-new-image";
172 $right_id = $right_prefix.$p['line'];
179 $cells[] = phutil_tag(
183 'class' => $class.' n',
187 $render = $p['render'];
188 if ($aural !== null) {
189 $render = array($aural, $render);
194 $cells[] = phutil_tag(
198 'data-copy-mode' => 'copy-unified',
202 $cells[] = $no_coverage;
205 // In simple mode, only render the text. This is used to render
206 // "Edit Suggestions" in inline comments.
208 $cells = array($cells[3]);
211 $out[] = phutil_tag('tr', array(), $cells);
215 $inline = $this->buildInlineComment(
218 $out[] = $this->getRowScaffoldForInline($inline);
227 'class' => 'show-more',
228 'colspan' => $column_width,
230 pht('Context not available.')));
236 $links = $this->renderShowContextLinks($top, $len, $rows);
238 $out[] = javelin_tag(
241 'sigil' => 'context-target',
246 'class' => 'show-more',
247 'colspan' => $column_width,
252 $out[] = hsprintf('<tr><th /><th /><td>%s</td></tr>', $type);
261 $result = $this->newSimpleTable($out);
263 $result = $this->wrapChangeInTable(phutil_implode_html('', $out));
270 public function renderDocumentEngineBlocks(
271 PhabricatorDocumentEngineBlocks
$block_list,
273 $new_changeset_key) {
275 $engine = $this->getDocumentEngine();
276 $layout = $block_list->newTwoUpLayout();
278 $old_comments = $this->getOldComments();
279 $new_comments = $this->getNewComments();
281 $unchanged = array();
282 foreach ($layout as $key => $row) {
283 list($old, $new) = $row;
293 if ($old->getDifferenceType() !== null) {
297 if ($new->getDifferenceType() !== null) {
301 $unchanged[$key] = true;
305 $count = count($layout);
306 for ($ii = 0; $ii < $count;) {
309 for ($jj = $ii; $jj < $count; $jj++
) {
310 list($old, $new) = $layout[$jj];
312 if (empty($unchanged[$jj])) {
317 'type' => 'unchanged',
323 for ($jj = $ii; $jj < $count; $jj++
) {
324 list($old, $new) = $layout[$jj];
326 if (!empty($unchanged[$jj])) {
336 for ($jj = $ii; $jj < $count; $jj++
) {
337 list($old, $new) = $layout[$jj];
339 if (!empty($unchanged[$jj])) {
350 // We always expect to consume at least one row when iterating through
351 // the loop and make progress. If we don't, bail out to avoid spinning
353 if ($ii === $start) {
356 'Failed to make progress during 1up diff layout.'));
362 $refs = $block_list->getDocumentRefs();
364 list($old_ref, $new_ref) = $refs;
368 foreach ($rows as $row) {
369 $row_type = $row['type'];
370 $layout_key = $row['layoutKey'];
371 $row_layout = $layout[$layout_key];
372 list($old, $new) = $row_layout;
375 $old_key = $old->getBlockKey();
381 $new_key = $new->getBlockKey();
387 $cell_classes = array();
389 if ($row_type === 'unchanged') {
390 $cell_content = $engine->newBlockContentView(
393 } else if ($old && $new) {
394 $block_diff = $engine->newBlockDiffViews(
400 // TODO: We're currently double-rendering this: once when building
401 // the old row, and once when building the new one. In both cases,
402 // we throw away the other half of the output. We could cache this
403 // to improve performance.
405 if ($row_type === 'old') {
406 $cell_content = $block_diff->getOldContent();
407 $cell_classes = $block_diff->getOldClasses();
409 $cell_content = $block_diff->getNewContent();
410 $cell_classes = $block_diff->getNewClasses();
412 } else if ($row_type === 'old') {
413 if (!$old_ref ||
!$old) {
417 $cell_content = $engine->newBlockContentView(
421 $cell_classes[] = 'old';
422 $cell_classes[] = 'old-full';
425 } else if ($row_type === 'new') {
426 if (!$new_ref ||
!$new) {
430 $cell_content = $engine->newBlockContentView(
434 $cell_classes[] = 'new';
435 $cell_classes[] = 'new-full';
440 if ($old_key === null) {
443 $old_id = "C{$old_changeset_key}OL{$old_key}";
446 if ($new_key === null) {
449 $new_id = "C{$new_changeset_key}NL{$new_key}";
452 $cells[] = phutil_tag(
456 'data-n' => $old_key,
460 $cells[] = phutil_tag(
464 'data-n' => $new_key,
468 $cells[] = phutil_tag(
474 $cell_classes[] = 'diff-flush';
475 $cell_classes = implode(' ', $cell_classes);
477 $cells[] = phutil_tag(
480 'class' => $cell_classes,
481 'data-copy-mode' => 'copy-unified',
485 $view[] = phutil_tag(
490 if ($old_key !== null) {
491 $old_inlines = idx($old_comments, $old_key, array());
492 foreach ($old_inlines as $inline) {
493 $inline = $this->buildInlineComment(
496 $view[] = $this->getRowScaffoldForInline($inline);
500 if ($new_key !== null) {
501 $new_inlines = idx($new_comments, $new_key, array());
502 foreach ($new_inlines as $inline) {
503 $inline = $this->buildInlineComment(
506 $view[] = $this->getRowScaffoldForInline($inline);
511 $output = $this->wrapChangeInTable($view);
512 return $this->renderChangesetTable($output);
515 public function getRowScaffoldForInline(PHUIDiffInlineCommentView
$view) {
516 return id(new PHUIDiffOneUpInlineCommentRowScaffold())
517 ->addInlineView($view);
521 private function newSimpleTable($content) {
525 'class' => 'diff-1up-simple-table',