Separate the inline comment summary element into a separate view
Summary: - Affects the "Inline Comments" summary table which appears in comments that have attached inlines in the discussion threads in Differential. - Prepares for inclusion in Diffusion. - No application changes (minor CSS), just factors code better. - Simplify/separate CSS. Test Plan: Looked at on-diff and off-diff comment summaries in Differential, display looked correct. Reviewers: davidreuss, nh, btrahan Reviewed By: davidreuss CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1928
This commit is contained in:
@@ -0,0 +1,147 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright 2012 Facebook, Inc.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
final class PhabricatorInlineSummaryView extends AphrontView {
|
||||
|
||||
private $groups = array();
|
||||
|
||||
public function addCommentGroup($name, array $items) {
|
||||
$this->groups[$name] = $items;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public static function renderCommentContent(
|
||||
PhabricatorInlineCommentInterface $inline,
|
||||
PhutilMarkupEngine $engine) {
|
||||
|
||||
$inline_content = $inline->getContent();
|
||||
if (strlen($inline_content)) {
|
||||
$inline_cache = $inline->getCache();
|
||||
if ($inline_cache) {
|
||||
$inline_content = $inline_cache;
|
||||
} else {
|
||||
$inline_content = $engine->markupText($inline_content);
|
||||
if ($inline->getID()) {
|
||||
$inline->setCache($inline_content);
|
||||
$unguarded = AphrontWriteGuard::beginScopedUnguardedWrites();
|
||||
$inline->save();
|
||||
unset($unguarded);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $inline_content;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
require_celerity_resource('inline-comment-summary-css');
|
||||
return $this->renderHeader().$this->renderTable();
|
||||
}
|
||||
|
||||
private function renderHeader() {
|
||||
return phutil_render_tag(
|
||||
'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;
|
||||
}
|
||||
}
|
||||
|
||||
$cols = $has_where ? 3 : 2;
|
||||
|
||||
$rows[] =
|
||||
'<tr>'.
|
||||
'<th colspan="'.$cols.'">'.
|
||||
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');
|
||||
|
||||
$rows[] =
|
||||
'<tr>'.
|
||||
'<td class="inline-line-number">'.$lines.'</td>'.
|
||||
($has_where ?
|
||||
'<td class="inline-which-diff">'.
|
||||
phutil_escape_html($where).
|
||||
'</td>'
|
||||
: null).
|
||||
'<td class="inline-summary-content">'.
|
||||
'<div class="phabricator-remarkup">'.
|
||||
$item['content'].
|
||||
'</div>'.
|
||||
'</td>'.
|
||||
'</tr>';
|
||||
}
|
||||
}
|
||||
|
||||
return phutil_render_tag(
|
||||
'table',
|
||||
array(
|
||||
'class' => 'phabricator-inline-summary-table',
|
||||
),
|
||||
implode("\n", $rows));
|
||||
}
|
||||
|
||||
}
|
||||
17
src/infrastructure/diff/view/inline/__init__.php
Normal file
17
src/infrastructure/diff/view/inline/__init__.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
/**
|
||||
* This file is automatically generated. Lint this module to rebuild it.
|
||||
* @generated
|
||||
*/
|
||||
|
||||
|
||||
|
||||
phutil_require_module('phabricator', 'aphront/writeguard');
|
||||
phutil_require_module('phabricator', 'infrastructure/celerity/api');
|
||||
phutil_require_module('phabricator', 'view/base');
|
||||
|
||||
phutil_require_module('phutil', 'markup');
|
||||
phutil_require_module('phutil', 'utils');
|
||||
|
||||
|
||||
phutil_require_source('PhabricatorInlineSummaryView.php');
|
||||
Reference in New Issue
Block a user