Skip to content

Commit

Permalink
html diff in revision view
Browse files Browse the repository at this point in the history
  • Loading branch information
Younès EL BIACHE committed Jul 7, 2016
1 parent 1041832 commit 9537e2a
Show file tree
Hide file tree
Showing 6 changed files with 587 additions and 295 deletions.
13 changes: 12 additions & 1 deletion app/Http/Controllers/PageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use BookStack\Repos\PageRepo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Views;
use Icap\HtmlDiff\HtmlDiff;

class PageController extends Controller
{
Expand Down Expand Up @@ -332,9 +333,19 @@ public function showRevision($bookSlug, $pageSlug, $revisionId)
$book = $this->bookRepo->getBySlug($bookSlug);
$page = $this->pageRepo->getBySlug($pageSlug, $book->id);
$revision = $this->pageRepo->getRevisionById($revisionId);

$next = $revision->getNext() ?: $page;
$htmlDiff = new HtmlDiff($revision->html, $next->html, true);
$diff = $htmlDiff->outputDiff()->toString();

$page->fill($revision->toArray());
$this->setPageTitle('Page Revision For ' . $page->getShortName());
return view('pages/revision', ['page' => $page, 'book' => $book]);

return view('pages/revision', [
'page' => $page,
'book' => $book,
'diff' => $diff,
]);
}

/**
Expand Down
21 changes: 21 additions & 0 deletions app/PageRevision.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,25 @@ public function getUrl()
return $this->page->getUrl() . '/revisions/' . $this->id;
}

/**
* Get previous revision
* @return \BookStack\PageRevision
*/
public function getPrevious()
{
if ($id = PageRevision::where('id', '<', $this->id)->max('id')) {
return PageRevision::find($id);
}
}

/**
* Get next revision
* @return \BookStack\PageRevision
*/
public function getNext()
{
if ($id = PageRevision::where('id', '>', $this->id)->min('id')) {
return PageRevision::find($id);
}
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
"barryvdh/laravel-debugbar": "^2.0",
"league/flysystem-aws-s3-v3": "^1.0",
"barryvdh/laravel-dompdf": "0.6.*",
"predis/predis": "^1.0"
"predis/predis": "^1.0",
"icap/html-diff": "^1.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
Loading

0 comments on commit 9537e2a

Please sign in to comment.