From ee396edd9c90bcdaac85547625bd576ce30cdb0f Mon Sep 17 00:00:00 2001 From: Guo Xiang Tan Date: Wed, 25 Jan 2017 14:33:16 +0800 Subject: [PATCH] Add edit post button to post revision modal for wiki-ed posts. --- .../discourse/controllers/history.js.es6 | 10 +++++++ .../javascripts/discourse/routes/topic.js.es6 | 8 ++++-- .../discourse/templates/modal/history.hbs | 28 +++++++++++++++++-- app/serializers/post_revision_serializer.rb | 7 ++++- config/locales/client.en.yml | 7 +++-- test/javascripts/acceptance/topic-test.js.es6 | 24 ++++++++++++++++ 6 files changed, 75 insertions(+), 9 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/history.js.es6 b/app/assets/javascripts/discourse/controllers/history.js.es6 index e94852cf3ec..b6e9a103777 100644 --- a/app/assets/javascripts/discourse/controllers/history.js.es6 +++ b/app/assets/javascripts/discourse/controllers/history.js.es6 @@ -109,6 +109,11 @@ export default Ember.Controller.extend(ModalFunctionality, { return !prevHidden && this.currentUser && this.currentUser.get('staff'); }, + @computed("model.wiki", "model.last_revision", "model.current_revision") + displayEdit(wiki, lastRevision, currentRevision) { + return wiki && (lastRevision === currentRevision); + }, + @computed() displayRevert() { return this.currentUser && this.currentUser.get('staff'); @@ -187,6 +192,11 @@ export default Ember.Controller.extend(ModalFunctionality, { hideVersion() { this.hide(this.get("model.post_id"), this.get("model.current_revision")); }, showVersion() { this.show(this.get("model.post_id"), this.get("model.current_revision")); }, + editWiki() { + this.get('topicController').send('editPost', this.get('post')); + this.send('closeModal'); + }, + revertToVersion() { this.revert(this.get("post"), this.get("model.current_revision")); }, displayInline() { this.set("viewMode", "inline"); }, diff --git a/app/assets/javascripts/discourse/routes/topic.js.es6 b/app/assets/javascripts/discourse/routes/topic.js.es6 index 9cda61f8d7c..105d0e6ba0e 100644 --- a/app/assets/javascripts/discourse/routes/topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/topic.js.es6 @@ -72,8 +72,12 @@ const TopicRoute = Discourse.Route.extend({ showHistory(model) { showModal('history', { model }); - this.controllerFor('history').refresh(model.get("id"), "latest"); - this.controllerFor('history').set('post', model); + const historyController = this.controllerFor('history'); + + historyController.refresh(model.get("id"), "latest"); + historyController.set('post', model); + historyController.set('topicController', this.controllerFor('topic')); + this.controllerFor('modal').set('modalClass', 'history-modal'); }, diff --git a/app/assets/javascripts/discourse/templates/modal/history.hbs b/app/assets/javascripts/discourse/templates/modal/history.hbs index 4bd8c65e538..62e7f9b9841 100644 --- a/app/assets/javascripts/discourse/templates/modal/history.hbs +++ b/app/assets/javascripts/discourse/templates/modal/history.hbs @@ -11,11 +11,25 @@ {{d-button action="loadNextVersion" icon="forward" title="post.revisions.controls.next" disabled=loadNextDisabled}} {{d-button action="loadLastVersion" icon="fast-forward" title="post.revisions.controls.last" disabled=loadLastDisabled}} +
- {{d-button action="displayInline" label="post.revisions.displays.inline.button" title="post.revisions.displays.inline.title" class=inlineClass}} + {{d-button action="displayInline" + icon="square-o" + label="post.revisions.displays.inline.button" + title="post.revisions.displays.inline.title" + class=inlineClass}} {{#unless site.mobileView}} - {{d-button action="displaySideBySide" label="post.revisions.displays.side_by_side.button" title="post.revisions.displays.side_by_side.title" class=sideBySideClass}} - {{d-button action="displaySideBySideMarkdown" label="post.revisions.displays.side_by_side_markdown.button" title="post.revisions.displays.side_by_side_markdown.title" class=sideBySideMarkdownClass}} + {{d-button action="displaySideBySide" + icon="columns" + label="post.revisions.displays.side_by_side.button" + title="post.revisions.displays.side_by_side.title" + class=sideBySideClass}} + + {{d-button action="displaySideBySideMarkdown" + icon="columns" + label="post.revisions.displays.side_by_side_markdown.button" + title="post.revisions.displays.side_by_side_markdown.title" + class=sideBySideMarkdownClass}} {{/unless}}
@@ -103,11 +117,19 @@ {{#if displayRevert}} {{d-button action="revertToVersion" icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}} {{/if}} + {{#if displayHide}} {{d-button action="hideVersion" icon="eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}} {{/if}} + {{#if displayShow}} {{d-button action="showVersion" icon="eye" label="post.revisions.controls.show" disabled=loading}} {{/if}} + + {{#if displayEdit}} + {{d-button action="editWiki" + icon="pencil" + label="post.revisions.controls.edit_wiki"}} + {{/if}} {{/d-modal-body}} diff --git a/app/serializers/post_revision_serializer.rb b/app/serializers/post_revision_serializer.rb index 8ff8b1826e3..6fe950739d2 100644 --- a/app/serializers/post_revision_serializer.rb +++ b/app/serializers/post_revision_serializer.rb @@ -23,7 +23,8 @@ class PostRevisionSerializer < ApplicationSerializer :body_changes, :title_changes, :user_changes, - :tags_changes + :tags_changes, + :wiki # Creates a field called field_name_changes with previous and @@ -95,6 +96,10 @@ class PostRevisionSerializer < ApplicationSerializer user.avatar_template end + def wiki + object.post.wiki + end + def edit_reason # only show 'edit_reason' when revisions are consecutive current["edit_reason"] if scope.can_view_hidden_post_revisions? || diff --git a/config/locales/client.en.yml b/config/locales/client.en.yml index ebdaee27768..086d1887251 100644 --- a/config/locales/client.en.yml +++ b/config/locales/client.en.yml @@ -1888,17 +1888,18 @@ en: hide: "Hide revision" show: "Show revision" revert: "Revert to this revision" + edit_wiki: "Edit wiki" comparing_previous_to_current_out_of_total: "{{previous}} {{current}} / {{total}}" displays: inline: title: "Show the rendered output with additions and removals inline" - button: ' HTML' + button: 'HTML' side_by_side: title: "Show the rendered output diffs side-by-side" - button: ' HTML' + button: 'HTML' side_by_side_markdown: title: "Show the raw source diffs side-by-side" - button: ' Raw' + button: 'Raw' category: can: 'can… ' diff --git a/test/javascripts/acceptance/topic-test.js.es6 b/test/javascripts/acceptance/topic-test.js.es6 index ea8471d71c5..dd9a9bdc20b 100644 --- a/test/javascripts/acceptance/topic-test.js.es6 +++ b/test/javascripts/acceptance/topic-test.js.es6 @@ -48,3 +48,27 @@ test("Updating the topic title and category", () => { equal(find('.fancy-title').text().trim(), 'this is the new title', 'it displays the new title'); }); }); + +test("Marking a topic as wiki", () => { + server.put('/posts/398/wiki', () => { // eslint-disable-line no-undef + return [ + 200, + { "Content-Type": "application/json" }, + {} + ]; + }); + + visit("/t/internationalization-localization/280"); + + andThen(() => { + ok(find('a.wiki').length === 0, 'it does not show the wiki icon'); + }); + + click('.topic-post:eq(0) button.show-more-actions'); + click('.topic-post:eq(0) button.show-post-admin-menu'); + click('.btn.wiki'); + + andThen(() => { + ok(find('a.wiki').length === 1, 'it shows the wiki icon'); + }); +});