Changeset View
Changeset View
Standalone View
Standalone View
src/applications/phriction/controller/PhrictionDiffController.php
Show First 20 Lines • Show All 92 Lines • ▼ Show 20 Lines | public function handleRequest(AphrontRequest $request) { | ||||
$changes = id(new DifferentialChangesetListView()) | $changes = id(new DifferentialChangesetListView()) | ||||
->setUser($this->getViewer()) | ->setUser($this->getViewer()) | ||||
->setChangesets(array($changeset)) | ->setChangesets(array($changeset)) | ||||
->setVisibleChangesets(array($changeset)) | ->setVisibleChangesets(array($changeset)) | ||||
->setRenderingReferences(array("{$l},{$r}")) | ->setRenderingReferences(array("{$l},{$r}")) | ||||
->setRenderURI('/phriction/diff/'.$document->getID().'/') | ->setRenderURI('/phriction/diff/'.$document->getID().'/') | ||||
->setTitle(pht('Changes')) | ->setTitle(pht('Changes')) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->setParser($parser); | ->setParser($parser); | ||||
require_celerity_resource('phriction-document-css'); | require_celerity_resource('phriction-document-css'); | ||||
$slug = $document->getSlug(); | $slug = $document->getSlug(); | ||||
$revert_l = $this->renderRevertButton($content_l, $current); | $revert_l = $this->renderRevertButton($content_l, $current); | ||||
$revert_r = $this->renderRevertButton($content_r, $current); | $revert_r = $this->renderRevertButton($content_r, $current); | ||||
$crumbs = $this->buildApplicationCrumbs(); | $crumbs = $this->buildApplicationCrumbs(); | ||||
$crumb_views = $this->renderBreadcrumbs($slug); | $crumb_views = $this->renderBreadcrumbs($slug); | ||||
foreach ($crumb_views as $view) { | foreach ($crumb_views as $view) { | ||||
$crumbs->addCrumb($view); | $crumbs->addCrumb($view); | ||||
} | } | ||||
$crumbs->addTextCrumb( | $crumbs->addTextCrumb( | ||||
pht('History'), | pht('History'), | ||||
PhrictionDocument::getSlugURI($slug, 'history')); | PhrictionDocument::getSlugURI($slug, 'history')); | ||||
$title = pht('Version %s vs %s', $l, $r); | $title = pht('Version %s vs %s', $l, $r); | ||||
$header = id(new PHUIHeaderView()) | $header = id(new PHUIHeaderView()) | ||||
->setHeader($title) | ->setHeader($title) | ||||
->setTall(true); | ->setHeaderIcon('fa-history'); | ||||
$crumbs->addTextCrumb($title, $request->getRequestURI()); | $crumbs->addTextCrumb($title, $request->getRequestURI()); | ||||
$comparison_table = $this->renderComparisonTable( | $comparison_table = $this->renderComparisonTable( | ||||
array( | array( | ||||
$content_r, | $content_r, | ||||
$content_l, | $content_l, | ||||
)); | )); | ||||
$navigation_table = null; | $navigation_table = null; | ||||
if ($l + 1 == $r) { | if ($l + 1 == $r) { | ||||
$nav_l = ($l > 1); | $nav_l = ($l > 1); | ||||
$nav_r = ($r != $current->getVersion()); | $nav_r = ($r != $current->getVersion()); | ||||
$uri = $request->getRequestURI(); | $uri = $request->getRequestURI(); | ||||
if ($nav_l) { | if ($nav_l) { | ||||
$link_l = phutil_tag( | $link_l = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $uri->alter('l', $l - 1)->alter('r', $r - 1), | 'href' => $uri->alter('l', $l - 1)->alter('r', $r - 1), | ||||
'class' => 'button simple', | 'class' => 'button grey', | ||||
), | ), | ||||
pht("\xC2\xAB Previous Change")); | pht("\xC2\xAB Previous Change")); | ||||
} else { | } else { | ||||
$link_l = phutil_tag( | $link_l = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '#', | 'href' => '#', | ||||
'class' => 'button grey disabled', | 'class' => 'button grey disabled', | ||||
), | ), | ||||
pht('Original Change')); | pht('Original Change')); | ||||
} | } | ||||
$link_r = null; | $link_r = null; | ||||
if ($nav_r) { | if ($nav_r) { | ||||
$link_r = phutil_tag( | $link_r = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => $uri->alter('l', $l + 1)->alter('r', $r + 1), | 'href' => $uri->alter('l', $l + 1)->alter('r', $r + 1), | ||||
'class' => 'button simple', | 'class' => 'button grey', | ||||
), | ), | ||||
pht("Next Change \xC2\xBB")); | pht("Next Change \xC2\xBB")); | ||||
} else { | } else { | ||||
$link_r = phutil_tag( | $link_r = phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '#', | 'href' => '#', | ||||
'class' => 'button grey disabled', | 'class' => 'button grey disabled', | ||||
), | ), | ||||
pht('Most Recent Change')); | pht('Most Recent Change')); | ||||
} | } | ||||
$navigation_table = phutil_tag( | $navigation_table = phutil_tag( | ||||
'table', | 'table', | ||||
array('class' => 'phriction-history-nav-table'), | array('class' => 'phriction-history-nav-table'), | ||||
phutil_tag('tr', array(), array( | phutil_tag('tr', array(), array( | ||||
phutil_tag('td', array('class' => 'nav-prev'), $link_l), | phutil_tag('td', array('class' => 'nav-prev'), $link_l), | ||||
phutil_tag('td', array('class' => 'nav-next'), $link_r), | phutil_tag('td', array('class' => 'nav-next'), $link_r), | ||||
))); | ))); | ||||
} | } | ||||
$output = hsprintf( | $output = hsprintf( | ||||
'<div class="phriction-document-history-diff">'. | '<div class="phriction-document-history-diff">'. | ||||
'%s%s'. | '%s%s'. | ||||
'<table class="phriction-revert-table">'. | '<table class="phriction-revert-table">'. | ||||
'<tr><td>%s</td><td>%s</td>'. | '<tr><td>%s</td><td>%s</td>'. | ||||
'</table>'. | '</table>'. | ||||
'</div>', | '</div>', | ||||
$comparison_table->render(), | $comparison_table->render(), | ||||
$navigation_table, | $navigation_table, | ||||
$revert_l, | $revert_l, | ||||
$revert_r); | $revert_r); | ||||
$object_box = id(new PHUIObjectBoxView()) | $object_box = id(new PHUIObjectBoxView()) | ||||
->setHeader($header) | ->setHeaderText(pht('Edits')) | ||||
->setBackground(PHUIObjectBoxView::BLUE_PROPERTY) | |||||
->appendChild($output); | ->appendChild($output); | ||||
return $this->buildApplicationPage( | $crumbs->setBorder(true); | ||||
array( | |||||
$crumbs, | $view = id(new PHUITwoColumnView()) | ||||
->setHeader($header) | |||||
->setFooter(array( | |||||
$object_box, | $object_box, | ||||
$changes, | $changes, | ||||
), | |||||
array( | |||||
'title' => pht('Document History'), | |||||
)); | )); | ||||
return $this->newPage() | |||||
->setTitle(pht('Document History')) | |||||
->setCrumbs($crumbs) | |||||
->appendChild($view); | |||||
} | } | ||||
private function renderRevertButton( | private function renderRevertButton( | ||||
PhrictionContent $content, | PhrictionContent $content, | ||||
PhrictionContent $current) { | PhrictionContent $current) { | ||||
$document_id = $content->getDocumentID(); | $document_id = $content->getDocumentID(); | ||||
$version = $content->getVersion(); | $version = $content->getVersion(); | ||||
Show All 9 Lines | if (isset($hidden_statuses[$content->getChangeType()])) { | ||||
return null; | return null; | ||||
} | } | ||||
if ($content->getID() == $current->getID()) { | if ($content->getID() == $current->getID()) { | ||||
return phutil_tag( | return phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '/phriction/edit/'.$document_id.'/', | 'href' => '/phriction/edit/'.$document_id.'/', | ||||
'class' => 'button simple', | 'class' => 'button grey', | ||||
), | ), | ||||
pht('Edit Current Version')); | pht('Edit Current Version')); | ||||
} | } | ||||
return phutil_tag( | return phutil_tag( | ||||
'a', | 'a', | ||||
array( | array( | ||||
'href' => '/phriction/edit/'.$document_id.'/?revert='.$version, | 'href' => '/phriction/edit/'.$document_id.'/?revert='.$version, | ||||
'class' => 'button simple', | 'class' => 'button grey', | ||||
), | ), | ||||
pht('Revert to Version %s...', $version)); | pht('Revert to Version %s...', $version)); | ||||
} | } | ||||
private function renderComparisonTable(array $content) { | private function renderComparisonTable(array $content) { | ||||
assert_instances_of($content, 'PhrictionContent'); | assert_instances_of($content, 'PhrictionContent'); | ||||
$viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
Show All 36 Lines |