1
0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-08-06 12:02:45 +03:00

Merge branch 'diff' of git://github.com/younes0/BookStack into younes0-diff

This commit is contained in:
Dan Brown
2016-09-29 09:32:40 +01:00
6 changed files with 219 additions and 54 deletions

View File

@@ -12,6 +12,7 @@ use BookStack\Repos\ChapterRepo;
use BookStack\Repos\PageRepo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Views;
use GatherContent\Htmldiff\Htmldiff;
class PageController extends Controller
{
@@ -335,9 +336,18 @@ class PageController extends Controller
$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,
]);
}
/**

View File

@@ -32,4 +32,25 @@ class PageRevision extends Model
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);
}
}
}