1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 08:42:41 +01:00

Add a UI element for navigating between versions of a Phriction document

Summary: Depends on D19621. Ref T13077. Fixes T4815. This adds previous/current/next/draft buttons and makes navigation between unpublished and published versions of a document more clear.

Test Plan: {F5841997}

Reviewers: amckinley

Maniphest Tasks: T13077, T4815

Differential Revision: https://secure.phabricator.com/D19622
This commit is contained in:
epriestley 2018-08-29 09:31:32 -07:00
parent 349686319e
commit 876638e428
3 changed files with 147 additions and 21 deletions

View file

@ -148,7 +148,7 @@ return array(
'rsrc/css/phui/phui-curtain-view.css' => '2bdaf026', 'rsrc/css/phui/phui-curtain-view.css' => '2bdaf026',
'rsrc/css/phui/phui-document-pro.css' => '0e41dd91', 'rsrc/css/phui/phui-document-pro.css' => '0e41dd91',
'rsrc/css/phui/phui-document-summary.css' => '9ca48bdf', 'rsrc/css/phui/phui-document-summary.css' => '9ca48bdf',
'rsrc/css/phui/phui-document.css' => '552493fa', 'rsrc/css/phui/phui-document.css' => 'c4ac41f9',
'rsrc/css/phui/phui-feed-story.css' => '44a9c8e9', 'rsrc/css/phui/phui-feed-story.css' => '44a9c8e9',
'rsrc/css/phui/phui-fontkit.css' => '1320ed01', 'rsrc/css/phui/phui-fontkit.css' => '1320ed01',
'rsrc/css/phui/phui-form-view.css' => 'f808e5be', 'rsrc/css/phui/phui-form-view.css' => 'f808e5be',
@ -813,7 +813,7 @@ return array(
'phui-crumbs-view-css' => '10728aaa', 'phui-crumbs-view-css' => '10728aaa',
'phui-curtain-view-css' => '2bdaf026', 'phui-curtain-view-css' => '2bdaf026',
'phui-document-summary-view-css' => '9ca48bdf', 'phui-document-summary-view-css' => '9ca48bdf',
'phui-document-view-css' => '552493fa', 'phui-document-view-css' => 'c4ac41f9',
'phui-document-view-pro-css' => '0e41dd91', 'phui-document-view-pro-css' => '0e41dd91',
'phui-feed-story-css' => '44a9c8e9', 'phui-feed-story-css' => '44a9c8e9',
'phui-font-icon-base-css' => '870a7360', 'phui-font-icon-base-css' => '870a7360',

View file

@ -20,8 +20,6 @@ final class PhrictionDocumentController
return id(new AphrontRedirectResponse())->setURI($uri); return id(new AphrontRedirectResponse())->setURI($uri);
} }
require_celerity_resource('phriction-document-css');
$version_note = null; $version_note = null;
$core_content = ''; $core_content = '';
$move_notice = ''; $move_notice = '';
@ -29,6 +27,8 @@ final class PhrictionDocumentController
$content = null; $content = null;
$toc = null; $toc = null;
$is_draft = false;
$document = id(new PhrictionDocumentQuery()) $document = id(new PhrictionDocumentQuery())
->setViewer($viewer) ->setViewer($viewer)
->withSlugs(array($slug)) ->withSlugs(array($slug))
@ -66,8 +66,14 @@ final class PhrictionDocumentController
->addAction($create_button); ->addAction($create_button);
} else { } else {
$version = $request->getInt('v'); $draft_content = id(new PhrictionContentQuery())
->setViewer($viewer)
->withDocumentPHIDs(array($document->getPHID()))
->setLimit(1)
->executeOne();
$max_version = (int)$draft_content->getVersion();
$version = $request->getInt('v');
if ($version) { if ($version) {
$content = id(new PhrictionContentQuery()) $content = id(new PhrictionContentQuery())
->setViewer($viewer) ->setViewer($viewer)
@ -78,15 +84,111 @@ final class PhrictionDocumentController
return new Aphront404Response(); return new Aphront404Response();
} }
if ($content->getPHID() != $document->getContentPHID()) { // When the "v" parameter exists, the user is in history mode so we
$version_note = id(new PHUIInfoView()) // show this header even if they're looking at the current version
->setSeverity(PHUIInfoView::SEVERITY_NOTICE) // of the document. This keeps the next/previous links working.
->appendChild(
pht( $view_version = (int)$content->getVersion();
'You are viewing an older version of this document, as it '. $published_version = (int)$document->getContent()->getVersion();
'appeared on %s.',
phabricator_datetime($content->getDateCreated(), $viewer))); if ($view_version < $published_version) {
$version_note = pht(
'You are viewing an older version of this document, as it '.
'appeared on %s.',
phabricator_datetime($content->getDateCreated(), $viewer));
} else if ($view_version > $published_version) {
$is_draft = true;
$version_note = pht(
'You are viewing an unpublished draft of this document.');
} else {
$version_note = pht(
'You are viewing the current published version of this document.');
} }
$version_note = array(
phutil_tag(
'strong',
array(),
pht('Version %d of %d: ', $view_version, $max_version)),
' ',
$version_note,
);
$version_note = id(new PHUIInfoView())
->setSeverity(PHUIInfoView::SEVERITY_NOTICE)
->appendChild($version_note);
$document_uri = new PhutilURI($document->getURI());
if ($view_version > 1) {
$previous_uri = $document_uri->alter('v', ($view_version - 1));
} else {
$previous_uri = null;
}
if ($view_version !== $published_version) {
$current_uri = $document_uri->alter('v', $published_version);
} else {
$current_uri = null;
}
if ($view_version < $max_version) {
$next_uri = $document_uri->alter('v', ($view_version + 1));
} else {
$next_uri = null;
}
if ($view_version !== $max_version) {
$draft_uri = $document_uri->alter('v', $max_version);
} else {
$draft_uri = null;
}
$button_bar = id(new PHUIButtonBarView())
->addButton(
id(new PHUIButtonView())
->setTag('a')
->setColor('grey')
->setIcon('fa-backward')
->setDisabled(!$previous_uri)
->setHref($previous_uri)
->setText(pht('Previous')))
->addButton(
id(new PHUIButtonView())
->setTag('a')
->setColor('grey')
->setIcon('fa-file-o')
->setDisabled(!$current_uri)
->setHref($current_uri)
->setText(pht('Published')))
->addButton(
id(new PHUIButtonView())
->setTag('a')
->setColor('grey')
->setIcon('fa-forward', false)
->setDisabled(!$next_uri)
->setHref($next_uri)
->setText(pht('Next')))
->addButton(
id(new PHUIButtonView())
->setTag('a')
->setColor('grey')
->setIcon('fa-fast-forward', false)
->setDisabled(!$draft_uri)
->setHref($draft_uri)
->setText(pht('Draft')));
require_celerity_resource('phui-document-view-css');
$version_note = array(
$version_note,
phutil_tag(
'div',
array(
'class' => 'phui-document-version-navigation',
),
$button_bar),
);
} else { } else {
$content = $document->getContent(); $content = $document->getContent();
} }
@ -218,7 +320,15 @@ final class PhrictionDocumentController
->setPolicyObject($document) ->setPolicyObject($document)
->setHeader($page_title); ->setHeader($page_title);
if ($content) { if ($is_draft) {
$draft_tag = id(new PHUITagView())
->setName(pht('Draft'))
->setIcon('fa-spinner')
->setColor('pink')
->setType(PHUITagView::TYPE_SHADE);
$header->addTag($draft_tag);
} else if ($content) {
$header->setEpoch($content->getDateCreated()); $header->setEpoch($content->getDateCreated());
} }
@ -299,21 +409,37 @@ final class PhrictionDocumentController
->setIcon('fa-pencil') ->setIcon('fa-pencil')
->setHref('/phriction/edit/'.$document->getID().'/')); ->setHref('/phriction/edit/'.$document->getID().'/'));
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setIcon('fa-history')
->setHref(PhrictionDocument::getSlugURI($slug, 'history')));
$is_current = false; $is_current = false;
$content_id = null; $content_id = null;
$is_draft = false;
if ($content) { if ($content) {
if ($content->getPHID() == $document->getContentPHID()) { if ($content->getPHID() == $document->getContentPHID()) {
$is_current = true; $is_current = true;
} }
$content_id = $content->getID(); $content_id = $content->getID();
$current_version = $document->getContent()->getVersion();
$is_draft = ($content->getVersion() >= $current_version);
} }
$can_publish = ($can_edit && $content && !$is_current); $can_publish = ($can_edit && $content && !$is_current);
if ($is_draft) {
$publish_name = pht('Publish Draft');
} else {
$publish_name = pht('Publish Revert');
}
$publish_uri = "/phriction/publish/{$id}/{$content_id}/"; $publish_uri = "/phriction/publish/{$id}/{$content_id}/";
$curtain->addAction( $curtain->addAction(
id(new PhabricatorActionView()) id(new PhabricatorActionView())
->setName(pht('Publish')) ->setName($publish_name)
->setIcon('fa-upload') ->setIcon('fa-upload')
->setDisabled(!$can_publish) ->setDisabled(!$can_publish)
->setWorkflow(true) ->setWorkflow(true)
@ -337,12 +463,6 @@ final class PhrictionDocumentController
->setWorkflow(true)); ->setWorkflow(true));
} }
$curtain->addAction(
id(new PhabricatorActionView())
->setName(pht('View History'))
->setIcon('fa-list')
->setHref(PhrictionDocument::getSlugURI($slug, 'history')));
$print_uri = PhrictionDocument::getSlugURI($slug).'?__print__=1'; $print_uri = PhrictionDocument::getSlugURI($slug).'?__print__=1';
$curtain->addAction( $curtain->addAction(

View file

@ -100,3 +100,9 @@
.remarkup-code { .remarkup-code {
font: 13px/18px "Menlo", "Consolas", "Monaco", monospace; font: 13px/18px "Menlo", "Consolas", "Monaco", monospace;
} }
.phui-document-version-navigation {
text-align: center;
padding: 8px;
background-color: {$lightgreybackground};
}