mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-20 04:20:55 +01:00
Add Mark as Helpful to PonderAnswer
Summary: Ref T6920, this adds a basic controller for marking an answer as helpful and removes the negative voting. Any current positive vote is kept as helpful. New UI is needed here, but there is a separate task for redesigning Ponder overall. Test Plan: Mark an answer as helpful, see count go up, remove helpful, see count go down. Test endpoint manually. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T6920 Differential Revision: https://secure.phabricator.com/D13834
This commit is contained in:
parent
0e7efceb51
commit
2752419160
8 changed files with 91 additions and 37 deletions
|
@ -3404,6 +3404,7 @@ phutil_register_library_map(array(
|
||||||
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
|
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
|
||||||
'PonderDefaultViewCapability' => 'applications/ponder/capability/PonderDefaultViewCapability.php',
|
'PonderDefaultViewCapability' => 'applications/ponder/capability/PonderDefaultViewCapability.php',
|
||||||
'PonderEditor' => 'applications/ponder/editor/PonderEditor.php',
|
'PonderEditor' => 'applications/ponder/editor/PonderEditor.php',
|
||||||
|
'PonderHelpfulSaveController' => 'applications/ponder/controller/PonderHelpfulSaveController.php',
|
||||||
'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php',
|
'PonderModerateCapability' => 'applications/ponder/capability/PonderModerateCapability.php',
|
||||||
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
||||||
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
|
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
|
||||||
|
@ -3429,7 +3430,6 @@ phutil_register_library_map(array(
|
||||||
'PonderVotableInterface' => 'applications/ponder/storage/PonderVotableInterface.php',
|
'PonderVotableInterface' => 'applications/ponder/storage/PonderVotableInterface.php',
|
||||||
'PonderVote' => 'applications/ponder/constants/PonderVote.php',
|
'PonderVote' => 'applications/ponder/constants/PonderVote.php',
|
||||||
'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php',
|
'PonderVoteEditor' => 'applications/ponder/editor/PonderVoteEditor.php',
|
||||||
'PonderVoteSaveController' => 'applications/ponder/controller/PonderVoteSaveController.php',
|
|
||||||
'PonderVotingUserHasAnswerEdgeType' => 'applications/ponder/edge/PonderVotingUserHasAnswerEdgeType.php',
|
'PonderVotingUserHasAnswerEdgeType' => 'applications/ponder/edge/PonderVotingUserHasAnswerEdgeType.php',
|
||||||
'ProjectAddProjectsEmailCommand' => 'applications/project/command/ProjectAddProjectsEmailCommand.php',
|
'ProjectAddProjectsEmailCommand' => 'applications/project/command/ProjectAddProjectsEmailCommand.php',
|
||||||
'ProjectBoardTaskCard' => 'applications/project/view/ProjectBoardTaskCard.php',
|
'ProjectBoardTaskCard' => 'applications/project/view/ProjectBoardTaskCard.php',
|
||||||
|
@ -7590,6 +7590,7 @@ phutil_register_library_map(array(
|
||||||
'PonderDAO' => 'PhabricatorLiskDAO',
|
'PonderDAO' => 'PhabricatorLiskDAO',
|
||||||
'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
'PonderDefaultViewCapability' => 'PhabricatorPolicyCapability',
|
||||||
'PonderEditor' => 'PhabricatorApplicationTransactionEditor',
|
'PonderEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
|
'PonderHelpfulSaveController' => 'PonderController',
|
||||||
'PonderModerateCapability' => 'PhabricatorPolicyCapability',
|
'PonderModerateCapability' => 'PhabricatorPolicyCapability',
|
||||||
'PonderQuestion' => array(
|
'PonderQuestion' => array(
|
||||||
'PonderDAO',
|
'PonderDAO',
|
||||||
|
@ -7625,7 +7626,6 @@ phutil_register_library_map(array(
|
||||||
'PonderTransactionFeedStory' => 'PhabricatorApplicationTransactionFeedStory',
|
'PonderTransactionFeedStory' => 'PhabricatorApplicationTransactionFeedStory',
|
||||||
'PonderVote' => 'PonderConstants',
|
'PonderVote' => 'PonderConstants',
|
||||||
'PonderVoteEditor' => 'PhabricatorEditor',
|
'PonderVoteEditor' => 'PhabricatorEditor',
|
||||||
'PonderVoteSaveController' => 'PonderController',
|
|
||||||
'PonderVotingUserHasAnswerEdgeType' => 'PhabricatorEdgeType',
|
'PonderVotingUserHasAnswerEdgeType' => 'PhabricatorEdgeType',
|
||||||
'ProjectAddProjectsEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
'ProjectAddProjectsEmailCommand' => 'MetaMTAEmailTransactionCommand',
|
||||||
'ProjectBoardTaskCard' => 'Phobject',
|
'ProjectBoardTaskCard' => 'Phobject',
|
||||||
|
|
|
@ -61,6 +61,8 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
|
||||||
=> 'PonderAnswerCommentController',
|
=> 'PonderAnswerCommentController',
|
||||||
'answer/history/(?P<id>\d+)/'
|
'answer/history/(?P<id>\d+)/'
|
||||||
=> 'PonderAnswerHistoryController',
|
=> 'PonderAnswerHistoryController',
|
||||||
|
'answer/helpful/(?P<action>add|remove)/(?P<id>[1-9]\d*)/'
|
||||||
|
=> 'PonderHelpfulSaveController',
|
||||||
'question/edit/(?:(?P<id>\d+)/)?'
|
'question/edit/(?:(?P<id>\d+)/)?'
|
||||||
=> 'PonderQuestionEditController',
|
=> 'PonderQuestionEditController',
|
||||||
'question/create/'
|
'question/create/'
|
||||||
|
@ -73,7 +75,6 @@ final class PhabricatorPonderApplication extends PhabricatorApplication {
|
||||||
=> 'PhabricatorMarkupPreviewController',
|
=> 'PhabricatorMarkupPreviewController',
|
||||||
'question/status/(?P<id>[1-9]\d*)/'
|
'question/status/(?P<id>[1-9]\d*)/'
|
||||||
=> 'PonderQuestionStatusController',
|
=> 'PonderQuestionStatusController',
|
||||||
'vote/' => 'PonderVoteSaveController',
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,5 @@ final class PonderVote extends PonderConstants {
|
||||||
|
|
||||||
const VOTE_UP = 1;
|
const VOTE_UP = 1;
|
||||||
const VOTE_NONE = 0;
|
const VOTE_NONE = 0;
|
||||||
const VOTE_DOWN = -1;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class PonderHelpfulSaveController extends PonderController {
|
||||||
|
|
||||||
|
public function handleRequest(AphrontRequest $request) {
|
||||||
|
$viewer = $request->getViewer();
|
||||||
|
$id = $request->getURIData('id');
|
||||||
|
$action = $request->getURIData('action');
|
||||||
|
|
||||||
|
$answer = id(new PonderAnswerQuery())
|
||||||
|
->setViewer($viewer)
|
||||||
|
->withIDs(array($id))
|
||||||
|
->needViewerVotes(true)
|
||||||
|
->executeOne();
|
||||||
|
|
||||||
|
if (!$answer) {
|
||||||
|
return new Aphront404Response();
|
||||||
|
}
|
||||||
|
|
||||||
|
$edit_uri = '/Q'.$answer->getQuestionID();
|
||||||
|
|
||||||
|
switch ($action) {
|
||||||
|
case 'add':
|
||||||
|
$newvote = PonderVote::VOTE_UP;
|
||||||
|
break;
|
||||||
|
case 'remove':
|
||||||
|
$newvote = PonderVote::VOTE_NONE;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($request->isFormPost()) {
|
||||||
|
|
||||||
|
$editor = id(new PonderVoteEditor())
|
||||||
|
->setVotable($answer)
|
||||||
|
->setActor($viewer)
|
||||||
|
->setVote($newvote)
|
||||||
|
->saveVote();
|
||||||
|
|
||||||
|
return id(new AphrontRedirectResponse())->setURI($edit_uri);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($action == 'add') {
|
||||||
|
$title = pht('Mark Answer as Helpful?');
|
||||||
|
$body = pht('This answer will be marked as helpful.');
|
||||||
|
$button = pht('Mark Helpful');
|
||||||
|
} else {
|
||||||
|
$title = pht('Remove Helpful From Answer?');
|
||||||
|
$body = pht('This answer will no longer be marked as helpful.');
|
||||||
|
$button = pht('Remove Helpful');
|
||||||
|
}
|
||||||
|
|
||||||
|
$dialog = $this->newDialog();
|
||||||
|
$dialog->setTitle($title);
|
||||||
|
$dialog->appendChild($body);
|
||||||
|
$dialog->addCancelButton($edit_uri);
|
||||||
|
$dialog->addSubmitButton($button);
|
||||||
|
|
||||||
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
||||||
|
}
|
||||||
|
}
|
|
@ -291,6 +291,28 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
->setObject($answer)
|
->setObject($answer)
|
||||||
->setObjectURI($request->getRequestURI());
|
->setObjectURI($request->getRequestURI());
|
||||||
|
|
||||||
|
$user_marked = $answer->getUserVote();
|
||||||
|
$can_vote = $viewer->isLoggedIn();
|
||||||
|
|
||||||
|
if ($user_marked) {
|
||||||
|
$helpful_uri = "/answer/helpful/remove/{$id}/";
|
||||||
|
$helpful_icon = 'fa-times';
|
||||||
|
$helpful_text = pht('Remove Helpful');
|
||||||
|
} else {
|
||||||
|
$helpful_uri = "/answer/helpful/add/{$id}/";
|
||||||
|
$helpful_icon = 'fa-thumbs-up';
|
||||||
|
$helpful_text = pht('Mark as Helpful');
|
||||||
|
}
|
||||||
|
|
||||||
|
$view->addAction(
|
||||||
|
id(new PhabricatorActionView())
|
||||||
|
->setIcon($helpful_icon)
|
||||||
|
->setName($helpful_text)
|
||||||
|
->setHref($this->getApplicationURI($helpful_uri))
|
||||||
|
->setRenderAsForm(true)
|
||||||
|
->setDisabled(!$can_vote)
|
||||||
|
->setWorkflow($can_vote));
|
||||||
|
|
||||||
$view->addAction(
|
$view->addAction(
|
||||||
id(new PhabricatorActionView())
|
id(new PhabricatorActionView())
|
||||||
->setIcon('fa-pencil')
|
->setIcon('fa-pencil')
|
||||||
|
@ -322,6 +344,10 @@ final class PonderQuestionViewController extends PonderController {
|
||||||
pht('Created'),
|
pht('Created'),
|
||||||
phabricator_datetime($answer->getDateCreated(), $viewer));
|
phabricator_datetime($answer->getDateCreated(), $viewer));
|
||||||
|
|
||||||
|
$view->addProperty(
|
||||||
|
pht('Helpfuls'),
|
||||||
|
$answer->getVoteCount());
|
||||||
|
|
||||||
$view->invokeWillRenderEvent();
|
$view->invokeWillRenderEvent();
|
||||||
|
|
||||||
$view->addSectionHeader(pht('Answer'));
|
$view->addSectionHeader(pht('Answer'));
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
<?php
|
|
||||||
|
|
||||||
final class PonderVoteSaveController extends PonderController {
|
|
||||||
|
|
||||||
public function handleRequest(AphrontRequest $request) {
|
|
||||||
$viewer = $request->getViewer();
|
|
||||||
$phid = $request->getStr('phid');
|
|
||||||
$newvote = $request->getInt('vote');
|
|
||||||
|
|
||||||
if (1 < $newvote || $newvote < -1) {
|
|
||||||
return new Aphront400Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
$target = null;
|
|
||||||
|
|
||||||
$object = id(new PhabricatorObjectQuery())
|
|
||||||
->setViewer($viewer)
|
|
||||||
->withPHIDs(array($phid))
|
|
||||||
->executeOne();
|
|
||||||
if (!$object) {
|
|
||||||
return new Aphront404Response();
|
|
||||||
}
|
|
||||||
|
|
||||||
$editor = id(new PonderVoteEditor())
|
|
||||||
->setVotable($object)
|
|
||||||
->setActor($viewer)
|
|
||||||
->setVote($newvote)
|
|
||||||
->saveVote();
|
|
||||||
|
|
||||||
return id(new AphrontAjaxResponse())->setContent(array());
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -101,7 +101,6 @@ final class PonderAnswerQuery
|
||||||
$edges[$answer->getPHID()][$etype],
|
$edges[$answer->getPHID()][$etype],
|
||||||
$viewer_phid,
|
$viewer_phid,
|
||||||
array());
|
array());
|
||||||
|
|
||||||
$answer->attachUserVote($viewer_phid, idx($user_edge, 'data', 0));
|
$answer->attachUserVote($viewer_phid, idx($user_edge, 'data', 0));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -98,6 +98,7 @@ final class PonderQuestionQuery
|
||||||
$aquery = id(new PonderAnswerQuery())
|
$aquery = id(new PonderAnswerQuery())
|
||||||
->setViewer($this->getViewer())
|
->setViewer($this->getViewer())
|
||||||
->setOrderVector(array('-id'))
|
->setOrderVector(array('-id'))
|
||||||
|
->needViewerVotes(true)
|
||||||
->withQuestionIDs(mpull($questions, 'getID'));
|
->withQuestionIDs(mpull($questions, 'getID'));
|
||||||
|
|
||||||
$answers = $aquery->execute();
|
$answers = $aquery->execute();
|
||||||
|
|
Loading…
Reference in a new issue