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

View file

@ -47,6 +47,7 @@ final class PhabricatorPhameApplication extends PhabricatorApplication {
'edit/(?:(?P<id>[^/]+)/)?' => 'PhamePostEditController',
'view/(?P<id>\d+)/' => 'PhamePostViewController',
'publish/(?P<id>\d+)/' => 'PhamePostPublishController',
'preview/(?P<id>\d+)/' => 'PhamePostPreviewController',
'unpublish/(?P<id>\d+)/' => 'PhamePostUnpublishController',
'notlive/(?P<id>\d+)/' => 'PhamePostNotLiveController',
'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();
}
$view_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
if ($request->isFormPost()) {
$xactions = array();
$xactions[] = id(new PhamePostTransaction())
@ -33,52 +31,22 @@ final class PhamePostPublishController extends PhamePostController {
->setContinueOnMissingFields(true)
->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())
->setUser($viewer)
$cancel_uri = $this->getApplicationURI('/post/view/'.$post->getID().'/');
$dialog = $this->newDialog()
->setTitle(pht('Publish Post?'))
->appendChild(
id(new AphrontFormSubmitControl())
->setValue(pht('Publish Post'))
->addCancelButton($view_uri));
pht(
'The post "%s" will go live once you publish it.',
$post->getTitle()))
->addSubmitButton(pht('Publish'))
->addCancelButton($cancel_uri);
$frame = $this->renderPreviewFrame($post);
$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().'/'),
),
''));
return id(new AphrontDialogResponse())->setDialog($dialog);
}
}

View file

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

View file

@ -63,7 +63,7 @@ final class PhamePostViewController extends PhamePostController {
->appendChild(
pht(
'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()) {
@ -150,7 +150,14 @@ final class PhamePostViewController extends PhamePostController {
->setIcon('fa-eye')
->setHref($this->getApplicationURI('post/publish/'.$id.'/'))
->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 {
$actions->addAction(
id(new PhabricatorActionView())

View file

@ -209,8 +209,21 @@ final class PhamePostEditor
$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()) {
$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(

View file

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