mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-23 07:12:41 +01:00
Use PHUIRemarkupPreviewPanel in Ponder
Summary: Ref T3578. Ref T3671. Depends on D6673. Use `PHUIRemarkupPreviewPanel` (introduced in D6673) to provide question create/edit and answer edit previews in Ponder. Then delete a million lines of duplicate code. Test Plan: Edited a question; edited an answer. Saw live previews. Reviewers: btrahan, Firehed Reviewed By: btrahan CC: aran Maniphest Tasks: T3578, T3671 Differential Revision: https://secure.phabricator.com/D6674
This commit is contained in:
parent
193a9611e4
commit
b2fa1293a7
10 changed files with 17 additions and 219 deletions
|
@ -2268,19 +2268,6 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'disk' => '/rsrc/js/application/phriction/phriction-document-preview.js',
|
||||
),
|
||||
'javelin-behavior-ponder-feedback-preview' =>
|
||||
array(
|
||||
'uri' => '/res/2e802dd9/rsrc/js/application/ponder/behavior-comment-preview.js',
|
||||
'type' => 'js',
|
||||
'requires' =>
|
||||
array(
|
||||
0 => 'javelin-behavior',
|
||||
1 => 'javelin-dom',
|
||||
2 => 'javelin-util',
|
||||
3 => 'phabricator-shaped-request',
|
||||
),
|
||||
'disk' => '/rsrc/js/application/ponder/behavior-comment-preview.js',
|
||||
),
|
||||
'javelin-behavior-ponder-votebox' =>
|
||||
array(
|
||||
'uri' => '/res/c28daa12/rsrc/js/application/ponder/behavior-votebox.js',
|
||||
|
@ -3866,7 +3853,7 @@ celerity_register_resource_map(array(
|
|||
),
|
||||
'phui-remarkup-preview-css' =>
|
||||
array(
|
||||
'uri' => '/res/702b30c4/rsrc/css/phui/phui-remarkup-preview.css',
|
||||
'uri' => '/res/80d54c8c/rsrc/css/phui/phui-remarkup-preview.css',
|
||||
'type' => 'css',
|
||||
'requires' =>
|
||||
array(
|
||||
|
|
|
@ -1899,10 +1899,8 @@ phutil_register_library_map(array(
|
|||
'PonderConstants' => 'applications/ponder/constants/PonderConstants.php',
|
||||
'PonderController' => 'applications/ponder/controller/PonderController.php',
|
||||
'PonderDAO' => 'applications/ponder/storage/PonderDAO.php',
|
||||
'PonderLiterals' => 'applications/ponder/constants/PonderLiterals.php',
|
||||
'PonderPHIDTypeAnswer' => 'applications/ponder/phid/PonderPHIDTypeAnswer.php',
|
||||
'PonderPHIDTypeQuestion' => 'applications/ponder/phid/PonderPHIDTypeQuestion.php',
|
||||
'PonderPostBodyView' => 'applications/ponder/view/PonderPostBodyView.php',
|
||||
'PonderQuestion' => 'applications/ponder/storage/PonderQuestion.php',
|
||||
'PonderQuestionCommentController' => 'applications/ponder/controller/PonderQuestionCommentController.php',
|
||||
'PonderQuestionEditController' => 'applications/ponder/controller/PonderQuestionEditController.php',
|
||||
|
@ -1910,7 +1908,6 @@ phutil_register_library_map(array(
|
|||
'PonderQuestionHistoryController' => 'applications/ponder/controller/PonderQuestionHistoryController.php',
|
||||
'PonderQuestionListController' => 'applications/ponder/controller/PonderQuestionListController.php',
|
||||
'PonderQuestionMailReceiver' => 'applications/ponder/mail/PonderQuestionMailReceiver.php',
|
||||
'PonderQuestionPreviewController' => 'applications/ponder/controller/PonderQuestionPreviewController.php',
|
||||
'PonderQuestionQuery' => 'applications/ponder/query/PonderQuestionQuery.php',
|
||||
'PonderQuestionReplyHandler' => 'applications/ponder/mail/PonderQuestionReplyHandler.php',
|
||||
'PonderQuestionSearchEngine' => 'applications/ponder/query/PonderQuestionSearchEngine.php',
|
||||
|
@ -4034,10 +4031,8 @@ phutil_register_library_map(array(
|
|||
'PonderCommentQuery' => 'PhabricatorQuery',
|
||||
'PonderController' => 'PhabricatorController',
|
||||
'PonderDAO' => 'PhabricatorLiskDAO',
|
||||
'PonderLiterals' => 'PonderConstants',
|
||||
'PonderPHIDTypeAnswer' => 'PhabricatorPHIDType',
|
||||
'PonderPHIDTypeQuestion' => 'PhabricatorPHIDType',
|
||||
'PonderPostBodyView' => 'AphrontView',
|
||||
'PonderQuestion' =>
|
||||
array(
|
||||
0 => 'PonderDAO',
|
||||
|
@ -4057,7 +4052,6 @@ phutil_register_library_map(array(
|
|||
1 => 'PhabricatorApplicationSearchResultsControllerInterface',
|
||||
),
|
||||
'PonderQuestionMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PonderQuestionPreviewController' => 'PonderController',
|
||||
'PonderQuestionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PonderQuestionReplyHandler' => 'PhabricatorMailReplyHandler',
|
||||
'PonderQuestionSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
|
|
|
@ -57,7 +57,7 @@ final class PhabricatorApplicationPonder extends PhabricatorApplication {
|
|||
'question/edit/(?:(?P<id>\d+)/)?' => 'PonderQuestionEditController',
|
||||
'question/comment/(?P<id>\d+)/' => 'PonderQuestionCommentController',
|
||||
'question/history/(?P<id>\d+)/' => 'PonderQuestionHistoryController',
|
||||
'question/preview/' => 'PonderQuestionPreviewController',
|
||||
'preview/' => 'PhabricatorMarkupPreviewController',
|
||||
'question/(?P<status>open|close)/(?P<id>[1-9]\d*)/' =>
|
||||
'PonderQuestionStatusController',
|
||||
'vote/' => 'PonderVoteSaveController',
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
<?php
|
||||
/**
|
||||
* @group ponder
|
||||
*/
|
||||
final class PonderLiterals extends PonderConstants {
|
||||
|
||||
const LITERAL_ANSWERED = "answered";
|
||||
const LITERAL_ASKED = "asked";
|
||||
|
||||
}
|
|
@ -66,6 +66,8 @@ final class PonderAnswerEditController extends PonderController {
|
|||
$errors = id(new AphrontErrorView())->setErrors($errors);
|
||||
}
|
||||
|
||||
$answer_content_id = celerity_generate_unique_node_id();
|
||||
|
||||
$form = id(new AphrontFormView())
|
||||
->setUser($viewer)
|
||||
->appendChild(
|
||||
|
@ -76,6 +78,7 @@ final class PonderAnswerEditController extends PonderController {
|
|||
id(new PhabricatorRemarkupControl())
|
||||
->setLabel(pht('Answer'))
|
||||
->setName('content')
|
||||
->setID($answer_content_id)
|
||||
->setValue($v_content)
|
||||
->setError($e_content))
|
||||
->appendChild(
|
||||
|
@ -92,11 +95,17 @@ final class PonderAnswerEditController extends PonderController {
|
|||
id(new PhabricatorCrumbView())
|
||||
->setName(pht('Edit Answer')));
|
||||
|
||||
$preview = id(new PHUIRemarkupPreviewPanel())
|
||||
->setHeader(pht('Answer Preview'))
|
||||
->setControlID($answer_content_id)
|
||||
->setPreviewURI($this->getApplicationURI('preview/'));
|
||||
|
||||
return $this->buildApplicationPage(
|
||||
array(
|
||||
$crumbs,
|
||||
$errors,
|
||||
$form,
|
||||
$preview,
|
||||
),
|
||||
array(
|
||||
'title' => pht('Edit Answer'),
|
||||
|
|
|
@ -104,22 +104,10 @@ final class PonderQuestionEditController extends PonderController {
|
|||
->addCancelButton($this->getApplicationURI())
|
||||
->setValue(pht('Ask Away!')));
|
||||
|
||||
$preview = hsprintf(
|
||||
'<div class="aphront-panel-flush">'.
|
||||
'<div id="question-preview">'.
|
||||
'<span class="aphront-panel-preview-loading-text">%s</span>'.
|
||||
'</div>'.
|
||||
'</div>',
|
||||
pht('Loading question preview...'));
|
||||
|
||||
Javelin::initBehavior(
|
||||
'ponder-feedback-preview',
|
||||
array(
|
||||
'uri' => '/ponder/question/preview/',
|
||||
'content' => 'content',
|
||||
'preview' => 'question-preview',
|
||||
'question_id' => null
|
||||
));
|
||||
$preview = id(new PHUIRemarkupPreviewPanel())
|
||||
->setHeader(pht('Question Preview'))
|
||||
->setControlID('content')
|
||||
->setPreviewURI($this->getApplicationURI('preview/'));
|
||||
|
||||
$crumbs = $this->buildApplicationCrumbs();
|
||||
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PonderQuestionPreviewController
|
||||
extends PonderController {
|
||||
|
||||
const VERB_ASKED = "asked";
|
||||
|
||||
public function processRequest() {
|
||||
|
||||
$request = $this->getRequest();
|
||||
|
||||
$user = $request->getUser();
|
||||
$author_phid = $user->getPHID();
|
||||
|
||||
$object_phids = array($author_phid);
|
||||
$handles = $this->loadViewerHandles($object_phids);
|
||||
|
||||
$question = new PonderQuestion();
|
||||
$question->setContent($request->getStr('content'));
|
||||
$question->setAuthorPHID($author_phid);
|
||||
|
||||
$view = new PonderPostBodyView();
|
||||
$view
|
||||
->setQuestion($question)
|
||||
->setTarget($question)
|
||||
->setPreview(true)
|
||||
->setUser($user)
|
||||
->setHandles($handles)
|
||||
->setAction(self::VERB_ASKED);
|
||||
|
||||
return id(new AphrontAjaxResponse())
|
||||
->setContent($view->render());
|
||||
}
|
||||
|
||||
}
|
|
@ -41,8 +41,8 @@ final class PonderAddAnswerView extends AphrontView {
|
|||
->appendChild(
|
||||
id(new AphrontFormSubmitControl())
|
||||
->setValue($is_serious ?
|
||||
pht('Submit') :
|
||||
pht('Make it so')));
|
||||
pht('Add Answer') :
|
||||
pht('Bequeath Wisdom')));
|
||||
|
||||
return id(new AphrontNullView())
|
||||
->appendChild(
|
||||
|
|
|
@ -1,103 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PonderPostBodyView extends AphrontView {
|
||||
|
||||
private $target;
|
||||
private $question;
|
||||
private $handles;
|
||||
private $preview;
|
||||
private $anchorName;
|
||||
private $action;
|
||||
|
||||
public function setQuestion($question) {
|
||||
$this->question = $question;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setTarget($target) {
|
||||
$this->target = $target;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setAction($action) {
|
||||
$this->action = $action;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setHandles(array $handles) {
|
||||
assert_instances_of($handles, 'PhabricatorObjectHandle');
|
||||
$this->handles = $handles;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setPreview($preview) {
|
||||
$this->preview = $preview;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function render() {
|
||||
|
||||
if (!$this->user) {
|
||||
throw new Exception("Call setUser() before rendering!");
|
||||
}
|
||||
|
||||
require_celerity_resource('phabricator-remarkup-css');
|
||||
require_celerity_resource('ponder-post-css');
|
||||
|
||||
$user = $this->user;
|
||||
$question = $this->question;
|
||||
$target = $this->target;
|
||||
$content = $target->getContent();
|
||||
$info = array();
|
||||
|
||||
|
||||
$content = PhabricatorMarkupEngine::renderOneObject(
|
||||
$target,
|
||||
$target->getMarkupField(),
|
||||
$this->user);
|
||||
|
||||
$content = phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'phabricator-remarkup',
|
||||
),
|
||||
$content);
|
||||
|
||||
$author = $this->handles[$target->getAuthorPHID()];
|
||||
$actions = array(hsprintf('%s %s', $author->renderLink(), $this->action));
|
||||
$author_link = $author->renderLink();
|
||||
$xaction_view = id(new PhabricatorTransactionView())
|
||||
->setUser($user)
|
||||
->setImageURI($author->getImageURI())
|
||||
->setContentSource($target->getContentSource())
|
||||
->setActions($actions);
|
||||
|
||||
if ($this->target instanceof PonderAnswer) {
|
||||
$xaction_view->addClass("ponder-answer");
|
||||
} else {
|
||||
$xaction_view->addClass("ponder-question");
|
||||
}
|
||||
|
||||
if ($this->preview) {
|
||||
$xaction_view->setIsPreview($this->preview);
|
||||
} else {
|
||||
$xaction_view->setEpoch($target->getDateCreated());
|
||||
if ($this->target instanceof PonderAnswer) {
|
||||
$anchor_text = 'Q' . $question->getID(). '#A' . $target->getID();
|
||||
$xaction_view->setAnchor('A'.$target->getID(), $anchor_text);
|
||||
$xaction_view->addClass("ponder-answer");
|
||||
}
|
||||
}
|
||||
|
||||
$xaction_view->appendChild(
|
||||
phutil_tag(
|
||||
'div',
|
||||
array(
|
||||
'class' => 'ponder-post-core',
|
||||
),
|
||||
$content));
|
||||
|
||||
return $xaction_view;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,32 +0,0 @@
|
|||
/**
|
||||
* @provides javelin-behavior-ponder-feedback-preview
|
||||
* @requires javelin-behavior
|
||||
* javelin-dom
|
||||
* javelin-util
|
||||
* phabricator-shaped-request
|
||||
*/
|
||||
|
||||
JX.behavior('ponder-feedback-preview', function(config) {
|
||||
|
||||
var content = JX.$(config.content);
|
||||
var question_id = config.question_id;
|
||||
|
||||
var callback = function(r) {
|
||||
JX.DOM.setContent(JX.$(config.preview), JX.$H(r));
|
||||
};
|
||||
|
||||
var getdata = function() {
|
||||
var data = {
|
||||
content : content.value,
|
||||
question_id : question_id
|
||||
};
|
||||
return data;
|
||||
};
|
||||
|
||||
var request = new JX.PhabricatorShapedRequest(config.uri, callback, getdata);
|
||||
var trigger = JX.bind(request, request.trigger);
|
||||
|
||||
JX.DOM.listen(content, 'keydown', null, trigger);
|
||||
|
||||
request.start();
|
||||
});
|
Loading…
Reference in a new issue