mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-03 23:00:14 -05:00
Added post revision restoration (#16680)
no issue Added functionality to restore a post revision
This commit is contained in:
parent
bf6f697be4
commit
096a31cf7e
6 changed files with 49 additions and 9 deletions
|
@ -110,6 +110,7 @@ export default class GhKoenigEditorReactComponent extends Component {
|
|||
@action
|
||||
registerEditorAPI(API) {
|
||||
this.editorAPI = API;
|
||||
this.args.registerAPI(API);
|
||||
}
|
||||
|
||||
// @action
|
||||
|
|
|
@ -450,7 +450,10 @@
|
|||
{{#if this.showPostHistory}}
|
||||
<GhFullscreenModal
|
||||
@modal="post-history"
|
||||
@model={{this.post}}
|
||||
@model={{hash
|
||||
post=this.post
|
||||
editorAPI=this.editorAPI
|
||||
}}
|
||||
@close={{this.closePostHistory}}
|
||||
@modifier="total-overlay post-history" />
|
||||
{{/if}}
|
||||
|
|
|
@ -35,13 +35,13 @@
|
|||
<div class="settings-menu settings-menu-pane settings-menu-pane-main">
|
||||
<div class="settings-menu-header-wrapper">
|
||||
<div class="settings-menu-header subview">
|
||||
<button
|
||||
aria-label="Close meta data panel"
|
||||
class="back settings-menu-header-action"
|
||||
data-test-button="close-psm-subview"
|
||||
<button
|
||||
aria-label="Close meta data panel"
|
||||
class="back settings-menu-header-action"
|
||||
data-test-button="close-psm-subview"
|
||||
type="button" {{action "closeModal"}}
|
||||
{{on "mousedown" (optional this.noop)}}
|
||||
>
|
||||
>
|
||||
{{svg-jar "arrow-left"}}
|
||||
<span class="hidden">Back</span>
|
||||
</button>
|
||||
|
@ -71,11 +71,15 @@
|
|||
{{#if revision.latest}}
|
||||
<span class="gh-post-history-version-current">Latest</span>
|
||||
{{/if}}
|
||||
</div>
|
||||
</div>
|
||||
<span class="gh-post-history-version-meta">{{revision.author.name}}</span>
|
||||
</button>
|
||||
{{#if (and revision.selected (not revision.latest))}}
|
||||
<button type="button" class="gh-post-history-version-restore">
|
||||
<button
|
||||
type="button"
|
||||
class="gh-post-history-version-restore"
|
||||
{{on "click" (fn this.restoreRevision index)}}
|
||||
>
|
||||
<span>Restore</span>
|
||||
</button>
|
||||
{{/if}}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import ModalComponent from 'ghost-admin/components/modal-base';
|
||||
import diff from 'node-htmldiff';
|
||||
import {action, computed} from '@ember/object';
|
||||
import {inject as service} from '@ember/service';
|
||||
|
||||
function checkFinishedRendering(element, done) {
|
||||
let last = element.innerHTML;
|
||||
|
@ -19,6 +20,7 @@ function checkFinishedRendering(element, done) {
|
|||
}
|
||||
|
||||
export default ModalComponent.extend({
|
||||
notifications: service(),
|
||||
selectedHTML: null,
|
||||
diffHtml: null,
|
||||
showDifferences: true,
|
||||
|
@ -57,7 +59,8 @@ export default ModalComponent.extend({
|
|||
|
||||
init() {
|
||||
this._super(...arguments);
|
||||
this.post = this.model;
|
||||
this.post = this.model.post;
|
||||
this.editorAPI = this.model.editorAPI;
|
||||
},
|
||||
|
||||
didInsertElement() {
|
||||
|
@ -87,6 +90,28 @@ export default ModalComponent.extend({
|
|||
return strippedHtml;
|
||||
},
|
||||
|
||||
restoreRevision: action(function (index){
|
||||
const revision = this.revisionList[index];
|
||||
|
||||
// Persist model
|
||||
this.post.lexical = revision.lexical;
|
||||
this.post.title = revision.title;
|
||||
this.post.save();
|
||||
|
||||
// @TODO: error handling
|
||||
|
||||
// Update editor title
|
||||
this.set('post.titleScratch', this.post.title);
|
||||
|
||||
// Update editor content
|
||||
const state = this.editorAPI.editorInstance.parseEditorState(this.post.lexical);
|
||||
this.editorAPI.editorInstance.setEditorState(state);
|
||||
|
||||
// Close modal
|
||||
this.closeModal();
|
||||
this.notifications.showNotification('Revision successfully restored.', {type: 'success'});
|
||||
}),
|
||||
|
||||
toggleDifferences: action(function () {
|
||||
this.toggleProperty('showDifferences');
|
||||
}),
|
||||
|
|
|
@ -308,6 +308,11 @@ export default class LexicalEditorController extends Controller {
|
|||
}
|
||||
}
|
||||
|
||||
@action
|
||||
registerEditorAPI(API) {
|
||||
this.editorAPI = API;
|
||||
}
|
||||
|
||||
@action
|
||||
clearFeatureImage() {
|
||||
this.post.set('featureImage', null);
|
||||
|
|
|
@ -90,6 +90,7 @@
|
|||
createSnippet=(if this.canManageSnippets this.createSnippet)
|
||||
}}
|
||||
@postType={{this.post.displayName}}
|
||||
@registerAPI={{this.registerEditorAPI}}
|
||||
/>
|
||||
|
||||
<div class="gh-editor-wordcount-container">
|
||||
|
@ -108,6 +109,7 @@
|
|||
@deletePost={{this.openDeletePostModal}}
|
||||
@updateSlugTask={{this.updateSlugTask}}
|
||||
@savePostTask={{this.savePostTask}}
|
||||
@editorAPI={{this.editorAPI}}
|
||||
/>
|
||||
{{/if}}
|
||||
</div>
|
||||
|
|
Loading…
Add table
Reference in a new issue