2012-03-19 19:45:16 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
final class PhabricatorInlineSummaryView extends AphrontView {
|
|
|
|
|
|
|
|
|
|
private $groups = array();
|
|
|
|
|
|
|
|
|
|
public function addCommentGroup($name, array $items) {
|
2012-04-07 00:09:15 -07:00
|
|
|
if (!isset($this->groups[$name])) {
|
|
|
|
|
$this->groups[$name] = $items;
|
|
|
|
|
} else {
|
|
|
|
|
$this->groups[$name] = array_merge($this->groups[$name], $items);
|
|
|
|
|
}
|
2012-03-19 19:45:16 -07:00
|
|
|
return $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function render() {
|
|
|
|
|
require_celerity_resource('inline-comment-summary-css');
|
|
|
|
|
return $this->renderHeader().$this->renderTable();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function renderHeader() {
|
2013-01-17 18:57:09 -08:00
|
|
|
return phutil_tag(
|
2012-03-19 19:45:16 -07:00
|
|
|
'div',
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'phabricator-inline-summary',
|
|
|
|
|
),
|
|
|
|
|
'Inline Comments');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function renderTable() {
|
|
|
|
|
$rows = array();
|
|
|
|
|
foreach ($this->groups as $group => $items) {
|
|
|
|
|
|
|
|
|
|
$has_where = false;
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
if (!empty($item['where'])) {
|
|
|
|
|
$has_where = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$rows[] =
|
|
|
|
|
'<tr>'.
|
2012-06-18 18:05:06 -07:00
|
|
|
'<th colspan="3">'.
|
2012-03-19 19:45:16 -07:00
|
|
|
phutil_escape_html($group).
|
|
|
|
|
'</th>'.
|
|
|
|
|
'</tr>';
|
|
|
|
|
|
|
|
|
|
foreach ($items as $item) {
|
|
|
|
|
|
|
|
|
|
$items = isort($items, 'line');
|
|
|
|
|
|
|
|
|
|
$line = $item['line'];
|
|
|
|
|
$length = $item['length'];
|
|
|
|
|
if ($length) {
|
|
|
|
|
$lines = $line."\xE2\x80\x93".($line + $length);
|
|
|
|
|
} else {
|
|
|
|
|
$lines = $line;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isset($item['href'])) {
|
|
|
|
|
$href = $item['href'];
|
|
|
|
|
$target = '_blank';
|
|
|
|
|
$tail = " \xE2\x86\x97";
|
|
|
|
|
} else {
|
|
|
|
|
$href = '#inline-'.$item['id'];
|
|
|
|
|
$target = null;
|
|
|
|
|
$tail = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$lines = phutil_escape_html($lines);
|
|
|
|
|
if ($href) {
|
|
|
|
|
$lines = phutil_render_tag(
|
|
|
|
|
'a',
|
|
|
|
|
array(
|
|
|
|
|
'href' => $href,
|
|
|
|
|
'target' => $target,
|
|
|
|
|
'class' => 'num',
|
|
|
|
|
),
|
|
|
|
|
$lines.$tail);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$where = idx($item, 'where');
|
|
|
|
|
|
2012-06-18 18:05:06 -07:00
|
|
|
$colspan = ($has_where ? '' : ' colspan="2"');
|
2012-03-19 19:45:16 -07:00
|
|
|
$rows[] =
|
|
|
|
|
'<tr>'.
|
|
|
|
|
'<td class="inline-line-number">'.$lines.'</td>'.
|
|
|
|
|
($has_where ?
|
|
|
|
|
'<td class="inline-which-diff">'.
|
|
|
|
|
phutil_escape_html($where).
|
|
|
|
|
'</td>'
|
|
|
|
|
: null).
|
2012-06-18 18:05:06 -07:00
|
|
|
'<td class="inline-summary-content"'.$colspan.'>'.
|
2012-03-19 19:45:16 -07:00
|
|
|
'<div class="phabricator-remarkup">'.
|
|
|
|
|
$item['content'].
|
|
|
|
|
'</div>'.
|
|
|
|
|
'</td>'.
|
|
|
|
|
'</tr>';
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-18 00:32:58 -08:00
|
|
|
return phutil_tag(
|
2012-03-19 19:45:16 -07:00
|
|
|
'table',
|
|
|
|
|
array(
|
|
|
|
|
'class' => 'phabricator-inline-summary-table',
|
|
|
|
|
),
|
2013-01-18 00:32:58 -08:00
|
|
|
new PhutilSafeHTML(implode("\n", $rows)));
|
2012-03-19 19:45:16 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|