diff --git a/ghost/admin/app/components/gh-koenig-editor-lexical.js b/ghost/admin/app/components/gh-koenig-editor-lexical.js index 6ff1a26eba..ad38fc081b 100644 --- a/ghost/admin/app/components/gh-koenig-editor-lexical.js +++ b/ghost/admin/app/components/gh-koenig-editor-lexical.js @@ -110,6 +110,7 @@ export default class GhKoenigEditorReactComponent extends Component { @action registerEditorAPI(API) { this.editorAPI = API; + this.args.registerAPI(API); } // @action diff --git a/ghost/admin/app/components/gh-post-settings-menu.hbs b/ghost/admin/app/components/gh-post-settings-menu.hbs index deeb6935f0..40f59638b9 100644 --- a/ghost/admin/app/components/gh-post-settings-menu.hbs +++ b/ghost/admin/app/components/gh-post-settings-menu.hbs @@ -450,7 +450,10 @@ {{#if this.showPostHistory}} {{/if}} diff --git a/ghost/admin/app/components/modal-post-history.hbs b/ghost/admin/app/components/modal-post-history.hbs index c005470beb..033f4659e5 100644 --- a/ghost/admin/app/components/modal-post-history.hbs +++ b/ghost/admin/app/components/modal-post-history.hbs @@ -35,13 +35,13 @@
- @@ -71,11 +71,15 @@ {{#if revision.latest}} Latest {{/if}} -
+
{{revision.author.name}} {{#if (and revision.selected (not revision.latest))}} - {{/if}} diff --git a/ghost/admin/app/components/modal-post-history.js b/ghost/admin/app/components/modal-post-history.js index 9bdb99362f..6df89db36f 100644 --- a/ghost/admin/app/components/modal-post-history.js +++ b/ghost/admin/app/components/modal-post-history.js @@ -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'); }), diff --git a/ghost/admin/app/controllers/lexical-editor.js b/ghost/admin/app/controllers/lexical-editor.js index cdf9a9e16b..10f3a18ce9 100644 --- a/ghost/admin/app/controllers/lexical-editor.js +++ b/ghost/admin/app/controllers/lexical-editor.js @@ -308,6 +308,11 @@ export default class LexicalEditorController extends Controller { } } + @action + registerEditorAPI(API) { + this.editorAPI = API; + } + @action clearFeatureImage() { this.post.set('featureImage', null); diff --git a/ghost/admin/app/templates/lexical-editor.hbs b/ghost/admin/app/templates/lexical-editor.hbs index a8968bf7d6..beea5a2b13 100644 --- a/ghost/admin/app/templates/lexical-editor.hbs +++ b/ghost/admin/app/templates/lexical-editor.hbs @@ -90,6 +90,7 @@ createSnippet=(if this.canManageSnippets this.createSnippet) }} @postType={{this.post.displayName}} + @registerAPI={{this.registerEditorAPI}} />
@@ -108,6 +109,7 @@ @deletePost={{this.openDeletePostModal}} @updateSlugTask={{this.updateSlugTask}} @savePostTask={{this.savePostTask}} + @editorAPI={{this.editorAPI}} /> {{/if}}