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

@ -308,10 +308,9 @@ class PageRepo extends EntityRepo
*/
public function updatePage(Page $page, $book_id, $input)
{
// Save a revision before updating
if ($page->html !== $input['html'] || $page->name !== $input['name']) {
$this->saveRevision($page, $input['summary']);
}
// Hold the old details to compare later
$oldHtml = $page->html;
$oldName = $page->name;
// Prevent slug being updated if no name change
if ($page->name !== $input['name']) {
@ -335,6 +334,11 @@ class PageRepo extends EntityRepo
// Remove all update drafts for this user & page.
$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;
}
@ -360,6 +364,7 @@ class PageRepo extends EntityRepo
/**
* Saves a page revision into the system.
* @param Page $page
* @param null|string $summary
* @return $this
*/
public function saveRevision(Page $page, $summary = null)

View File

@ -157,9 +157,22 @@ module.exports = function (ngApp, events) {
return {
restrict: 'A',
link: function (scope, element, attrs) {
var menu = element.find('ul');
const menu = element.find('ul');
element.find('[dropdown-toggle]').on('click', function () {
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 () {
menu.hide();
menu.removeClass('anim menuIn');

View File

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

View File

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

View File

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

View File

@ -22,13 +22,24 @@
<li ng-if="isNewPageDraft">
<a href="{{$model->getUrl()}}/delete" class="text-neg"><i class="zmdi zmdi-delete"></i>Delete Draft</a>
</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>
</div>
</div>
<div class="col-sm-4 faded">
<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>
<input name="summary" id="summary-input" type="text" placeholder="edit summary" />
<div dropdown class="dropdown-container">
<a dropdown-toggle class="text-primary text-button"><i class="zmdi zmdi-edit"></i> @{{(changeSummary | limitTo:16) + (changeSummary.length>16?'...':'') || 'Set Changelog'}}</a>
<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>

View File

@ -16,7 +16,7 @@
</a>
@endif
<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>

View File

@ -5,32 +5,40 @@
<div class="faded-small toolbar">
<div class="container">
<div class="row">
<div class="col-md-6 faded">
<div class="col-sm-12 faded">
<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 class="col-md-6 faded">
</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>
@if(count($page->revisions) > 0)
<table class="table">
<tr>
<th width="30%">Name</th>
<th width="25%">Name</th>
<th colspan="2" width="10%">Created By</th>
<th width="15%">Revision Date</th>
<th width="20%">Summary</th>
<th width="25%">Changelog</th>
<th width="15%">Actions</th>
</tr>
@foreach($page->revisions as $revision)
@foreach($page->revisions as $index => $revision)
<tr>
<td>{{$revision->name}}</td>
<td style="line-height: 0;">
@ -41,11 +49,15 @@
<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>
<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
</tr>
@endforeach
</table>