mirror of
https://github.com/discourse/discourse.git
synced 2025-03-28 19:01:10 +08:00
FIX: revision history UI
This commit is contained in:
parent
380a894222
commit
aece2b61a9
@ -12,17 +12,11 @@ Discourse.HistoryController = Discourse.ObjectController.extend(Discourse.ModalF
|
||||
viewMode: "side_by_side",
|
||||
|
||||
refresh: function(postId, postVersion) {
|
||||
this.setProperties({
|
||||
loading: true,
|
||||
viewMode: Discourse.Mobile.mobileView ? "inline" : "side_by_side"
|
||||
});
|
||||
this.set("loading", true);
|
||||
|
||||
var self = this;
|
||||
Discourse.Post.loadRevision(postId, postVersion).then(function (result) {
|
||||
self.setProperties({
|
||||
loading: false,
|
||||
model: result
|
||||
});
|
||||
self.setProperties({ loading: false, model: result });
|
||||
});
|
||||
},
|
||||
|
||||
@ -46,9 +40,9 @@ Discourse.HistoryController = Discourse.ObjectController.extend(Discourse.ModalF
|
||||
var curCategory = Discourse.Category.findById(changes.current_category_id);
|
||||
|
||||
var raw = "";
|
||||
|
||||
prevCategory = Discourse.HTML.categoryLink(prevCategory);
|
||||
curCategory = Discourse.HTML.categoryLink(curCategory);
|
||||
var opts = { allowUncategorized: true };
|
||||
prevCategory = Discourse.HTML.categoryLink(prevCategory, opts);
|
||||
curCategory = Discourse.HTML.categoryLink(curCategory, opts);
|
||||
|
||||
if(viewMode === "side_by_side_markdown" || viewMode === "side_by_side") {
|
||||
raw = "<div class='span8'>" + prevCategory + "</div> <div class='span8 offset1'>" + curCategory + "</div>";
|
||||
@ -64,7 +58,7 @@ Discourse.HistoryController = Discourse.ObjectController.extend(Discourse.ModalF
|
||||
|
||||
return raw;
|
||||
|
||||
}.property("inline", "side_by_side", "side_by_side_markdown", "viewMode"),
|
||||
}.property("viewMode", "category_changes"),
|
||||
|
||||
title_diff: function() {
|
||||
var viewMode = this.get("viewMode");
|
||||
@ -72,11 +66,11 @@ Discourse.HistoryController = Discourse.ObjectController.extend(Discourse.ModalF
|
||||
viewMode = "side_by_side";
|
||||
}
|
||||
return this.get("title_changes." + viewMode);
|
||||
}.property("inline", "side_by_side", "side_by_side_markdown", "viewMode"),
|
||||
}.property("viewMode", "title_changes"),
|
||||
|
||||
body_diff: function() {
|
||||
return this.get("body_changes." + this.get("viewMode"));
|
||||
}.property("inline", "side_by_side", "side_by_side_markdown", "viewMode"),
|
||||
}.property("viewMode", "body_changes"),
|
||||
|
||||
actions: {
|
||||
loadFirstVersion: function() { this.refresh(this.get("post_id"), 2); },
|
||||
|
@ -23,12 +23,14 @@
|
||||
</div>
|
||||
<div id="revisions">
|
||||
{{#if title_changes}}
|
||||
<h2>{{{title_diff}}}</h2>
|
||||
<div class="row">
|
||||
<h2>{{{title_diff}}}</h2>
|
||||
</div>
|
||||
{{/if}}
|
||||
{{#if category_changes}}
|
||||
<div class="category-diff">
|
||||
{{{category_diff}}}
|
||||
</div>
|
||||
<div class="row">
|
||||
{{{category_diff}}}
|
||||
</div>
|
||||
{{/if}}
|
||||
{{{body_diff}}}
|
||||
</div>
|
||||
|
@ -24,6 +24,9 @@
|
||||
}
|
||||
#revisions {
|
||||
word-wrap: break-word;
|
||||
.row, table {
|
||||
margin-top: 10px;
|
||||
}
|
||||
}
|
||||
img {
|
||||
max-width: 670px;
|
||||
|
@ -7,42 +7,38 @@ class PostRevision < ActiveRecord::Base
|
||||
serialize :modifications, Hash
|
||||
|
||||
def body_changes
|
||||
changes_for("cooked", "raw")
|
||||
cooked_diff = DiscourseDiff.new(previous("cooked"), current("cooked"))
|
||||
raw_diff = DiscourseDiff.new(previous("raw"), current("raw"))
|
||||
|
||||
{
|
||||
inline: cooked_diff.inline_html,
|
||||
side_by_side: cooked_diff.side_by_side_html,
|
||||
side_by_side_markdown: raw_diff.side_by_side_markdown
|
||||
}
|
||||
end
|
||||
|
||||
def category_changes
|
||||
prev = previous("category_id")
|
||||
cur = current("category_id")
|
||||
return if prev == cur
|
||||
|
||||
{
|
||||
previous_category_id: previous("category_id"),
|
||||
current_category_id: current("category_id"),
|
||||
previous_category_id: prev,
|
||||
current_category_id: cur,
|
||||
}
|
||||
end
|
||||
|
||||
def title_changes
|
||||
changes_for("title", nil, true)
|
||||
end
|
||||
|
||||
def changes_for(name, markdown=nil, wrap=false)
|
||||
prev = previous(name)
|
||||
cur = current(name)
|
||||
|
||||
if wrap
|
||||
prev = "<div>#{CGI::escapeHTML(prev)}</div>"
|
||||
cur = "<div>#{CGI::escapeHTML(cur)}</div>"
|
||||
end
|
||||
prev = "<div>#{CGI::escapeHTML(previous("title"))}</div>"
|
||||
cur = "<div>#{CGI::escapeHTML(current("title"))}</div>"
|
||||
return if prev == cur
|
||||
|
||||
diff = DiscourseDiff.new(prev, cur)
|
||||
|
||||
result = {
|
||||
{
|
||||
inline: diff.inline_html,
|
||||
side_by_side: diff.side_by_side_html
|
||||
}
|
||||
|
||||
if markdown
|
||||
diff = DiscourseDiff.new(previous(markdown), current(markdown))
|
||||
result[:side_by_side_markdown] = diff.side_by_side_markdown
|
||||
end
|
||||
|
||||
result
|
||||
end
|
||||
|
||||
def previous(field)
|
||||
@ -54,12 +50,9 @@ class PostRevision < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def previous_revisions
|
||||
@previous_revs ||=
|
||||
PostRevision.where("post_id = ? AND number < ?",
|
||||
post_id, number
|
||||
)
|
||||
.order("number desc")
|
||||
.to_a
|
||||
@previous_revs ||= PostRevision.where("post_id = ? AND number < ?", post_id, number)
|
||||
.order("number desc")
|
||||
.to_a
|
||||
end
|
||||
|
||||
def has_topic_data?
|
||||
|
Loading…
x
Reference in New Issue
Block a user