1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-30 10:42:41 +01:00

Add inline comments to the web view of Diffusion / Audit

Summary: Depends on D1928. Uses the new UI element to display inlines in Diffusion.

Test Plan: Looked at a commit with inline comments, saw them in the summaries.

Reviewers: davidreuss, nh, btrahan

Reviewed By: davidreuss

CC: aran, epriestley

Maniphest Tasks: T904

Differential Revision: https://secure.phabricator.com/D1929
This commit is contained in:
epriestley 2012-03-19 19:56:06 -07:00
parent 0a4cbdff5e
commit e42c29f4ec
8 changed files with 163 additions and 4 deletions

View file

@ -325,6 +325,7 @@ phutil_register_library_map(array(
'DiffusionPathChangeQuery' => 'applications/diffusion/query/pathchange/base',
'DiffusionPathCompleteController' => 'applications/diffusion/controller/pathcomplete',
'DiffusionPathIDQuery' => 'applications/diffusion/query/pathid/base',
'DiffusionPathQuery' => 'applications/diffusion/query/path',
'DiffusionPathQueryTestCase' => 'applications/diffusion/query/pathid/base/__tests__',
'DiffusionPathValidateController' => 'applications/diffusion/controller/pathvalidate',
'DiffusionQuery' => 'applications/diffusion/query/base',

View file

@ -350,9 +350,25 @@ final class DiffusionCommitController extends DiffusionController {
'targetPHID = %s ORDER BY dateCreated ASC',
$commit->getPHID());
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
'commitPHID = %s AND auditCommentID IS NOT NULL',
$commit->getPHID());
$path_ids = mpull($inlines, 'getPathID');
$path_map = array();
if ($path_ids) {
$path_map = id(new DiffusionPathQuery())
->withPathIDs($path_ids)
->execute();
$path_map = ipull($path_map, 'path', 'id');
}
$view = new DiffusionCommentListView();
$view->setUser($user);
$view->setComments($comments);
$view->setInlineComments($inlines);
$view->setPathMap($path_map);
$phids = $view->getRequiredHandlePHIDs();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();

View file

@ -11,12 +11,14 @@ phutil_require_module('phabricator', 'applications/audit/constants/commitstatus'
phutil_require_module('phabricator', 'applications/audit/editor/comment');
phutil_require_module('phabricator', 'applications/audit/query/audit');
phutil_require_module('phabricator', 'applications/audit/storage/auditcomment');
phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment');
phutil_require_module('phabricator', 'applications/audit/view/list');
phutil_require_module('phabricator', 'applications/differential/constants/changetype');
phutil_require_module('phabricator', 'applications/differential/view/changesetlistview');
phutil_require_module('phabricator', 'applications/diffusion/controller/base');
phutil_require_module('phabricator', 'applications/diffusion/data/pathchange');
phutil_require_module('phabricator', 'applications/diffusion/query/contains/base');
phutil_require_module('phabricator', 'applications/diffusion/query/path');
phutil_require_module('phabricator', 'applications/diffusion/query/pathchange/base');
phutil_require_module('phabricator', 'applications/diffusion/query/pathid/base');
phutil_require_module('phabricator', 'applications/diffusion/request/base');

View file

@ -0,0 +1,59 @@
<?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 DiffusionPathQuery {
private $pathIDs;
public function withPathIDs(array $path_ids) {
$this->pathIDs = $path_ids;
return $this;
}
public function execute() {
$conn_r = id(new PhabricatorRepository())->establishConnection('r');
$where = $this->buildWhereClause($conn_r);
$results = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q',
PhabricatorRepository::TABLE_PATH,
$where);
return ipull($results, null, 'id');
}
private function buildWhereClause($conn_r) {
$where = array();
if ($this->pathIDs) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->pathIDs);
}
if ($where) {
return 'WHERE ('.implode(') AND (', $where).')';
} else {
return '';
}
}
}

View file

@ -0,0 +1,16 @@
<?php
/**
* This file is automatically generated. Lint this module to rebuild it.
* @generated
*/
phutil_require_module('phabricator', 'applications/repository/storage/repository');
phutil_require_module('phabricator', 'storage/qsprintf');
phutil_require_module('phabricator', 'storage/queryfx');
phutil_require_module('phutil', 'utils');
phutil_require_source('DiffusionPathQuery.php');

View file

@ -23,6 +23,9 @@ final class DiffusionCommentView extends AphrontView {
private $commentNumber;
private $handles;
private $isPreview;
private $pathMap;
private $inlineComments;
private $engine;
@ -51,6 +54,16 @@ final class DiffusionCommentView extends AphrontView {
return $this;
}
public function setInlineComments(array $inline_comments) {
$this->inlineComments = $inline_comments;
return $this;
}
public function setPathMap(array $path_map) {
$this->pathMap = $path_map;
return $this;
}
public function getRequiredHandlePHIDs() {
return array($this->comment->getActorPHID());
}
@ -125,9 +138,42 @@ final class DiffusionCommentView extends AphrontView {
return
'<div class="phabricator-remarkup">'.
$engine->markupText($comment->getContent()).
$this->renderSingleView($this->renderInlines()).
'</div>';
}
private function renderInlines() {
if (!$this->inlineComments) {
return null;
}
$inlines_by_path = mgroup($this->inlineComments, 'getPathID');
$view = new PhabricatorInlineSummaryView();
foreach ($inlines_by_path as $path_id => $inlines) {
$path = idx($this->pathMap, $path_id);
if ($path === null) {
continue;
}
$items = array();
foreach ($inlines as $inline) {
$items[] = array(
'id' => $inline->getID(),
'line' => $inline->getLineNumber(),
'length' => $inline->getLineLength(),
'content' => PhabricatorInlineSummaryView::renderCommentContent(
$inline,
$this->getEngine()),
);
}
$view->addCommentGroup($path, $items);
}
return $view;
}
private function getEngine() {
if (!$this->engine) {
$this->engine = PhabricatorMarkupEngine::newDiffusionMarkupEngine();
@ -151,7 +197,4 @@ final class DiffusionCommentView extends AphrontView {
return $classes;
}
}

View file

@ -8,6 +8,7 @@
phutil_require_module('phabricator', 'applications/audit/constants/action');
phutil_require_module('phabricator', 'applications/markup/engine');
phutil_require_module('phabricator', 'infrastructure/diff/view/inline');
phutil_require_module('phabricator', 'view/base');
phutil_require_module('phabricator', 'view/layout/transaction');

View file

@ -20,6 +20,8 @@ final class DiffusionCommentListView extends AphrontView {
private $user;
private $comments;
private $inlineComments = array();
private $pathMap = array();
public function setUser(PhabricatorUser $user) {
$this->user = $user;
@ -31,11 +33,24 @@ final class DiffusionCommentListView extends AphrontView {
return $this;
}
public function setInlineComments(array $inline_comments) {
$this->inlineComments = $inline_comments;
return $this;
}
public function setPathMap(array $path_map) {
$this->pathMap = $path_map;
return $this;
}
public function getRequiredHandlePHIDs() {
$phids = array();
foreach ($this->comments as $comment) {
$phids[$comment->getActorPHID()] = true;
}
foreach ($this->inlineComments as $comment) {
$phids[$comment->getAuthorPHID()] = true;
}
return array_keys($phids);
}
@ -44,17 +59,23 @@ final class DiffusionCommentListView extends AphrontView {
return $this;
}
public function render() {
$inline_comments = mgroup($this->inlineComments, 'getAuditCommentID');
$num = 1;
$comments = array();
foreach ($this->comments as $comment) {
$inlines = idx($inline_comments, $comment->getID(), array());
$view = id(new DiffusionCommentView())
->setComment($comment)
->setInlineComments($inlines)
->setCommentNumber($num)
->setHandles($this->handles)
->setPathMap($this->pathMap)
->setUser($this->user);
$comments[] = $view->render();