html diff in revision view

This commit is contained in:
Younès EL BIACHE 2016-07-07 19:42:21 +02:00
parent 10418323ef
commit 9537e2ae95
6 changed files with 589 additions and 297 deletions

View File

@ -12,6 +12,7 @@ use BookStack\Repos\ChapterRepo;
use BookStack\Repos\PageRepo;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Views;
use Icap\HtmlDiff\HtmlDiff;
class PageController extends Controller
{
@ -332,9 +333,19 @@ 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;
$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,
]);
}
/**

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);
}
}
}

View File

@ -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",

831
composer.lock generated

File diff suppressed because it is too large Load Diff

12
resources/assets/sass/_pages.scss Normal file → Executable file
View File

@ -60,6 +60,18 @@
word-break: break-word;
hyphens: auto;
}
// diffs
.diff-html-removed,
.diff-html-added {
text-decoration: none;
}
.diff-html-added {
background: rgba(45, 255, 0, 0.2);
}
.diff-html-removed {
background: rgba(255, 0, 0, 0.2);
}
}
// Page content pointers

View File

@ -18,5 +18,9 @@
<div style="clear:left;"></div>
{!! $page->html !!}
@if (isset($diff) && $diff)
{!! $diff !!}
@else
{!! $page->html !!}
@endif
</div>