Dan Brown

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

...@@ -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 GatherContent\Htmldiff\Htmldiff;
15 16
16 class PageController extends Controller 17 class PageController extends Controller
17 { 18 {
...@@ -335,9 +336,18 @@ class PageController extends Controller ...@@ -335,9 +336,18 @@ class PageController extends Controller
335 $book = $this->bookRepo->getBySlug($bookSlug); 336 $book = $this->bookRepo->getBySlug($bookSlug);
336 $page = $this->pageRepo->getBySlug($pageSlug, $book->id); 337 $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
337 $revision = $this->pageRepo->getRevisionById($revisionId); 338 $revision = $this->pageRepo->getRevisionById($revisionId);
339 +
340 + $next = $revision->getNext() ?: $page;
341 + $diff = (new Htmldiff)->diff($revision->html, $next->html);
342 +
338 $page->fill($revision->toArray()); 343 $page->fill($revision->toArray());
339 $this->setPageTitle('Page Revision For ' . $page->getShortName()); 344 $this->setPageTitle('Page Revision For ' . $page->getShortName());
340 - return view('pages/revision', ['page' => $page, 'book' => $book]); 345 +
346 + return view('pages/revision', [
347 + 'page' => $page,
348 + 'book' => $book,
349 + 'diff' => $diff,
350 + ]);
341 } 351 }
342 352
343 /** 353 /**
......
...@@ -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 }
......
...@@ -7,13 +7,15 @@ ...@@ -7,13 +7,15 @@
7 "require": { 7 "require": {
8 "php": ">=5.6.4", 8 "php": ">=5.6.4",
9 "laravel/framework": "^5.3.4", 9 "laravel/framework": "^5.3.4",
10 + "ext-tidy": "*",
10 "intervention/image": "^2.3", 11 "intervention/image": "^2.3",
11 "laravel/socialite": "^2.0", 12 "laravel/socialite": "^2.0",
12 "barryvdh/laravel-ide-helper": "^2.1", 13 "barryvdh/laravel-ide-helper": "^2.1",
13 "barryvdh/laravel-debugbar": "^2.2.3", 14 "barryvdh/laravel-debugbar": "^2.2.3",
14 "league/flysystem-aws-s3-v3": "^1.0", 15 "league/flysystem-aws-s3-v3": "^1.0",
15 "barryvdh/laravel-dompdf": "^0.7", 16 "barryvdh/laravel-dompdf": "^0.7",
16 - "predis/predis": "^1.1" 17 + "predis/predis": "^1.1",
18 + "gathercontent/htmldiff": "^0.2.1"
17 }, 19 },
18 "require-dev": { 20 "require-dev": {
19 "fzaninotto/faker": "~1.4", 21 "fzaninotto/faker": "~1.4",
......
...@@ -71,6 +71,18 @@ ...@@ -71,6 +71,18 @@
71 max-width: 100%; 71 max-width: 100%;
72 height: auto !important; 72 height: auto !important;
73 } 73 }
74 +
75 + // diffs
76 + ins,
77 + del {
78 + text-decoration: none;
79 + }
80 + ins {
81 + background: #dbffdb;
82 + }
83 + del {
84 + background: #FFECEC;
85 + }
74 } 86 }
75 87
76 // Page content pointers 88 // Page content pointers
......
...@@ -24,5 +24,9 @@ ...@@ -24,5 +24,9 @@
24 24
25 <div style="clear:left;"></div> 25 <div style="clear:left;"></div>
26 26
27 + @if (isset($diff) && $diff)
28 + {!! $diff !!}
29 + @else
27 {!! $page->html !!} 30 {!! $page->html !!}
31 + @endif
28 </div> 32 </div>
...\ No newline at end of file ...\ No newline at end of file
......