mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-26 16:52:41 +01:00
Make inline comment preview work in Diffusion
Summary: created a PhabricatorInlineCommentPreviewController so controllers in Diffusion and Differential respectively just have to handle the URI mapping and data loading like good little controllers. Test Plan: left inline comments on commits, deleted inline commits, submitted inline comments -- all worked well did the same on some diffs Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T1176 Differential Revision: https://secure.phabricator.com/D3034
This commit is contained in:
parent
49205f977c
commit
bc29a3e8a2
7 changed files with 109 additions and 33 deletions
|
@ -360,6 +360,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionHistoryTableView' => 'applications/diffusion/view/DiffusionHistoryTableView.php',
|
||||
'DiffusionHomeController' => 'applications/diffusion/controller/DiffusionHomeController.php',
|
||||
'DiffusionInlineCommentController' => 'applications/diffusion/controller/DiffusionInlineCommentController.php',
|
||||
'DiffusionInlineCommentPreviewController' => 'applications/diffusion/controller/DiffusionInlineCommentPreviewController.php',
|
||||
'DiffusionLastModifiedController' => 'applications/diffusion/controller/DiffusionLastModifiedController.php',
|
||||
'DiffusionLastModifiedQuery' => 'applications/diffusion/query/lastmodified/DiffusionLastModifiedQuery.php',
|
||||
'DiffusionMercurialBranchQuery' => 'applications/diffusion/query/branch/DiffusionMercurialBranchQuery.php',
|
||||
|
@ -721,6 +722,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorInfrastructureTestCase' => 'infrastructure/__tests__/PhabricatorInfrastructureTestCase.php',
|
||||
'PhabricatorInlineCommentController' => 'infrastructure/diff/PhabricatorInlineCommentController.php',
|
||||
'PhabricatorInlineCommentInterface' => 'infrastructure/diff/interface/PhabricatorInlineCommentInterface.php',
|
||||
'PhabricatorInlineCommentPreviewController' => 'infrastructure/diff/PhabricatorInlineCommentPreviewController.php',
|
||||
'PhabricatorInlineSummaryView' => 'infrastructure/diff/view/PhabricatorInlineSummaryView.php',
|
||||
'PhabricatorJavelinLinter' => 'infrastructure/lint/linter/PhabricatorJavelinLinter.php',
|
||||
'PhabricatorJumpNavHandler' => 'applications/search/engine/PhabricatorJumpNavHandler.php',
|
||||
|
@ -1369,7 +1371,7 @@ phutil_register_library_map(array(
|
|||
),
|
||||
'DifferentialInlineCommentEditController' => 'PhabricatorInlineCommentController',
|
||||
'DifferentialInlineCommentEditView' => 'AphrontView',
|
||||
'DifferentialInlineCommentPreviewController' => 'DifferentialController',
|
||||
'DifferentialInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController',
|
||||
'DifferentialInlineCommentView' => 'AphrontView',
|
||||
'DifferentialLinesFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
'DifferentialLintFieldSpecification' => 'DifferentialFieldSpecification',
|
||||
|
@ -1442,6 +1444,7 @@ phutil_register_library_map(array(
|
|||
'DiffusionHistoryTableView' => 'DiffusionView',
|
||||
'DiffusionHomeController' => 'DiffusionController',
|
||||
'DiffusionInlineCommentController' => 'PhabricatorInlineCommentController',
|
||||
'DiffusionInlineCommentPreviewController' => 'PhabricatorInlineCommentPreviewController',
|
||||
'DiffusionLastModifiedController' => 'DiffusionController',
|
||||
'DiffusionLastModifiedQuery' => 'DiffusionQuery',
|
||||
'DiffusionMercurialBranchQuery' => 'DiffusionBranchQuery',
|
||||
|
@ -1753,6 +1756,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorIRCWhatsNewHandler' => 'PhabricatorIRCHandler',
|
||||
'PhabricatorInfrastructureTestCase' => 'PhabricatorTestCase',
|
||||
'PhabricatorInlineCommentController' => 'PhabricatorController',
|
||||
'PhabricatorInlineCommentPreviewController' => 'PhabricatorController',
|
||||
'PhabricatorInlineSummaryView' => 'AphrontView',
|
||||
'PhabricatorJavelinLinter' => 'ArcanistLinter',
|
||||
'PhabricatorLDAPLoginController' => 'PhabricatorAuthController',
|
||||
|
|
|
@ -257,7 +257,11 @@ class AphrontDefaultApplicationConfiguration
|
|||
'tags/(?P<dblob>.*)' => 'DiffusionTagListController',
|
||||
'branches/(?P<dblob>.*)' => 'DiffusionBranchTableController',
|
||||
),
|
||||
'inline/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'inline/' => array(
|
||||
'edit/(?P<phid>[^/]+)/' => 'DiffusionInlineCommentController',
|
||||
'preview/(?P<phid>[^/]+)/' =>
|
||||
'DiffusionInlineCommentPreviewController',
|
||||
),
|
||||
'services/' => array(
|
||||
'path/' => array(
|
||||
'complete/' => 'DiffusionPathCompleteController',
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
*/
|
||||
|
||||
final class DifferentialInlineCommentPreviewController
|
||||
extends DifferentialController {
|
||||
extends PhabricatorInlineCommentPreviewController {
|
||||
|
||||
private $revisionID;
|
||||
|
||||
|
@ -25,41 +25,15 @@ final class DifferentialInlineCommentPreviewController
|
|||
$this->revisionID = $data['id'];
|
||||
}
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
// TODO: This is a reasonable approximation of the feature as it exists
|
||||
// in Facebook trunk but we should probably pull filename data, sort these,
|
||||
// figure out next/prev/edit/delete, deal with out-of-date inlines, etc.
|
||||
protected function loadInlineComments() {
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$inlines = id(new DifferentialInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND revisionID = %d AND commentID IS NULL',
|
||||
$user->getPHID(),
|
||||
$this->revisionID);
|
||||
|
||||
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
||||
|
||||
$phids = array($user->getPHID());
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->loadHandles();
|
||||
|
||||
$views = array();
|
||||
foreach ($inlines as $inline) {
|
||||
$view = new DifferentialInlineCommentView();
|
||||
$view->setInlineComment($inline);
|
||||
$view->setMarkupEngine($engine);
|
||||
$view->setHandles($handles);
|
||||
$view->setEditable(false);
|
||||
$view->setPreview(true);
|
||||
$views[] = $view->render();
|
||||
}
|
||||
$views = implode("\n", $views);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($views);
|
||||
return $inlines;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -264,7 +264,7 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
'/diffusion/'.$callsign.'/diff/?view=r');
|
||||
|
||||
$change_list->setInlineCommentControllerURI(
|
||||
'/diffusion/inline/'.phutil_escape_uri($commit->getPHID()).'/');
|
||||
'/diffusion/inline/edit/'.phutil_escape_uri($commit->getPHID()).'/');
|
||||
|
||||
// TODO: This is pretty awkward, unify the CSS between Diffusion and
|
||||
// Differential better.
|
||||
|
@ -580,6 +580,8 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
'auditors' => 'add-auditors-tokenizer',
|
||||
'ccs' => 'add-ccs-tokenizer',
|
||||
),
|
||||
'inline' => 'inline-comment-preview',
|
||||
'inlineuri' => '/diffusion/inline/preview/'.$commit->getPHID().'/',
|
||||
));
|
||||
|
||||
$preview_panel =
|
||||
|
@ -589,6 +591,8 @@ final class DiffusionCommitController extends DiffusionController {
|
|||
Loading preview...
|
||||
</div>
|
||||
</div>
|
||||
<div id="inline-comment-preview">
|
||||
</div>
|
||||
</div>';
|
||||
|
||||
return
|
||||
|
|
|
@ -65,6 +65,7 @@ final class DiffusionDiffController extends DiffusionController {
|
|||
}
|
||||
|
||||
$parser = new DifferentialChangesetParser();
|
||||
$parser->setUser($user);
|
||||
$parser->setChangeset($changeset);
|
||||
$parser->setRenderingReference($diff_query->getRenderingReference());
|
||||
$parser->setMarkupEngine(
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
<?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 DiffusionInlineCommentPreviewController
|
||||
extends PhabricatorInlineCommentPreviewController {
|
||||
|
||||
private $commitPHID;
|
||||
|
||||
public function willProcessRequest(array $data) {
|
||||
$this->commitPHID = $data['phid'];
|
||||
}
|
||||
|
||||
protected function loadInlineComments() {
|
||||
$user = $this->getRequest()->getUser();
|
||||
|
||||
$inlines = id(new PhabricatorAuditInlineComment())->loadAllWhere(
|
||||
'authorPHID = %s AND commitPHID = %s AND auditCommentID IS NULL',
|
||||
$user->getPHID(),
|
||||
$this->commitPHID);
|
||||
|
||||
return $inlines;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
<?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.
|
||||
*/
|
||||
|
||||
abstract class PhabricatorInlineCommentPreviewController
|
||||
extends PhabricatorController {
|
||||
|
||||
abstract protected function loadInlineComments();
|
||||
|
||||
public function processRequest() {
|
||||
$request = $this->getRequest();
|
||||
$user = $request->getUser();
|
||||
|
||||
$inlines = $this->loadInlineComments();
|
||||
assert_instances_of($inlines, 'PhabricatorInlineCommentInterface');
|
||||
$engine = PhabricatorMarkupEngine::newDifferentialMarkupEngine();
|
||||
|
||||
$phids = array($user->getPHID());
|
||||
$handles = id(new PhabricatorObjectHandleData($phids))
|
||||
->loadHandles();
|
||||
|
||||
$views = array();
|
||||
foreach ($inlines as $inline) {
|
||||
$view = new DifferentialInlineCommentView();
|
||||
$view->setInlineComment($inline);
|
||||
$view->setMarkupEngine($engine);
|
||||
$view->setHandles($handles);
|
||||
$view->setEditable(false);
|
||||
$view->setPreview(true);
|
||||
$views[] = $view->render();
|
||||
}
|
||||
$views = implode("\n", $views);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($views);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue