1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Allow users to add comments in Pholio

Summary: Basic support for adding comments. Missing a lot of frills. Uses new comment/transaction UI.

Test Plan:
Added some comments. Tried to add an empty comment.

Some comments:

{F22361}

No text provided:

{F22362}

Reviewers: btrahan, chad

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2097

Differential Revision: https://secure.phabricator.com/D3834
This commit is contained in:
epriestley 2012-11-21 17:27:20 -08:00
parent 1d5551789d
commit e389fc70fa
5 changed files with 189 additions and 5 deletions

View file

@ -1208,6 +1208,7 @@ phutil_register_library_map(array(
'PholioImage' => 'applications/pholio/storage/PholioImage.php',
'PholioIndexer' => 'applications/pholio/indexer/PholioIndexer.php',
'PholioMock' => 'applications/pholio/storage/PholioMock.php',
'PholioMockCommentController' => 'applications/pholio/controller/PholioMockCommentController.php',
'PholioMockEditController' => 'applications/pholio/controller/PholioMockEditController.php',
'PholioMockEditor' => 'applications/pholio/editor/PholioMockEditor.php',
'PholioMockListController' => 'applications/pholio/controller/PholioMockListController.php',
@ -1215,6 +1216,7 @@ phutil_register_library_map(array(
'PholioMockViewController' => 'applications/pholio/controller/PholioMockViewController.php',
'PholioPixelComment' => 'applications/pholio/storage/PholioPixelComment.php',
'PholioTransaction' => 'applications/pholio/storage/PholioTransaction.php',
'PholioTransactionQuery' => 'applications/pholio/query/PholioTransactionQuery.php',
'PhortuneMonthYearExpiryControl' => 'applications/phortune/control/PhortuneMonthYearExpiryControl.php',
'PhortuneStripeBaseController' => 'applications/phortune/stripe/controller/PhortuneStripeBaseController.php',
'PhortuneStripePaymentFormView' => 'applications/phortune/stripe/view/PhortuneStripePaymentFormView.php',
@ -2412,6 +2414,7 @@ phutil_register_library_map(array(
2 => 'PhabricatorPolicyInterface',
3 => 'PhabricatorSubscribableInterface',
),
'PholioMockCommentController' => 'PholioController',
'PholioMockEditController' => 'PholioController',
'PholioMockEditor' => 'PhabricatorEditor',
'PholioMockListController' => 'PholioController',
@ -2427,6 +2430,7 @@ phutil_register_library_map(array(
0 => 'PholioDAO',
1 => 'PhabricatorMarkupInterface',
),
'PholioTransactionQuery' => 'PhabricatorOffsetPagedQuery',
'PhortuneMonthYearExpiryControl' => 'AphrontFormControl',
'PhortuneStripeBaseController' => 'PhabricatorController',
'PhortuneStripePaymentFormView' => 'AphrontView',

View file

@ -56,9 +56,10 @@ final class PhabricatorApplicationPholio extends PhabricatorApplication {
'/M(?P<id>[1-9]\d*)' => 'PholioMockViewController',
'/pholio/' => array(
'' => 'PholioMockListController',
'view/(?P<view>\w+)/' => 'PholioMockListController',
'new/' => 'PholioMockEditController',
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
'view/(?P<view>\w+)/' => 'PholioMockListController',
'new/' => 'PholioMockEditController',
'edit/(?P<id>\d+)/' => 'PholioMockEditController',
'comment/(?P<id>\d+)/' => 'PholioMockCommentController',
),
);
}

View file

@ -0,0 +1,78 @@
<?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.
*/
/**
* @group pholio
*/
final class PholioMockCommentController extends PholioController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$mock = id(new PholioMockQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
if (!$mock) {
return new Aphront404Response();
}
$mock_uri = '/M'.$mock->getID();
$comment = $request->getStr('comment');
if (!strlen($comment)) {
$dialog = id(new AphrontDialogView())
->setUser($user)
->setTitle(pht('Empty Comment'))
->appendChild('You did not provide a comment!')
->addCancelButton($mock_uri);
return id(new AphrontDialogResponse())->setDialog($dialog);
}
$content_source = PhabricatorContentSource::newForSource(
PhabricatorContentSource::SOURCE_WEB,
array(
'ip' => $request->getRemoteAddr(),
));
// TODO: Move this to an Editor.
$xaction = id(new PholioTransaction())
// TODO: Formalize transaction types.
->setTransactionType('none')
->setAuthorPHID($user->getPHID())
->setComment($comment)
->setContentSource($content_source)
->setMockID($mock->getID());
$xaction->save();
return id(new AphrontRedirectResponse())->setURI($mock_uri);
}
}

View file

@ -40,14 +40,25 @@ final class PholioMockViewController extends PholioController {
return new Aphront404Response();
}
$xactions = id(new PholioTransactionQuery())
->withMockIDs(array($mock->getID()))
->execute();
$phids = array();
$phids[] = $mock->getAuthorPHID();
foreach ($xactions as $xaction) {
$phids[] = $xaction->getAuthorPHID();
}
$this->loadHandles($phids);
$engine = id(new PhabricatorMarkupEngine())
->setViewer($user);
$engine->addObject($mock, PholioMock::MARKUP_FIELD_DESCRIPTION);
foreach ($xactions as $xaction) {
$engine->addObject($xaction, PholioTransaction::MARKUP_FIELD_COMMENT);
}
$engine->process();
$title = 'M'.$mock->getID().' '.$mock->getName();
@ -65,6 +76,9 @@ final class PholioMockViewController extends PholioController {
'<h1 style="margin: 2em; padding: 1em; border: 1px dashed grey;">'.
'Comments/Transactions Go Here</h1>';
$xaction_view = $this->buildTransactionView($xactions, $engine);
$add_comment = $this->buildAddCommentView($mock);
$content = array(
@ -72,7 +86,7 @@ final class PholioMockViewController extends PholioController {
$actions,
$properties,
$carousel,
$comments,
$xaction_view,
$add_comment,
);
@ -155,7 +169,7 @@ final class PholioMockViewController extends PholioController {
$form = id(new AphrontFormView())
->setUser($user)
->setAction($this->getApplicationURI('/addcomment/'.$mock->getID().'/'))
->setAction($this->getApplicationURI('/comment/'.$mock->getID().'/'))
->setWorkflow(true)
->setFlexible(true)
->appendChild(
@ -172,4 +186,27 @@ final class PholioMockViewController extends PholioController {
);
}
private function buildTransactionView(
array $xactions,
PhabricatorMarkupEngine $engine) {
assert_instances_of($xactions, 'PholioTransaction');
$view = new PhabricatorTimelineView();
foreach ($xactions as $xaction) {
$author = $this->getHandle($xaction->getAuthorPHID());
$view->addEvent(
id(new PhabricatorTimelineEventView())
->setUserHandle($author)
->setTitle($author->renderLink().' added a comment.')
->appendChild(
$engine->getOutput(
$xaction,
PholioTransaction::MARKUP_FIELD_COMMENT)));
}
return $view;
}
}

View file

@ -0,0 +1,64 @@
<?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.
*/
/**
* @group pholio
*/
final class PholioTransactionQuery
extends PhabricatorOffsetPagedQuery {
private $mockIDs;
public function withMockIDs(array $ids) {
$this->mockIDs = $ids;
return $this;
}
public function execute() {
$table = new PholioTransaction();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T x %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
private function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->mockIDs) {
$where[] = qsprintf(
$conn_r,
'mockID IN (%Ld)',
$this->mockIDs);
}
return $this->formatWhereClause($where);
}
private function buildOrderClause(AphrontDatabaseConnection $conn_r) {
return 'ORDER BY id ASC';
}
}