Add edit post button to post revision modal for wiki-ed posts.

This commit is contained in:
Guo Xiang Tan 2017-01-25 14:33:16 +08:00
parent 781d83a46f
commit ee396edd9c
6 changed files with 75 additions and 9 deletions

View File

@ -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"); },

View File

@ -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');
},

View File

@ -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}}
</div>
<div id="display-modes">
{{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}}
</div>
</div>
@ -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}}
</div>
{{/d-modal-body}}

View File

@ -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? ||

View File

@ -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: "<strong>{{previous}}</strong> <i class='fa fa-arrows-h'></i> <strong>{{current}}</strong> / {{total}}"
displays:
inline:
title: "Show the rendered output with additions and removals inline"
button: '<i class="fa fa-square-o"></i> HTML'
button: 'HTML'
side_by_side:
title: "Show the rendered output diffs side-by-side"
button: '<i class="fa fa-columns"></i> HTML'
button: 'HTML'
side_by_side_markdown:
title: "Show the raw source diffs side-by-side"
button: '<i class="fa fa-columns"></i> Raw'
button: 'Raw'
category:
can: 'can&hellip; '

View File

@ -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');
});
});