From 18e8d9a452651aa465e9c87bc3fc28fc38d41c3b Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 29 Aug 2018 15:46:13 -0700 Subject: [PATCH] Make the Phriction "History" view more aware of drafts Summary: Ref T13077. Updates the "History" view to be slightly better organized and draft-aware. Test Plan: Viewed page history in Phriction. Reviewers: amckinley Maniphest Tasks: T13077 Differential Revision: https://secure.phabricator.com/D19626 --- .../controller/PhrictionHistoryController.php | 131 ++++++++++-------- src/view/phui/PHUIObjectItemView.php | 4 +- 2 files changed, 75 insertions(+), 60 deletions(-) diff --git a/src/applications/phriction/controller/PhrictionHistoryController.php b/src/applications/phriction/controller/PhrictionHistoryController.php index 2a3afc9769..3023d7dcce 100644 --- a/src/applications/phriction/controller/PhrictionHistoryController.php +++ b/src/applications/phriction/controller/PhrictionHistoryController.php @@ -31,32 +31,18 @@ final class PhrictionHistoryController ->executeWithCursorPager($pager); $author_phids = mpull($history, 'getAuthorPHID'); - $handles = $this->loadViewerHandles($author_phids); + $handles = $viewer->loadHandles($author_phids); + + $max_version = (int)$document->getMaxVersion(); + $current_version = $document->getContent()->getVersion(); $list = new PHUIObjectItemListView(); $list->setFlush(true); - foreach ($history as $content) { - - $author = $handles[$content->getAuthorPHID()]->renderLink(); $slug_uri = PhrictionDocument::getSlugURI($document->getSlug()); $version = $content->getVersion(); - $diff_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/'); - - $vs_previous = null; - if ($content->getVersion() != 1) { - $vs_previous = $diff_uri - ->alter('l', $content->getVersion() - 1) - ->alter('r', $content->getVersion()); - } - - $vs_head = null; - if ($content->getPHID() != $document->getContentPHID()) { - $vs_head = $diff_uri - ->alter('l', $content->getVersion()) - ->alter('r', $current->getVersion()); - } + $base_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/'); $change_type = PhrictionChangeType::getChangeTypeLabel( $content->getChangeType()); @@ -68,63 +54,90 @@ final class PhrictionHistoryController $color = 'lightbluetext'; break; case PhrictionChangeType::CHANGE_MOVE_HERE: - $color = 'yellow'; + $color = 'yellow'; break; case PhrictionChangeType::CHANGE_MOVE_AWAY: - $color = 'orange'; + $color = 'orange'; break; case PhrictionChangeType::CHANGE_STUB: $color = 'green'; break; default: - throw new Exception(pht('Unknown change type!')); + $color = 'indigo'; break; } + $version_uri = $slug_uri.'?v='.$version; + $item = id(new PHUIObjectItemView()) - ->setHeader(pht('%s by %s', $change_type, $author)) - ->setStatusIcon('fa-file '.$color) - ->addAttribute( - phutil_tag( - 'a', - array( - 'href' => $slug_uri.'?v='.$version, - ), - pht('Version %s', $version))) - ->addAttribute(pht('%s %s', - phabricator_date($content->getDateCreated(), $viewer), - phabricator_time($content->getDateCreated(), $viewer))); + ->setHref($version_uri); - if ($content->getDescription()) { - $item->addAttribute($content->getDescription()); - } - - if ($vs_previous) { - $item->addIcon( - 'fa-reply', - pht('Show Change'), - array( - 'href' => $vs_previous, - )); + if ($version > $current_version) { + $icon = 'fa-spinner'; + $color = 'pink'; + $header = pht('Draft %d', $version); } else { - $item->addIcon( - 'fa-reply grey', - phutil_tag('em', array(), pht('No previous change'))); + $icon = 'fa-file-o'; + $header = pht('Version %d', $version); } - if ($vs_head) { - $item->addIcon( - 'fa-reply-all', - pht('Show Later Changes'), - array( - 'href' => $vs_head, - )); - } else { - $item->addIcon( - 'fa-reply-all grey', - phutil_tag('em', array(), pht('No later changes'))); + if ($version == $current_version) { + $item->setEffect('selected'); } + $item + ->setHeader($header) + ->setStatusIcon($icon.' '.$color); + + $description = $content->getDescription(); + if (strlen($description)) { + $item->addAttribute($description); + } + + $item->addIcon( + null, + phabricator_datetime($content->getDateCreated(), $viewer)); + + $author_phid = $content->getAuthorPHID(); + $item->addByline($viewer->renderHandle($author_phid)); + + $diff_uri = null; + if ($version > 1) { + $diff_uri = $base_uri + ->alter('l', $version - 1) + ->alter('r', $version); + } else { + $diff_uri = null; + } + + if ($content->getVersion() != $max_version) { + $compare_uri = $base_uri + ->alter('l', $version) + ->alter('r', $max_version); + } else { + $compare_uri = null; + } + + $button_bar = id(new PHUIButtonBarView()) + ->addButton( + id(new PHUIButtonView()) + ->setTag('a') + ->setColor('grey') + ->setIcon('fa-chevron-down') + ->setDisabled(!$diff_uri) + ->setHref($diff_uri) + ->setText(pht('Diff'))) + ->addButton( + id(new PHUIButtonView()) + ->setTag('a') + ->setColor('grey') + ->setIcon('fa-chevron-circle-up') + ->setDisabled(!$compare_uri) + ->setHref($compare_uri) + ->setText(pht('Compare'))); + + $item->setSideColumn($button_bar); + $list->addItem($item); } diff --git a/src/view/phui/PHUIObjectItemView.php b/src/view/phui/PHUIObjectItemView.php index c1e57632c4..0657086c49 100644 --- a/src/view/phui/PHUIObjectItemView.php +++ b/src/view/phui/PHUIObjectItemView.php @@ -709,8 +709,9 @@ final class PHUIObjectItemView extends AphrontTagView { } /* Fixed width, right column container. */ + $column3 = null; if ($this->sideColumn) { - $column2 = phutil_tag( + $column3 = phutil_tag( 'div', array( 'class' => 'phui-oi-col2 phui-oi-side-column', @@ -731,6 +732,7 @@ final class PHUIObjectItemView extends AphrontTagView { $column0, $column1, $column2, + $column3, ))); $box = phutil_tag(