html diff in revision view
This commit is contained in:
parent
10418323ef
commit
9537e2ae95
6 changed files with 589 additions and 297 deletions
|
@ -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,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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
831
composer.lock
generated
File diff suppressed because it is too large
Load diff
12
resources/assets/sass/_pages.scss
Normal file → Executable file
12
resources/assets/sass/_pages.scss
Normal file → Executable 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
|
||||
|
|
|
@ -18,5 +18,9 @@
|
|||
|
||||
<div style="clear:left;"></div>
|
||||
|
||||
{!! $page->html !!}
|
||||
@if (isset($diff) && $diff)
|
||||
{!! $diff !!}
|
||||
@else
|
||||
{!! $page->html !!}
|
||||
@endif
|
||||
</div>
|
Loading…
Reference in a new issue