Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionHistoryController.php
Show All 25 Lines | $pager = id(new AphrontCursorPagerView()) | ||||
->readFromRequest($request); | ->readFromRequest($request); | ||||
$history = id(new PhrictionContentQuery()) | $history = id(new PhrictionContentQuery()) | ||||
->setViewer($viewer) | ->setViewer($viewer) | ||||
->withDocumentPHIDs(array($document->getPHID())) | ->withDocumentPHIDs(array($document->getPHID())) | ||||
->executeWithCursorPager($pager); | ->executeWithCursorPager($pager); | ||||
$author_phids = mpull($history, 'getAuthorPHID'); | $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 = new PHUIObjectItemListView(); | ||||
$list->setFlush(true); | $list->setFlush(true); | ||||
foreach ($history as $content) { | foreach ($history as $content) { | ||||
$author = $handles[$content->getAuthorPHID()]->renderLink(); | |||||
$slug_uri = PhrictionDocument::getSlugURI($document->getSlug()); | $slug_uri = PhrictionDocument::getSlugURI($document->getSlug()); | ||||
$version = $content->getVersion(); | $version = $content->getVersion(); | ||||
$diff_uri = new PhutilURI('/phriction/diff/'.$document->getID().'/'); | $base_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()); | |||||
} | |||||
$change_type = PhrictionChangeType::getChangeTypeLabel( | $change_type = PhrictionChangeType::getChangeTypeLabel( | ||||
$content->getChangeType()); | $content->getChangeType()); | ||||
switch ($content->getChangeType()) { | switch ($content->getChangeType()) { | ||||
case PhrictionChangeType::CHANGE_DELETE: | case PhrictionChangeType::CHANGE_DELETE: | ||||
$color = 'red'; | $color = 'red'; | ||||
break; | break; | ||||
case PhrictionChangeType::CHANGE_EDIT: | case PhrictionChangeType::CHANGE_EDIT: | ||||
$color = 'lightbluetext'; | $color = 'lightbluetext'; | ||||
break; | break; | ||||
case PhrictionChangeType::CHANGE_MOVE_HERE: | case PhrictionChangeType::CHANGE_MOVE_HERE: | ||||
$color = 'yellow'; | $color = 'yellow'; | ||||
break; | break; | ||||
case PhrictionChangeType::CHANGE_MOVE_AWAY: | case PhrictionChangeType::CHANGE_MOVE_AWAY: | ||||
$color = 'orange'; | $color = 'orange'; | ||||
break; | break; | ||||
case PhrictionChangeType::CHANGE_STUB: | case PhrictionChangeType::CHANGE_STUB: | ||||
$color = 'green'; | $color = 'green'; | ||||
break; | break; | ||||
default: | default: | ||||
throw new Exception(pht('Unknown change type!')); | $color = 'indigo'; | ||||
break; | break; | ||||
} | } | ||||
$version_uri = $slug_uri.'?v='.$version; | |||||
$item = id(new PHUIObjectItemView()) | $item = id(new PHUIObjectItemView()) | ||||
->setHeader(pht('%s by %s', $change_type, $author)) | ->setHref($version_uri); | ||||
->setStatusIcon('fa-file '.$color) | |||||
->addAttribute( | if ($version > $current_version) { | ||||
phutil_tag( | $icon = 'fa-spinner'; | ||||
'a', | $color = 'pink'; | ||||
array( | $header = pht('Draft %d', $version); | ||||
'href' => $slug_uri.'?v='.$version, | } else { | ||||
), | $icon = 'fa-file-o'; | ||||
pht('Version %s', $version))) | $header = pht('Version %d', $version); | ||||
->addAttribute(pht('%s %s', | } | ||||
phabricator_date($content->getDateCreated(), $viewer), | |||||
phabricator_time($content->getDateCreated(), $viewer))); | |||||
if ($content->getDescription()) { | if ($version == $current_version) { | ||||
$item->addAttribute($content->getDescription()); | $item->setEffect('selected'); | ||||
} | |||||
$item | |||||
->setHeader($header) | |||||
->setStatusIcon($icon.' '.$color); | |||||
$description = $content->getDescription(); | |||||
if (strlen($description)) { | |||||
$item->addAttribute($description); | |||||
} | } | ||||
if ($vs_previous) { | |||||
$item->addIcon( | $item->addIcon( | ||||
'fa-reply', | null, | ||||
pht('Show Change'), | phabricator_datetime($content->getDateCreated(), $viewer)); | ||||
array( | |||||
'href' => $vs_previous, | $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 { | } else { | ||||
$item->addIcon( | $diff_uri = null; | ||||
'fa-reply grey', | |||||
phutil_tag('em', array(), pht('No previous change'))); | |||||
} | } | ||||
if ($vs_head) { | if ($content->getVersion() != $max_version) { | ||||
$item->addIcon( | $compare_uri = $base_uri | ||||
'fa-reply-all', | ->alter('l', $version) | ||||
pht('Show Later Changes'), | ->alter('r', $max_version); | ||||
array( | |||||
'href' => $vs_head, | |||||
)); | |||||
} else { | } else { | ||||
$item->addIcon( | $compare_uri = null; | ||||
'fa-reply-all grey', | |||||
phutil_tag('em', array(), pht('No later changes'))); | |||||
} | } | ||||
$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); | $list->addItem($item); | ||||
} | } | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumb_views = $this->renderBreadcrumbs($document->getSlug()); | $crumb_views = $this->renderBreadcrumbs($document->getSlug()); | ||||
foreach ($crumb_views as $view) { | foreach ($crumb_views as $view) { | ||||
$crumbs->addCrumb($view); | $crumbs->addCrumb($view); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 41 Lines • Show Last 20 Lines |