]> BookStack Code Mirror - bookstack/commitdiff
Separated revision preview and diff & fixed chosen diff html
authorDan Brown <redacted>
Thu, 29 Sep 2016 09:10:46 +0000 (10:10 +0100)
committerDan Brown <redacted>
Thu, 29 Sep 2016 09:10:46 +0000 (10:10 +0100)
Closes #8

app/Http/Controllers/PageController.php
app/PageRevision.php
app/Repos/PageRepo.php
resources/views/pages/revisions.blade.php
routes/web.php

index 6081d1b27ddaa2bc275d8a6573d7a212e2c9160e..033377a4d14f34566dac16eed9f0e16308ec2235 100644 (file)
@@ -336,13 +336,36 @@ 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;
-        $diff = (new Htmldiff)->diff($revision->html, $next->html);
 
         $page->fill($revision->toArray());
         $this->setPageTitle('Page Revision For ' . $page->getShortName());
         
+        return view('pages/revision', [
+            'page' => $page,
+            'book' => $book,
+        ]);
+    }
+
+    /**
+     * Shows the changes of a single revision
+     * @param string $bookSlug
+     * @param string $pageSlug
+     * @param int $revisionId
+     * @return \Illuminate\View\View
+     */
+    public function showRevisionChanges($bookSlug, $pageSlug, $revisionId)
+    {
+        $book = $this->bookRepo->getBySlug($bookSlug);
+        $page = $this->pageRepo->getBySlug($pageSlug, $book->id);
+        $revision = $this->pageRepo->getRevisionById($revisionId);
+
+        $prev = $revision->getPrevious();
+        $prevContent = ($prev === null) ? '' : $prev->html;
+        $diff = (new Htmldiff)->diff($prevContent, $revision->html);
+
+        $page->fill($revision->toArray());
+        $this->setPageTitle('Page Revision For ' . $page->getShortName());
+
         return view('pages/revision', [
             'page' => $page,
             'book' => $book,
index e5721f5aa1dc08f790eb011daa4ee2fbb706aba2..ff469f0ed3a78b3d3750c3ff6d07b6b2d787c226 100644 (file)
@@ -25,32 +25,26 @@ class PageRevision extends Model
 
     /**
      * Get the url for this revision.
+     * @param null|string $path
      * @return string
      */
-    public function getUrl()
+    public function getUrl($path = null)
     {
-        return $this->page->getUrl() . '/revisions/' . $this->id;
+        $url = $this->page->getUrl() . '/revisions/' . $this->id;
+        if ($path) return $url . '/' . trim($path, '/');
+        return $url;
     }
 
     /**
-     * Get previous revision
-     * @return \BookStack\PageRevision
+     * Get the previous revision for the same page if existing
+     * @return \BookStack\PageRevision|null
      */
     public function getPrevious()
     {
-        if ($id = PageRevision::where('id', '<', $this->id)->max('id')) {
-            return PageRevision::find($id);
+        if ($id = static::where('page_id', '=', $this->page_id)->where('id', '<', $this->id)->max('id')) {
+            return static::find($id);
         }
+        return null;
     }
 
-    /**
-     * Get next revision
-     * @return \BookStack\PageRevision
-     */
-    public function getNext()
-    {
-        if ($id = PageRevision::where('id', '>', $this->id)->min('id')) {
-            return PageRevision::find($id);
-        }
-    }
 }
index c64da126774bd3db3180028b8cb4f0a288dcee81..93ff61b629180d22597d52a8ba9de0cfd44da6bd 100644 (file)
@@ -548,7 +548,7 @@ class PageRepo extends EntityRepo
     /**
      * Gets a single revision via it's id.
      * @param $id
-     * @return mixed
+     * @return PageRevision
      */
     public function getRevisionById($id)
     {
index 926affffc3824d969518ae57383ed19a53726b00..720e34fea4efd76c4187e4f5b37b29e9b65e3a57 100644 (file)
 
             <table class="table">
                 <tr>
-                    <th width="25%">Name</th>
-                    <th colspan="2" width="10%">Created By</th>
+                    <th width="23%">Name</th>
+                    <th colspan="2" width="8%">Created By</th>
                     <th width="15%">Revision Date</th>
                     <th width="25%">Changelog</th>
-                    <th width="15%">Actions</th>
+                    <th width="20%">Actions</th>
                 </tr>
                 @foreach($page->revisions as $index => $revision)
                     <tr>
                         <td> @if($revision->createdBy) {{ $revision->createdBy->name }} @else Deleted User @endif</td>
                         <td><small>{{ $revision->created_at->format('jS F, Y H:i:s') }} <br> ({{ $revision->created_at->diffForHumans() }})</small></td>
                         <td>{{ $revision->summary }}</td>
-                        @if ($index !== 0)
-                            <td>
+                        <td>
+                            <a href="{{ $revision->getUrl('changes') }}" target="_blank">Changes</a>
+                            <span class="text-muted">&nbsp;|&nbsp;</span>
+
+                            @if ($index === 0)
+                                <a target="_blank" href="{{ $page->getUrl() }}"><i>Current Version</i></a>
+                            @else
                                 <a href="{{ $revision->getUrl() }}" target="_blank">Preview</a>
                                 <span class="text-muted">&nbsp;|&nbsp;</span>
-                                <a href="{{ $revision->getUrl() }}/restore">Restore</a>
-                            </td>
-                        @else
-                            <td><a target="_blank" href="{{ $page->getUrl() }}"><i>Current Version</i></a></td>
-                        @endif
+                                <a href="{{ $revision->getUrl('restore') }}" target="_blank">Restore</a>
+                            @endif
+                        </td>
                     </tr>
                 @endforeach
             </table>
index 58ceb5f3b6930208654024a81c203d0c30e5ef2a..c3fe503d1db59b4eb7b8933b1def0157be5403b8 100644 (file)
@@ -47,6 +47,7 @@ Route::group(['middleware' => 'auth'], function () {
         // Revisions
         Route::get('/{bookSlug}/page/{pageSlug}/revisions', 'PageController@showRevisions');
         Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}', 'PageController@showRevision');
+        Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/changes', 'PageController@showRevisionChanges');
         Route::get('/{bookSlug}/page/{pageSlug}/revisions/{revId}/restore', 'PageController@restoreRevision');
 
         // Chapters