From 9a7beadd22f0356e56cdd86d5c7e5bcf525b6e6d Mon Sep 17 00:00:00 2001 From: Chad Little Date: Wed, 12 Aug 2015 07:56:31 -0700 Subject: [PATCH] Clean up some Ponder language Summary: Ref T9099. - Remove unused function - Fix celerity resource include - Add a note when an answer's been closed - Clean up architecture a little - Add a better notice when you've already answered. Test Plan: Test with and without answers, with answering, with being closed. Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9099 Differential Revision: https://secure.phabricator.com/D13875 --- .../ponder/constants/PonderQuestionStatus.php | 2 +- .../PonderQuestionViewController.php | 62 ++----------------- .../ponder/view/PonderAddAnswerView.php | 30 ++++++++- .../ponder/view/PonderFooterView.php | 1 + 4 files changed, 35 insertions(+), 60 deletions(-) diff --git a/src/applications/ponder/constants/PonderQuestionStatus.php b/src/applications/ponder/constants/PonderQuestionStatus.php index f37a208bcc..c401d52234 100644 --- a/src/applications/ponder/constants/PonderQuestionStatus.php +++ b/src/applications/ponder/constants/PonderQuestionStatus.php @@ -41,7 +41,7 @@ final class PonderQuestionStatus extends PonderConstants { self::STATUS_OPEN => pht('This question is open for answers.'), self::STATUS_CLOSED_RESOLVED => - pht('This question has been resolved.'), + pht('This question has been answered or resolved.'), self::STATUS_CLOSED_OBSOLETE => pht('This question is no longer valid or out of date.'), self::STATUS_CLOSED_DUPLICATE => diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index a974716540..2f0ae5099f 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -18,21 +18,10 @@ final class PonderQuestionViewController extends PonderController { $answers = $this->buildAnswers($question->getAnswers()); - $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); - if (isset($authors[$viewer->getPHID()])) { - $answer_add_panel = id(new PHUIInfoView()) - ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) - ->appendChild( - pht( - 'You have already answered this question. You can not answer '. - 'twice, but you can edit your existing answer.')); - } else { - $answer_add_panel = new PonderAddAnswerView(); - $answer_add_panel - ->setQuestion($question) - ->setUser($viewer) - ->setActionURI('/ponder/answer/add/'); - } + $answer_add_panel = id(new PonderAddAnswerView()) + ->setQuestion($question) + ->setUser($viewer) + ->setActionURI('/ponder/answer/add/'); $header = new PHUIHeaderView(); $header->setHeader($question->getTitle()); @@ -245,49 +234,6 @@ final class PonderQuestionViewController extends PonderController { return $view; } - private function wrapComments($n, $stuff) { - if ($n == 0) { - $text = pht('Add a Comment'); - } else { - $text = pht('Show %s Comments', new PhutilNumber($n)); - } - - $show_id = celerity_generate_unique_node_id(); - $hide_id = celerity_generate_unique_node_id(); - - Javelin::initBehavior('phabricator-reveal-content'); - require_celerity_resource('ponder-view-css'); - - $show = phutil_tag( - 'div', - array( - 'id' => $show_id, - 'class' => 'ponder-show-comments', - ), - javelin_tag( - 'a', - array( - 'href' => '#', - 'sigil' => 'reveal-content', - 'meta' => array( - 'showIDs' => array($hide_id), - 'hideIDs' => array($show_id), - ), - ), - $text)); - - $hide = phutil_tag( - 'div', - array( - 'class' => 'ponder-comments-view', - 'id' => $hide_id, - 'style' => 'display: none', - ), - $stuff); - - return array($show, $hide); - } - private function buildSidebar(PonderQuestion $question) { $viewer = $this->getViewer(); $status = $question->getStatus(); diff --git a/src/applications/ponder/view/PonderAddAnswerView.php b/src/applications/ponder/view/PonderAddAnswerView.php index 53e06074f7..5ffe99edc7 100644 --- a/src/applications/ponder/view/PonderAddAnswerView.php +++ b/src/applications/ponder/view/PonderAddAnswerView.php @@ -18,6 +18,28 @@ final class PonderAddAnswerView extends AphrontView { public function render() { $question = $this->question; + $viewer = $this->user; + + $authors = mpull($question->getAnswers(), null, 'getAuthorPHID'); + if (isset($authors[$viewer->getPHID()])) { + return id(new PHUIInfoView()) + ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) + ->setTitle(pht('Already Answered')) + ->appendChild( + pht( + 'You have already answered this question. You can not answer '. + 'twice, but you can edit your existing answer.')); + } + + $info_panel = null; + if ($question->getStatus() != PonderQuestionStatus::STATUS_OPEN) { + $info_panel = id(new PHUIInfoView()) + ->setSeverity(PHUIInfoView::SEVERITY_WARNING) + ->appendChild( + pht( + 'This question has been marked as closed, + but you can still leave a new answer.')); + } $header = id(new PHUIHeaderView()) ->setHeader(pht('Add Answer')); @@ -39,8 +61,14 @@ final class PonderAddAnswerView extends AphrontView { id(new AphrontFormSubmitControl()) ->setValue(pht('Add Answer'))); - return id(new PHUIObjectBoxView()) + $box = id(new PHUIObjectBoxView()) ->setHeader($header) ->appendChild($form); + + if ($info_panel) { + $box->setInfoView($info_panel); + } + + return $box; } } diff --git a/src/applications/ponder/view/PonderFooterView.php b/src/applications/ponder/view/PonderFooterView.php index 7e553b3f4b..8f55b86aeb 100644 --- a/src/applications/ponder/view/PonderFooterView.php +++ b/src/applications/ponder/view/PonderFooterView.php @@ -28,6 +28,7 @@ final class PonderFooterView extends AphrontTagView { } protected function getTagContent() { + require_celerity_resource('ponder-view-css'); Javelin::initBehavior('phabricator-reveal-content'); $hide_action_id = celerity_generate_unique_node_id();