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'); 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() @computed()
displayRevert() { displayRevert() {
return this.currentUser && this.currentUser.get('staff'); 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")); }, 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")); }, 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")); }, revertToVersion() { this.revert(this.get("post"), this.get("model.current_revision")); },
displayInline() { this.set("viewMode", "inline"); }, displayInline() { this.set("viewMode", "inline"); },

View File

@ -72,8 +72,12 @@ const TopicRoute = Discourse.Route.extend({
showHistory(model) { showHistory(model) {
showModal('history', { model }); showModal('history', { model });
this.controllerFor('history').refresh(model.get("id"), "latest"); const historyController = this.controllerFor('history');
this.controllerFor('history').set('post', model);
historyController.refresh(model.get("id"), "latest");
historyController.set('post', model);
historyController.set('topicController', this.controllerFor('topic'));
this.controllerFor('modal').set('modalClass', 'history-modal'); 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="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="loadLastVersion" icon="fast-forward" title="post.revisions.controls.last" disabled=loadLastDisabled}}
</div> </div>
<div id="display-modes"> <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}} {{#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="displaySideBySide"
{{d-button action="displaySideBySideMarkdown" label="post.revisions.displays.side_by_side_markdown.button" title="post.revisions.displays.side_by_side_markdown.title" class=sideBySideMarkdownClass}} 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}} {{/unless}}
</div> </div>
</div> </div>
@ -103,11 +117,19 @@
{{#if displayRevert}} {{#if displayRevert}}
{{d-button action="revertToVersion" icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}} {{d-button action="revertToVersion" icon="undo" label="post.revisions.controls.revert" class="btn-danger" disabled=loading}}
{{/if}} {{/if}}
{{#if displayHide}} {{#if displayHide}}
{{d-button action="hideVersion" icon="eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}} {{d-button action="hideVersion" icon="eye-slash" label="post.revisions.controls.hide" class="btn-danger" disabled=loading}}
{{/if}} {{/if}}
{{#if displayShow}} {{#if displayShow}}
{{d-button action="showVersion" icon="eye" label="post.revisions.controls.show" disabled=loading}} {{d-button action="showVersion" icon="eye" label="post.revisions.controls.show" disabled=loading}}
{{/if}} {{/if}}
{{#if displayEdit}}
{{d-button action="editWiki"
icon="pencil"
label="post.revisions.controls.edit_wiki"}}
{{/if}}
</div> </div>
{{/d-modal-body}} {{/d-modal-body}}

View File

@ -23,7 +23,8 @@ class PostRevisionSerializer < ApplicationSerializer
:body_changes, :body_changes,
:title_changes, :title_changes,
:user_changes, :user_changes,
:tags_changes :tags_changes,
:wiki
# Creates a field called field_name_changes with previous and # Creates a field called field_name_changes with previous and
@ -95,6 +96,10 @@ class PostRevisionSerializer < ApplicationSerializer
user.avatar_template user.avatar_template
end end
def wiki
object.post.wiki
end
def edit_reason def edit_reason
# only show 'edit_reason' when revisions are consecutive # only show 'edit_reason' when revisions are consecutive
current["edit_reason"] if scope.can_view_hidden_post_revisions? || current["edit_reason"] if scope.can_view_hidden_post_revisions? ||

View File

@ -1888,17 +1888,18 @@ en:
hide: "Hide revision" hide: "Hide revision"
show: "Show revision" show: "Show revision"
revert: "Revert to this 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}}" comparing_previous_to_current_out_of_total: "<strong>{{previous}}</strong> <i class='fa fa-arrows-h'></i> <strong>{{current}}</strong> / {{total}}"
displays: displays:
inline: inline:
title: "Show the rendered output with additions and removals 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: side_by_side:
title: "Show the rendered output diffs 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: side_by_side_markdown:
title: "Show the raw source diffs side-by-side" title: "Show the raw source diffs side-by-side"
button: '<i class="fa fa-columns"></i> Raw' button: 'Raw'
category: category:
can: 'can&hellip; ' 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'); 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');
});
});