1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-19 05:12:41 +01:00

Clean up Phame Preview

Summary: This adds a separate Publish/Unpublish step aside from Preview in Phame Posts. This allows easier access to publishing without previewing, though I left publish in tact on the preview page. Also cleaned up some minor transaction issues with mail.

Test Plan: New Post, Publish Post, Preview Post. Check mail logs. Get mail upon publish.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: Korvin

Differential Revision: https://secure.phabricator.com/D14642
This commit is contained in:
Chad Little 2015-12-02 13:27:56 -08:00
parent 9104867c71
commit dd82cd4922
8 changed files with 128 additions and 52 deletions

View file

@ -3331,6 +3331,7 @@ phutil_register_library_map(array(
'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php', 'PhamePostMailReceiver' => 'applications/phame/mail/PhamePostMailReceiver.php',
'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php', 'PhamePostNewController' => 'applications/phame/controller/post/PhamePostNewController.php',
'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php', 'PhamePostNotLiveController' => 'applications/phame/controller/post/PhamePostNotLiveController.php',
'PhamePostPreviewController' => 'applications/phame/controller/post/PhamePostPreviewController.php',
'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php', 'PhamePostPublishController' => 'applications/phame/controller/post/PhamePostPublishController.php',
'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php', 'PhamePostQuery' => 'applications/phame/query/PhamePostQuery.php',
'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php', 'PhamePostReplyHandler' => 'applications/phame/mail/PhamePostReplyHandler.php',
@ -7670,6 +7671,7 @@ phutil_register_library_map(array(
'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver', 'PhamePostMailReceiver' => 'PhabricatorObjectMailReceiver',
'PhamePostNewController' => 'PhamePostController', 'PhamePostNewController' => 'PhamePostController',
'PhamePostNotLiveController' => 'PhamePostController', 'PhamePostNotLiveController' => 'PhamePostController',
'PhamePostPreviewController' => 'PhamePostController',
'PhamePostPublishController' => 'PhamePostController', 'PhamePostPublishController' => 'PhamePostController',
'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 'PhamePostQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler', 'PhamePostReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',

View file

@ -47,6 +47,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController', 'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController',
'view/(?P<id>\d+)/' => 'PhamePostViewController', 'view/(?P<id>\d+)/' => 'PhamePostViewController',
'publish/(?P<id>\d+)/' => 'PhamePostPublishController', 'publish/(?P<id>\d+)/' => 'PhamePostPublishController',
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController', 'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController',
'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController', 'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController',
'preview/' => 'PhabricatorMarkupPreviewController', 'preview/' => 'PhabricatorMarkupPreviewController',

View file

@ -0,0 +1,89 @@
<?php
final class PhamePostPreviewController extends PhamePostController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$post = id(new PhamePostQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$post) {
return new Aphront404Response();
}
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PhamePostTransaction())
->setTransactionType(PhamePostTransaction::TYPE_VISIBILITY)
->setNewValue(PhameConstants::VISIBILITY_PUBLISHED);
id(new PhamePostEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true)
->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri);
}
$form = id(new AphrontFormView())
->setUser($viewer)
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Publish Post'))
->addCancelButton($view_uri));
$frame = $this->renderPreviewFrame($post);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Preview Post'))
->setForm($form);
$blog = $post->getBlog();
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(
$blog->getName(),
$this->getApplicationURI('blog/view/'.$blog->getID().'/'));
$crumbs->addTextCrumb(pht('Preview Post'), $view_uri);
return $this->newPage()
->setTitle(pht('Preview Post'))
->setCrumbs($crumbs)
->appendChild(
array(
$form_box,
$frame,
));
}
private function renderPreviewFrame(PhamePost $post) {
return phutil_tag(
'div',
array(
'style' => 'text-align: center; padding: 16px;',
),
phutil_tag(
'iframe',
array(
'style' => 'width: 100%; height: 800px; '.
'border: 1px solid #BFCFDA; '.
'background-color: #fff; '.
'border-radius: 3px; ',
'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
),
''));
}
}

View file

@ -18,8 +18,6 @@ final class PhamePostPublishController extends PhamePostController {
return new Aphront404Response(); return new Aphront404Response();
} }
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
if ($request->isFormPost()) { if ($request->isFormPost()) {
$xactions = array(); $xactions = array();
$xactions[] = id(new PhamePostTransaction()) $xactions[] = id(new PhamePostTransaction())
@ -33,52 +31,22 @@ final class PhamePostPublishController extends PhamePostController {
->setContinueOnMissingFields(true) ->setContinueOnMissingFields(true)
->applyTransactions($post, $xactions); ->applyTransactions($post, $xactions);
return id(new AphrontRedirectResponse())->setURI($view_uri); return id(new AphrontRedirectResponse())
->setURI($this->getApplicationURI('/post/view/'.$post->getID().'/'));
} }
$form = id(new AphrontFormView()) $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
->setUser($viewer)
$dialog = $this->newDialog()
->setTitle(pht('Publish Post?'))
->appendChild( ->appendChild(
id(new AphrontFormSubmitControl()) pht(
->setValue(pht('Publish Post')) 'The post "%s" will go live once you publish it.',
->addCancelButton($view_uri)); $post->getTitle()))
->addSubmitButton(pht('Publish'))
->addCancelButton($cancel_uri);
$frame = $this->renderPreviewFrame($post); return id(new AphrontDialogResponse())->setDialog($dialog);
$form_box = id(new PHUIObjectBoxView())
->setHeaderText(pht('Preview Post'))
->setForm($form);
$crumbs = $this->buildApplicationCrumbs();
$crumbs->addTextCrumb(pht('Preview'), $view_uri);
return $this->newPage()
->setTitle(pht('Preview Post'))
->setCrumbs($crumbs)
->appendChild(
array(
$form_box,
$frame,
));
}
private function renderPreviewFrame(PhamePost $post) {
return phutil_tag(
'div',
array(
'style' => 'text-align: center; padding: 16px;',
),
phutil_tag(
'iframe',
array(
'style' => 'width: 100%; height: 600px; '.
'border: 1px solid #BFCFDA; '.
'background-color: #fff; '.
'border-radius: 3px; ',
'src' => $this->getApplicationURI('/post/framed/'.$post->getID().'/'),
),
''));
} }
} }

View file

@ -37,8 +37,7 @@ final class PhamePostUnpublishController extends PhamePostController {
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/'); $cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
$dialog = id(new AphrontDialogView()) $dialog = $this->newDialog()
->setUser($viewer)
->setTitle(pht('Unpublish Post?')) ->setTitle(pht('Unpublish Post?'))
->appendChild( ->appendChild(
pht( pht(

View file

@ -63,7 +63,7 @@ final class PhamePostViewController extends PhamePostController {
->appendChild( ->appendChild(
pht( pht(
'Only you can see this draft until you publish it. '. 'Only you can see this draft until you publish it. '.
'Use "Preview / Publish" to publish this post.'))); 'Use "Preview or Publish" to publish this post.')));
} }
if (!$post->getBlog()) { if (!$post->getBlog()) {
@ -150,7 +150,14 @@ final class PhamePostViewController extends PhamePostController {
->setIcon('fa-eye') ->setIcon('fa-eye')
->setHref($this->getApplicationURI('post/publish/'.$id.'/')) ->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
->setDisabled(!$can_edit) ->setDisabled(!$can_edit)
->setName(pht('Preview / Publish'))); ->setName(pht('Publish'))
->setWorkflow(true));
$actions->addAction(
id(new PhabricatorActionView())
->setIcon('fa-eye')
->setHref($this->getApplicationURI('post/preview/'.$id.'/'))
->setDisabled(!$can_edit)
->setName(pht('Preview in Skin')));
} else { } else {
$actions->addAction( $actions->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())

View file

@ -209,8 +209,21 @@ final class PhamePostEditor
$body = parent::buildMailBody($object, $xactions); $body = parent::buildMailBody($object, $xactions);
// We don't send mail if the object is a draft, and we only want
// to include the full body of the post on the either the
// first creation or if it was created as a draft, once it goes live.
if ($this->getIsNewObject()) { if ($this->getIsNewObject()) {
$body->addRemarkupSection(null, $object->getBody()); $body->addRemarkupSection(null, $object->getBody());
} else {
foreach ($xactions as $xaction) {
switch ($xaction->getTransactionType()) {
case PhamePostTransaction::TYPE_VISIBILITY:
if (!$object->isDraft()) {
$body->addRemarkupSection(null, $object->getBody());
}
break;
}
}
} }
$body->addLinkSection( $body->addLinkSection(

View file

@ -206,10 +206,7 @@ final class PhamePostTransaction
} }
if (strlen($text)) { if (strlen($text)) {
return phutil_escape_html_newlines( return PhabricatorMarkupEngine::summarize($text);
id(new PhutilUTF8StringTruncator())
->setMaximumGlyphs(128)
->truncateString($text));
} }
return parent::getBodyForFeed($story); return parent::getBodyForFeed($story);