Separated revision preview and diff & fixed chosen diff html
Closes #8
Showing
5 changed files
with
48 additions
and
27 deletions
| ... | @@ -337,8 +337,31 @@ class PageController extends Controller | ... | @@ -337,8 +337,31 @@ class PageController extends Controller |
| 337 | $page = $this->pageRepo->getBySlug($pageSlug, $book->id); | 337 | $page = $this->pageRepo->getBySlug($pageSlug, $book->id); |
| 338 | $revision = $this->pageRepo->getRevisionById($revisionId); | 338 | $revision = $this->pageRepo->getRevisionById($revisionId); |
| 339 | 339 | ||
| 340 | - $next = $revision->getNext() ?: $page; | 340 | + $page->fill($revision->toArray()); |
| 341 | - $diff = (new Htmldiff)->diff($revision->html, $next->html); | 341 | + $this->setPageTitle('Page Revision For ' . $page->getShortName()); |
| 342 | + | ||
| 343 | + return view('pages/revision', [ | ||
| 344 | + 'page' => $page, | ||
| 345 | + 'book' => $book, | ||
| 346 | + ]); | ||
| 347 | + } | ||
| 348 | + | ||
| 349 | + /** | ||
| 350 | + * Shows the changes of a single revision | ||
| 351 | + * @param string $bookSlug | ||
| 352 | + * @param string $pageSlug | ||
| 353 | + * @param int $revisionId | ||
| 354 | + * @return \Illuminate\View\View | ||
| 355 | + */ | ||
| 356 | + public function showRevisionChanges($bookSlug, $pageSlug, $revisionId) | ||
| 357 | + { | ||
| 358 | + $book = $this->bookRepo->getBySlug($bookSlug); | ||
| 359 | + $page = $this->pageRepo->getBySlug($pageSlug, $book->id); | ||
| 360 | + $revision = $this->pageRepo->getRevisionById($revisionId); | ||
| 361 | + | ||
| 362 | + $prev = $revision->getPrevious(); | ||
| 363 | + $prevContent = ($prev === null) ? '' : $prev->html; | ||
| 364 | + $diff = (new Htmldiff)->diff($prevContent, $revision->html); | ||
| 342 | 365 | ||
| 343 | $page->fill($revision->toArray()); | 366 | $page->fill($revision->toArray()); |
| 344 | $this->setPageTitle('Page Revision For ' . $page->getShortName()); | 367 | $this->setPageTitle('Page Revision For ' . $page->getShortName()); | ... | ... |
| ... | @@ -25,32 +25,26 @@ class PageRevision extends Model | ... | @@ -25,32 +25,26 @@ class PageRevision extends Model |
| 25 | 25 | ||
| 26 | /** | 26 | /** |
| 27 | * Get the url for this revision. | 27 | * Get the url for this revision. |
| 28 | + * @param null|string $path | ||
| 28 | * @return string | 29 | * @return string |
| 29 | */ | 30 | */ |
| 30 | - public function getUrl() | 31 | + public function getUrl($path = null) |
| 31 | { | 32 | { |
| 32 | - return $this->page->getUrl() . '/revisions/' . $this->id; | 33 | + $url = $this->page->getUrl() . '/revisions/' . $this->id; |
| 34 | + if ($path) return $url . '/' . trim($path, '/'); | ||
| 35 | + return $url; | ||
| 33 | } | 36 | } |
| 34 | 37 | ||
| 35 | /** | 38 | /** |
| 36 | - * Get previous revision | 39 | + * Get the previous revision for the same page if existing |
| 37 | - * @return \BookStack\PageRevision | 40 | + * @return \BookStack\PageRevision|null |
| 38 | */ | 41 | */ |
| 39 | public function getPrevious() | 42 | public function getPrevious() |
| 40 | { | 43 | { |
| 41 | - if ($id = PageRevision::where('id', '<', $this->id)->max('id')) { | 44 | + if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) { |
| 42 | - return PageRevision::find($id); | 45 | + return static::find($id); |
| 43 | } | 46 | } |
| 47 | + return null; | ||
| 44 | } | 48 | } |
| 45 | 49 | ||
| 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 | - } | ||
| 56 | } | 50 | } | ... | ... |
| ... | @@ -548,7 +548,7 @@ class PageRepo extends EntityRepo | ... | @@ -548,7 +548,7 @@ class PageRepo extends EntityRepo |
| 548 | /** | 548 | /** |
| 549 | * Gets a single revision via it's id. | 549 | * Gets a single revision via it's id. |
| 550 | * @param $id | 550 | * @param $id |
| 551 | - * @return mixed | 551 | + * @return PageRevision |
| 552 | */ | 552 | */ |
| 553 | public function getRevisionById($id) | 553 | public function getRevisionById($id) |
| 554 | { | 554 | { | ... | ... |
| ... | @@ -32,11 +32,11 @@ | ... | @@ -32,11 +32,11 @@ |
| 32 | 32 | ||
| 33 | <table class="table"> | 33 | <table class="table"> |
| 34 | <tr> | 34 | <tr> |
| 35 | - <th width="25%">Name</th> | 35 | + <th width="23%">Name</th> |
| 36 | - <th colspan="2" width="10%">Created By</th> | 36 | + <th colspan="2" width="8%">Created By</th> |
| 37 | <th width="15%">Revision Date</th> | 37 | <th width="15%">Revision Date</th> |
| 38 | <th width="25%">Changelog</th> | 38 | <th width="25%">Changelog</th> |
| 39 | - <th width="15%">Actions</th> | 39 | + <th width="20%">Actions</th> |
| 40 | </tr> | 40 | </tr> |
| 41 | @foreach($page->revisions as $index => $revision) | 41 | @foreach($page->revisions as $index => $revision) |
| 42 | <tr> | 42 | <tr> |
| ... | @@ -49,15 +49,18 @@ | ... | @@ -49,15 +49,18 @@ |
| 49 | <td> @if($revision->createdBy) {{ $revision->createdBy->name }} @else Deleted User @endif</td> | 49 | <td> @if($revision->createdBy) {{ $revision->createdBy->name }} @else Deleted User @endif</td> |
| 50 | <td><small>{{ $revision->created_at->format('jS F, Y H:i:s') }} <br> ({{ $revision->created_at->diffForHumans() }})</small></td> | 50 | <td><small>{{ $revision->created_at->format('jS F, Y H:i:s') }} <br> ({{ $revision->created_at->diffForHumans() }})</small></td> |
| 51 | <td>{{ $revision->summary }}</td> | 51 | <td>{{ $revision->summary }}</td> |
| 52 | - @if ($index !== 0) | ||
| 53 | <td> | 52 | <td> |
| 54 | - <a href="{{ $revision->getUrl() }}" target="_blank">Preview</a> | 53 | + <a href="{{ $revision->getUrl('changes') }}" target="_blank">Changes</a> |
| 55 | <span class="text-muted"> | </span> | 54 | <span class="text-muted"> | </span> |
| 56 | - <a href="{{ $revision->getUrl() }}/restore">Restore</a> | 55 | + |
| 57 | - </td> | 56 | + @if ($index === 0) |
| 57 | + <a target="_blank" href="{{ $page->getUrl() }}"><i>Current Version</i></a> | ||
| 58 | @else | 58 | @else |
| 59 | - <td><a target="_blank" href="{{ $page->getUrl() }}"><i>Current Version</i></a></td> | 59 | + <a href="{{ $revision->getUrl() }}" target="_blank">Preview</a> |
| 60 | + <span class="text-muted"> | </span> | ||
| 61 | + <a href="{{ $revision->getUrl('restore') }}" target="_blank">Restore</a> | ||
| 60 | @endif | 62 | @endif |
| 63 | + </td> | ||
| 61 | </tr> | 64 | </tr> |
| 62 | @endforeach | 65 | @endforeach |
| 63 | </table> | 66 | </table> | ... | ... |
| ... | @@ -47,6 +47,7 @@ Route::group(['middleware' => 'auth'], function () { | ... | @@ -47,6 +47,7 @@ Route::group(['middleware' => 'auth'], function () { |
| 47 | // Revisions | 47 | // Revisions |
| 48 | Route::get('/{bookSlug}/page/{pageSlug}/revisions', 'PageController@showRevisions'); | 48 | Route::get('/{bookSlug}/page/{pageSlug}/revisions', 'PageController@showRevisions'); |
| 49 | Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}', 'PageController@showRevision'); | 49 | Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}', 'PageController@showRevision'); |
| 50 | + Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/changes', 'PageController@showRevisionChanges'); | ||
| 50 | Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/restore', 'PageController@restoreRevision'); | 51 | Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/restore', 'PageController@restoreRevision'); |
| 51 | 52 | ||
| 52 | // Chapters | 53 | // Chapters | ... | ... |
-
Please register or sign in to post a comment