Younès EL BIACHE

html diff in revision view

...@@ -12,6 +12,7 @@ use BookStack\Repos\ChapterRepo; ...@@ -12,6 +12,7 @@ use BookStack\Repos\ChapterRepo;
12 use BookStack\Repos\PageRepo; 12 use BookStack\Repos\PageRepo;
13 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; 13 use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
14 use Views; 14 use Views;
15 +use Icap\HtmlDiff\HtmlDiff;
15 16
16 class PageController extends Controller 17 class PageController extends Controller
17 { 18 {
...@@ -332,9 +333,19 @@ class PageController extends Controller ...@@ -332,9 +333,19 @@ class PageController extends Controller
332 $book = $this->bookRepo->getBySlug($bookSlug); 333 $book = $this->bookRepo->getBySlug($bookSlug);
333 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 334 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
334 $revision = $this->pageRepo->getRevisionById($revisionId); 335 $revision = $this->pageRepo->getRevisionById($revisionId);
336 +
337 + $next = $revision->getNext() ?: $page;
338 + $htmlDiff = new HtmlDiff($revision->html, $next->html, true);
339 + $diff = $htmlDiff->outputDiff()->toString();
340 +
335 $page->fill($revision->toArray()); 341 $page->fill($revision->toArray());
336 $this->setPageTitle('Page Revision For ' . $page->getShortName()); 342 $this->setPageTitle('Page Revision For ' . $page->getShortName());
337 - return view('pages/revision', ['page' => $page, 'book' => $book]); 343 +
344 + return view('pages/revision', [
345 + 'page' => $page,
346 + 'book' => $book,
347 + 'diff' => $diff,
348 + ]);
338 } 349 }
339 350
340 /** 351 /**
......
...@@ -32,4 +32,25 @@ class PageRevision extends Model ...@@ -32,4 +32,25 @@ class PageRevision extends Model
32 return $this->page->getUrl() . '/revisions/' . $this->id; 32 return $this->page->getUrl() . '/revisions/' . $this->id;
33 } 33 }
34 34
35 + /**
36 + * Get previous revision
37 + * @return \BookStack\PageRevision
38 + */
39 + public function getPrevious()
40 + {
41 + if ($id = PageRevision::where('id', '<', $this->id)->max('id')) {
42 + return PageRevision::find($id);
43 + }
44 + }
45 +
46 + /**
47 + * Get next revision
48 + * @return \BookStack\PageRevision
49 + */
50 + public function getNext()
51 + {
52 + if ($id = PageRevision::where('id', '>', $this->id)->min('id')) {
53 + return PageRevision::find($id);
54 + }
55 + }
35 } 56 }
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
13 "barryvdh/laravel-debugbar": "^2.0", 13 "barryvdh/laravel-debugbar": "^2.0",
14 "league/flysystem-aws-s3-v3": "^1.0", 14 "league/flysystem-aws-s3-v3": "^1.0",
15 "barryvdh/laravel-dompdf": "0.6.*", 15 "barryvdh/laravel-dompdf": "0.6.*",
16 - "predis/predis": "^1.0" 16 + "predis/predis": "^1.0",
17 + "icap/html-diff": "^1.1"
17 }, 18 },
18 "require-dev": { 19 "require-dev": {
19 "fzaninotto/faker": "~1.4", 20 "fzaninotto/faker": "~1.4",
......
...@@ -60,6 +60,18 @@ ...@@ -60,6 +60,18 @@
60 word-break: break-word; 60 word-break: break-word;
61 hyphens: auto; 61 hyphens: auto;
62 } 62 }
63 +
64 + // diffs
65 + .diff-html-removed,
66 + .diff-html-added {
67 + text-decoration: none;
68 + }
69 + .diff-html-added {
70 + background: rgba(45, 255, 0, 0.2);
71 + }
72 + .diff-html-removed {
73 + background: rgba(255, 0, 0, 0.2);
74 + }
63 } 75 }
64 76
65 // Page content pointers 77 // Page content pointers
......
...@@ -18,5 +18,9 @@ ...@@ -18,5 +18,9 @@
18 18
19 <div style="clear:left;"></div> 19 <div style="clear:left;"></div>
20 20
21 - {!! $page->html !!} 21 + @if (isset($diff) && $diff)
22 + {!! $diff !!}
23 + @else
24 + {!! $page->html !!}
25 + @endif
22 </div> 26 </div>
...\ No newline at end of file ...\ No newline at end of file
......