From e4806631a5b3b9387c22fa186d48158564529e74 Mon Sep 17 00:00:00 2001 From: Chad Little Date: Thu, 5 Nov 2015 12:13:35 -0800 Subject: [PATCH] Use PHUIDocumentProView in Phame Summary: Updates "View Post" to use PHUIDocumentViewPro, updates calls to `newPage` and other minor modernizations. Edit Page updated to show proper document display as well. Ref T9545 Test Plan: Write a blog post, edit it. {F945897} {F945896} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Maniphest Tasks: T9545 Differential Revision: https://secure.phabricator.com/D14415 --- resources/celerity/map.php | 4 +- .../post/PhamePostEditController.php | 49 +++++---- .../post/PhamePostPreviewController.php | 9 +- .../post/PhamePostViewController.php | 101 +++++++++--------- webroot/rsrc/css/phui/phui-document-pro.css | 12 +-- 5 files changed, 88 insertions(+), 87 deletions(-) diff --git a/resources/celerity/map.php b/resources/celerity/map.php index 2e59acf3cc..91b57e9f5d 100644 --- a/resources/celerity/map.php +++ b/resources/celerity/map.php @@ -126,7 +126,7 @@ return array( 'rsrc/css/phui/phui-box.css' => 'a5bb366d', 'rsrc/css/phui/phui-button.css' => '16020a60', 'rsrc/css/phui/phui-crumbs-view.css' => 'd842f867', - 'rsrc/css/phui/phui-document-pro.css' => '61d70f8e', + 'rsrc/css/phui/phui-document-pro.css' => '4f2b42e3', 'rsrc/css/phui/phui-document.css' => '9fa715d2', 'rsrc/css/phui/phui-feed-story.css' => 'b7b26d23', 'rsrc/css/phui/phui-fontkit.css' => 'c9d63950', @@ -781,7 +781,7 @@ return array( 'phui-calendar-month-css' => '476be7e0', 'phui-crumbs-view-css' => 'd842f867', 'phui-document-view-css' => '9fa715d2', - 'phui-document-view-pro-css' => '61d70f8e', + 'phui-document-view-pro-css' => '4f2b42e3', 'phui-feed-story-css' => 'b7b26d23', 'phui-font-icon-base-css' => 'ecbbb4c2', 'phui-fontkit-css' => 'c9d63950', diff --git a/src/applications/phame/controller/post/PhamePostEditController.php b/src/applications/phame/controller/post/PhamePostEditController.php index e79d435deb..023040996a 100644 --- a/src/applications/phame/controller/post/PhamePostEditController.php +++ b/src/applications/phame/controller/post/PhamePostEditController.php @@ -3,12 +3,12 @@ final class PhamePostEditController extends PhameController { public function handleRequest(AphrontRequest $request) { - $user = $request->getUser(); + $viewer = $request->getViewer(); $id = $request->getURIData('id'); if ($id) { $post = id(new PhamePostQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withIDs(array($id)) ->requireCapabilities( array( @@ -29,7 +29,7 @@ final class PhamePostEditController extends PhameController { $v_projects = array_reverse($v_projects); } else { $blog = id(new PhameBlogQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withIDs(array($request->getInt('blog'))) ->requireCapabilities( array( @@ -42,7 +42,7 @@ final class PhamePostEditController extends PhameController { } $v_projects = array(); - $post = PhamePost::initializePost($user, $blog); + $post = PhamePost::initializePost($viewer, $blog); $cancel_uri = $this->getApplicationURI('/blog/view/'.$blog->getID().'/'); $submit_button = pht('Save Draft'); @@ -87,7 +87,7 @@ final class PhamePostEditController extends PhameController { ->setNewValue(array('=' => array_fuse($v_projects))); $editor = id(new PhamePostEditor()) - ->setActor($user) + ->setActor($viewer) ->setContentSourceFromRequest($request) ->setContinueOnNoEffect(true); @@ -106,12 +106,12 @@ final class PhamePostEditController extends PhameController { } $handle = id(new PhabricatorHandleQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withPHIDs(array($post->getBlogPHID())) ->executeOne(); $form = id(new AphrontFormView()) - ->setUser($user) + ->setUser($viewer) ->addHiddenInput('blog', $request->getInt('blog')) ->appendChild( id(new AphrontFormMarkupControl()) @@ -141,7 +141,7 @@ final class PhamePostEditController extends PhameController { ->setValue($body) ->setHeight(AphrontFormTextAreaControl::HEIGHT_VERY_TALL) ->setID('post-body') - ->setUser($user) + ->setUser($viewer) ->setDisableMacros(true)) ->appendControl( id(new AphrontFormTokenizerControl()) @@ -160,14 +160,18 @@ final class PhamePostEditController extends PhameController { ->addCancelButton($cancel_uri) ->setValue($submit_button)); - $loading = phutil_tag_div( - 'aphront-panel-preview-loading-text', - pht('Loading preview...')); + $header = id(new PHUIHeaderView()) + ->setHeader(pht('%s (Post Preview)', $title)); - $preview_panel = phutil_tag_div('aphront-panel-preview', array( - phutil_tag_div('phame-post-preview-header', pht('Post Preview')), - phutil_tag('div', array('id' => 'post-preview'), $loading), - )); + $container = id(new PHUIBoxView()) + ->setID('post-preview'); + + $document = id(new PHUIDocumentViewPro()) + ->setHeader($header) + ->appendChild($container); + + $preview_panel = id(new PHUIObjectBoxView()) + ->appendChild($document); Javelin::initBehavior( 'phame-post-preview', @@ -189,14 +193,13 @@ final class PhamePostEditController extends PhameController { $page_title, $this->getApplicationURI('/post/view/'.$id.'/')); - return $this->buildApplicationPage( - array( - $crumbs, - $form_box, - $preview_panel, - ), - array( - 'title' => $page_title, + return $this->newPage() + ->setTitle($page_title) + ->setCrumbs($crumbs) + ->appendChild( + array( + $form_box, + $preview_panel, )); } diff --git a/src/applications/phame/controller/post/PhamePostPreviewController.php b/src/applications/phame/controller/post/PhamePostPreviewController.php index 5b87ec680b..0140e48fe6 100644 --- a/src/applications/phame/controller/post/PhamePostPreviewController.php +++ b/src/applications/phame/controller/post/PhamePostPreviewController.php @@ -6,10 +6,9 @@ final class PhamePostPreviewController extends PhameController { return null; } - public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); - $body = $request->getStr('body'); + public function handleRequest(AphrontRequest $request) { + $viewer = $request->getViewer(); + $body = $request->getStr('body'); $post = id(new PhamePost()) ->setBody($body); @@ -17,7 +16,7 @@ final class PhamePostPreviewController extends PhameController { $content = PhabricatorMarkupEngine::renderOneObject( $post, PhamePost::MARKUP_FIELD_BODY, - $user); + $viewer); $content = phutil_tag_div('phabricator-remarkup', $content); diff --git a/src/applications/phame/controller/post/PhamePostViewController.php b/src/applications/phame/controller/post/PhamePostViewController.php index 1b2b8c1a3c..cc389568a6 100644 --- a/src/applications/phame/controller/post/PhamePostViewController.php +++ b/src/applications/phame/controller/post/PhamePostViewController.php @@ -3,10 +3,10 @@ final class PhamePostViewController extends PhameController { public function handleRequest(AphrontRequest $request) { - $user = $request->getUser(); + $viewer = $request->getViewer(); $post = id(new PhamePostQuery()) - ->setViewer($user) + ->setViewer($viewer) ->withIDs(array($request->getURIData('id'))) ->executeOne(); @@ -14,29 +14,35 @@ final class PhamePostViewController extends PhameController { return new Aphront404Response(); } - $nav = $this->renderSideNavFilterView(); - - $actions = $this->renderActions($post, $user); - $properties = $this->renderProperties($post, $user, $actions); - $crumbs = $this->buildApplicationCrumbs(); $crumbs->addTextCrumb( $post->getTitle(), $this->getApplicationURI('post/view/'.$post->getID().'/')); + $crumbs->setBorder(true); - $nav->appendChild($crumbs); + $actions = $this->renderActions($post, $viewer); + $properties = $this->renderProperties($post, $viewer); + + $action_button = id(new PHUIButtonView()) + ->setTag('a') + ->setText(pht('Actions')) + ->setHref('#') + ->setIconFont('fa-bars') + ->addClass('phui-mobile-menu') + ->setDropdownMenu($actions); $header = id(new PHUIHeaderView()) - ->setHeader($post->getTitle()) - ->setUser($user) - ->setPolicyObject($post); + ->setHeader($post->getTitle()) + ->setUser($viewer) + ->setPolicyObject($post) + ->addActionLink($action_button); - $object_box = id(new PHUIObjectBoxView()) + $document = id(new PHUIDocumentViewPro()) ->setHeader($header) - ->addPropertyList($properties); + ->setPropertyList($properties); if ($post->isDraft()) { - $object_box->appendChild( + $document->appendChild( id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_NOTICE) ->setTitle(pht('Draft Post')) @@ -47,7 +53,7 @@ final class PhamePostViewController extends PhameController { } if (!$post->getBlog()) { - $object_box->appendChild( + $document->appendChild( id(new PHUIInfoView()) ->setSeverity(PHUIInfoView::SEVERITY_WARNING) ->setTitle(pht('Not On A Blog')) @@ -57,32 +63,40 @@ final class PhamePostViewController extends PhameController { 'been deleted). Use "Move Post" to move it to a new blog.'))); } - $nav->appendChild( - array( - $object_box, - $this->buildTransactionTimeline( - $post, - new PhamePostTransactionQuery()), - )); + $engine = id(new PhabricatorMarkupEngine()) + ->setViewer($viewer) + ->addObject($post, PhamePost::MARKUP_FIELD_BODY) + ->process(); - return $this->buildApplicationPage( - $nav, - array( - 'title' => $post->getTitle(), + $document->appendChild( + phutil_tag( + 'div', + array( + 'class' => 'phabricator-remarkup', + ), + $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY))); + + return $this->newPage() + ->setTitle($post->getTitle()) + ->addClass('pro-white-background') + ->setCrumbs($crumbs) + ->appendChild( + array( + $document, )); } private function renderActions( PhamePost $post, - PhabricatorUser $user) { + PhabricatorUser $viewer) { $actions = id(new PhabricatorActionListView()) ->setObject($post) ->setObjectURI($this->getRequest()->getRequestURI()) - ->setUser($user); + ->setUser($viewer); $can_edit = PhabricatorPolicyFilter::hasCapability( - $user, + $viewer, $post, PhabricatorPolicyCapability::CAN_EDIT); @@ -139,7 +153,7 @@ final class PhamePostViewController extends PhameController { $actions->addAction( id(new PhabricatorActionView()) - ->setUser($user) + ->setUser($viewer) ->setIcon('fa-globe') ->setHref($live_uri) ->setName(pht('View Live')) @@ -151,43 +165,28 @@ final class PhamePostViewController extends PhameController { private function renderProperties( PhamePost $post, - PhabricatorUser $user, - PhabricatorActionListView $actions) { + PhabricatorUser $viewer) { $properties = id(new PHUIPropertyListView()) - ->setUser($user) - ->setObject($post) - ->setActionList($actions); + ->setUser($viewer) + ->setObject($post); $properties->addProperty( pht('Blog'), - $user->renderHandle($post->getBlogPHID())); + $viewer->renderHandle($post->getBlogPHID())); $properties->addProperty( pht('Blogger'), - $user->renderHandle($post->getBloggerPHID())); + $viewer->renderHandle($post->getBloggerPHID())); $properties->addProperty( pht('Published'), $post->isDraft() ? pht('Draft') - : phabricator_datetime($post->getDatePublished(), $user)); - - $engine = id(new PhabricatorMarkupEngine()) - ->setViewer($user) - ->addObject($post, PhamePost::MARKUP_FIELD_BODY) - ->process(); + : phabricator_datetime($post->getDatePublished(), $viewer)); $properties->invokeWillRenderEvent(); - $properties->addTextContent( - phutil_tag( - 'div', - array( - 'class' => 'phabricator-remarkup', - ), - $engine->getOutput($post, PhamePost::MARKUP_FIELD_BODY))); - return $properties; } diff --git a/webroot/rsrc/css/phui/phui-document-pro.css b/webroot/rsrc/css/phui/phui-document-pro.css index 39fa574e59..3408c5b094 100644 --- a/webroot/rsrc/css/phui/phui-document-pro.css +++ b/webroot/rsrc/css/phui/phui-document-pro.css @@ -3,7 +3,8 @@ */ .phui-document-view.phui-document-view-pro, -.phui-document-view-pro-box { +.phui-document-view-pro-box, +.phui-document-properties { max-width: 800px; padding: 0 16px; position: relative; @@ -11,15 +12,14 @@ } .phui-document-properties { - max-width: 800px; - padding: 0 16px; + max-width: 768px; background-color: {$lightgreybackground}; - margin: 0 auto; + margin: 16px auto; border-radius: 3px; } -.device-phone .phui-document-properties { - margin: 0 8px; +.device .phui-document-properties { + margin: 0 8px 16px; } .device-phone .phui-document-view.phui-document-view-pro {