Changed when revisions are saved and update changelog input

Revisions are now saved when te page content is originally saved whereas before they were saved on the next update to the page.
This commit is contained in:
Dan Brown 2016-07-10 12:12:52 +01:00
parent 8a9a8dfae5
commit 7215392784
8 changed files with 73 additions and 31 deletions

View File

@ -147,7 +147,7 @@ class PageRepo extends EntityRepo
$draftPage->fill($input); $draftPage->fill($input);
// Save page tags if present // Save page tags if present
if(isset($input['tags'])) { if (isset($input['tags'])) {
$this->tagRepo->saveTagsToEntity($draftPage, $input['tags']); $this->tagRepo->saveTagsToEntity($draftPage, $input['tags']);
} }
@ -308,10 +308,9 @@ class PageRepo extends EntityRepo
*/ */
public function updatePage(Page $page, $book_id, $input) public function updatePage(Page $page, $book_id, $input)
{ {
// Save a revision before updating // Hold the old details to compare later
if ($page->html !== $input['html'] || $page->name !== $input['name']) { $oldHtml = $page->html;
$this->saveRevision($page, $input['summary']); $oldName = $page->name;
}
// Prevent slug being updated if no name change // Prevent slug being updated if no name change
if ($page->name !== $input['name']) { if ($page->name !== $input['name']) {
@ -319,7 +318,7 @@ class PageRepo extends EntityRepo
} }
// Save page tags if present // Save page tags if present
if(isset($input['tags'])) { if (isset($input['tags'])) {
$this->tagRepo->saveTagsToEntity($page, $input['tags']); $this->tagRepo->saveTagsToEntity($page, $input['tags']);
} }
@ -335,6 +334,11 @@ class PageRepo extends EntityRepo
// Remove all update drafts for this user & page. // Remove all update drafts for this user & page.
$this->userUpdateDraftsQuery($page, $userId)->delete(); $this->userUpdateDraftsQuery($page, $userId)->delete();
// Save a revision after updating
if ($oldHtml !== $input['html'] || $oldName !== $input['name'] || $input['summary'] !== null) {
$this->saveRevision($page, $input['summary']);
}
return $page; return $page;
} }
@ -360,6 +364,7 @@ class PageRepo extends EntityRepo
/** /**
* Saves a page revision into the system. * Saves a page revision into the system.
* @param Page $page * @param Page $page
* @param null|string $summary
* @return $this * @return $this
*/ */
public function saveRevision(Page $page, $summary = null) public function saveRevision(Page $page, $summary = null)
@ -406,7 +411,7 @@ class PageRepo extends EntityRepo
$draft->fill($data); $draft->fill($data);
if (setting('app-editor') !== 'markdown') $draft->markdown = ''; if (setting('app-editor') !== 'markdown') $draft->markdown = '';
$draft->save(); $draft->save();
return $draft; return $draft;
} }

View File

@ -157,9 +157,22 @@ module.exports = function (ngApp, events) {
return { return {
restrict: 'A', restrict: 'A',
link: function (scope, element, attrs) { link: function (scope, element, attrs) {
var menu = element.find('ul'); const menu = element.find('ul');
element.find('[dropdown-toggle]').on('click', function () { element.find('[dropdown-toggle]').on('click', function () {
menu.show().addClass('anim menuIn'); menu.show().addClass('anim menuIn');
let inputs = menu.find('input');
let hasInput = inputs.length > 0;
if (hasInput) {
inputs.first().focus();
element.on('keypress', 'input', event => {
if (event.keyCode === 13) {
event.preventDefault();
menu.hide();
menu.removeClass('anim menuIn');
return false;
}
});
}
element.mouseleave(function () { element.mouseleave(function () {
menu.hide(); menu.hide();
menu.removeClass('anim menuIn'); menu.removeClass('anim menuIn');

View File

@ -155,6 +155,7 @@ form.search-box {
text-decoration: none; text-decoration: none;
} }
} }
} }
.faded span.faded-text { .faded span.faded-text {

View File

@ -375,6 +375,9 @@ ul.pagination {
.text-muted { .text-muted {
color: #999; color: #999;
} }
li.padded {
padding: $-xs $-m;
}
a { a {
display: block; display: block;
padding: $-xs $-m; padding: $-xs $-m;
@ -384,10 +387,10 @@ ul.pagination {
background-color: #EEE; background-color: #EEE;
} }
i { i {
margin-right: $-m; margin-right: $-s;
padding-right: 0; padding-right: 0;
display: inline; display: inline-block;
width: 22px; width: 16px;
} }
} }
li.border-bottom { li.border-bottom {

View File

@ -18,9 +18,6 @@
flex: 1; flex: 1;
flex-direction: column; flex-direction: column;
} }
#summary-input {
width: 140px;
}
} }
.page-style.editor { .page-style.editor {

View File

@ -22,14 +22,25 @@
<li ng-if="isNewPageDraft"> <li ng-if="isNewPageDraft">
<a href="{{$model->getUrl()}}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete Draft</a> <a href="{{$model->getUrl()}}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete Draft</a>
</li> </li>
<li>
<a type="button" ng-if="isUpdateDraft" ng-click="discardDraft()" class="text-neg"><i class="zmdi zmdi-close-circle"></i>Discard Draft</a>
</li>
</ul> </ul>
</div> </div>
</div> </div>
<div class="col-sm-4 faded"> <div class="col-sm-4 faded">
<div class="action-buttons" ng-cloak> <div class="action-buttons" ng-cloak>
<button type="button" ng-if="isUpdateDraft" ng-click="discardDraft()" class="text-button text-neg"><i class="zmdi zmdi-close-circle"></i>Discard Draft</button> <div dropdown class="dropdown-container">
<input name="summary" id="summary-input" type="text" placeholder="edit summary" /> <a dropdown-toggle class="text-primary text-button"><i class="zmdi zmdi-edit"></i> @{{(changeSummary | limitTo:16) + (changeSummary.length>16?'...':'') || 'Set Changelog'}}</a>
<button type="submit" id="save-button" class="text-button text-pos"><i class="zmdi zmdi-floppy"></i>Save Page</button> <ul class="wide">
<li class="padded">
<p class="text-muted">Enter a brief description of the changes you've made</p>
<input name="summary" id="summary-input" type="text" placeholder="Enter Changelog" ng-model="changeSummary" />
</li>
</ul>
</div>
<button type="submit" id="save-button" class="text-button text-pos"><i class="zmdi zmdi-floppy"></i>Save Page</button>
</div> </div>
</div> </div>
</div> </div>

View File

@ -16,7 +16,7 @@
</a> </a>
@endif @endif
<span class="sep">&raquo;</span> <span class="sep">&raquo;</span>
<a href="{{$page->getUrl()}}" class="text-book text-button"><i class="zmdi zmdi-file"></i>{{ $page->getShortName() }}</a> <a href="{{$page->getUrl()}}" class="text-page text-button"><i class="zmdi zmdi-file"></i>{{ $page->getShortName() }}</a>
</div> </div>
</div> </div>
</div> </div>

View File

@ -5,32 +5,40 @@
<div class="faded-small toolbar"> <div class="faded-small toolbar">
<div class="container"> <div class="container">
<div class="row"> <div class="row">
<div class="col-md-6 faded"> <div class="col-sm-12 faded">
<div class="breadcrumbs"> <div class="breadcrumbs">
<a href="{{$page->getUrl()}}" class="text-primary text-button"><i class="zmdi zmdi-arrow-left"></i>Back to page</a> <a href="{{$page->book->getUrl()}}" class="text-book text-button"><i class="zmdi zmdi-book"></i>{{ $page->book->getShortName() }}</a>
@if($page->hasChapter())
<span class="sep">&raquo;</span>
<a href="{{ $page->chapter->getUrl() }}" class="text-chapter text-button">
<i class="zmdi zmdi-collection-bookmark"></i>
{{$page->chapter->getShortName()}}
</a>
@endif
<span class="sep">&raquo;</span>
<a href="{{$page->getUrl()}}" class="text-page text-button"><i class="zmdi zmdi-file"></i>{{ $page->getShortName() }}</a>
</div> </div>
</div> </div>
<div class="col-md-6 faded">
</div>
</div> </div>
</div> </div>
</div> </div>
<div class="container medium" ng-non-bindable>
<div class="container" ng-non-bindable>
<h1>Page Revisions <span class="subheader">For "{{ $page->name }}"</span></h1> <h1>Page Revisions <span class="subheader">For "{{ $page->name }}"</span></h1>
@if(count($page->revisions) > 0) @if(count($page->revisions) > 0)
<table class="table"> <table class="table">
<tr> <tr>
<th width="30%">Name</th> <th width="25%">Name</th>
<th colspan="2" width="10%">Created By</th> <th colspan="2" width="10%">Created By</th>
<th width="15%">Revision Date</th> <th width="15%">Revision Date</th>
<th width="20%">Summary</th> <th width="25%">Changelog</th>
<th width="15%">Actions</th> <th width="15%">Actions</th>
</tr> </tr>
@foreach($page->revisions as $revision) @foreach($page->revisions as $index => $revision)
<tr> <tr>
<td>{{$revision->name}}</td> <td>{{$revision->name}}</td>
<td style="line-height: 0;"> <td style="line-height: 0;">
@ -41,11 +49,15 @@
<td> @if($revision->createdBy) {{$revision->createdBy->name}} @else Deleted User @endif</td> <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><small>{{$revision->created_at->format('jS F, Y H:i:s')}} <br> ({{$revision->created_at->diffForHumans()}})</small></td>
<td>{{$revision->summary}}</td> <td>{{$revision->summary}}</td>
<td> @if ($index !== 0)
<a href="{{$revision->getUrl()}}" target="_blank">Preview</a> <td>
<span class="text-muted">&nbsp;|&nbsp;</span> <a href="{{$revision->getUrl()}}" target="_blank">Preview</a>
<a href="{{$revision->getUrl()}}/restore">Restore</a> <span class="text-muted">&nbsp;|&nbsp;</span>
</td> <a href="{{$revision->getUrl()}}/restore">Restore</a>
</td>
@else
<td><a target="_blank" href="{{ $page->getUrl() }}"><i>Current Version</i></a></td>
@endif
</tr> </tr>
@endforeach @endforeach
</table> </table>