Skip to content

Commit

Permalink
Merge branch 'diff' of git://github.com/younes0/BookStack into younes…
Browse files Browse the repository at this point in the history
…0-diff
  • Loading branch information
ssddanbrown committed Sep 29, 2016
2 parents 42d8e9e + c279c6e commit fff5bbc
Show file tree
Hide file tree
Showing 6 changed files with 219 additions and 54 deletions.
12 changes: 11 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 GatherContent\Htmldiff\Htmldiff;

class PageController extends Controller
{
Expand Down Expand Up @@ -335,9 +336,18 @@ 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;
$diff = (new Htmldiff)->diff($revision->html, $next->html);

$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);
}
}
}
4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,15 @@
"require": {
"php": ">=5.6.4",
"laravel/framework": "^5.3.4",
"ext-tidy": "*",
"intervention/image": "^2.3",
"laravel/socialite": "^2.0",
"barryvdh/laravel-ide-helper": "^2.1",
"barryvdh/laravel-debugbar": "^2.2.3",
"league/flysystem-aws-s3-v3": "^1.0",
"barryvdh/laravel-dompdf": "^0.7",
"predis/predis": "^1.1"
"predis/predis": "^1.1",
"gathercontent/htmldiff": "^0.2.1"
},
"require-dev": {
"fzaninotto/faker": "~1.4",
Expand Down
Loading

0 comments on commit fff5bbc

Please sign in to comment.