Toggle navigation
Toggle navigation
This project
Loading...
Sign in
Зуев Егор
/
wiki.dev
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
Authored by
Dan Brown
2016-09-29 10:10:46 +0100
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Commit
f15cc5bdfad7ce729e61abbd14ebc2807d7bb651
f15cc5bd
1 parent
fff5bbce
Separated revision preview and diff & fixed chosen diff html
Closes #8
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
51 additions
and
30 deletions
app/Http/Controllers/PageController.php
app/PageRevision.php
app/Repos/PageRepo.php
resources/views/pages/revisions.blade.php
routes/web.php
app/Http/Controllers/PageController.php
View file @
f15cc5b
...
...
@@ -336,9 +336,6 @@ 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
());
...
...
@@ -346,6 +343,32 @@ class PageController extends Controller
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
,
'diff'
=>
$diff
,
]);
}
...
...
app/PageRevision.php
View file @
f15cc5b
...
...
@@ -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
);
}
}
}
...
...
app/Repos/PageRepo.php
View file @
f15cc5b
...
...
@@ -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
)
{
...
...
resources/views/pages/revisions.blade.php
View file @
f15cc5b
...
...
@@ -32,11 +32,11 @@
<table
class=
"table"
>
<tr>
<th
width=
"2
5
%"
>
Name
</th>
<th
colspan=
"2"
width=
"
10
%"
>
Created By
</th>
<th
width=
"2
3
%"
>
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>
...
...
@@ -49,15 +49,18 @@
<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"
>
|
</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"
>
|
</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>
...
...
routes/web.php
View file @
f15cc5b
...
...
@@ -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
...
...
Please
register
or
sign in
to post a comment