mirror of
https://github.com/discourse/discourse.git
synced 2024-12-01 03:13:38 +08:00
Merge pull request #785 from ZogStriP/show-diff-in-history-view
show diff in post history view
This commit is contained in:
commit
1b3faaa60f
1378
app/assets/javascripts/defer/google_diff_match_patch.js
Normal file
1378
app/assets/javascripts/defer/google_diff_match_patch.js
Normal file
File diff suppressed because it is too large
Load Diff
|
@ -1,7 +1,7 @@
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
|
|
||||||
{{#if view.loading}}
|
{{#if view.loading}}
|
||||||
Loading...
|
{{i18n loading}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class='span8'>
|
<div class='span8'>
|
||||||
|
|
||||||
|
@ -29,8 +29,8 @@
|
||||||
selectionBinding="view.versionRight"}}
|
selectionBinding="view.versionRight"}}
|
||||||
|
|
||||||
<div class='contents'>
|
<div class='contents'>
|
||||||
{{#if view.postRight}}
|
{{#if view.diff}}
|
||||||
{{{view.postRight.cooked}}}
|
{{{view.diff}}}
|
||||||
{{else}}
|
{{else}}
|
||||||
<div class='history-loading'>{{i18n loading}}</div>
|
<div class='history-loading'>{{i18n loading}}</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
@ -40,4 +40,3 @@
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -1,3 +1,6 @@
|
||||||
|
/*jshint newcap:false*/
|
||||||
|
/*global diff_match_patch:true assetPath:true*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
This view handles rendering of the history of a post
|
This view handles rendering of the history of a post
|
||||||
|
|
||||||
|
@ -10,6 +13,16 @@ Discourse.HistoryView = Discourse.View.extend({
|
||||||
templateName: 'history',
|
templateName: 'history',
|
||||||
title: Em.String.i18n('history'),
|
title: Em.String.i18n('history'),
|
||||||
modalClass: 'history-modal',
|
modalClass: 'history-modal',
|
||||||
|
diffLibraryLoaded: false,
|
||||||
|
diff: null,
|
||||||
|
|
||||||
|
init: function(){
|
||||||
|
this._super();
|
||||||
|
var historyView = this;
|
||||||
|
$LAB.script(assetPath('defer/google_diff_match_patch')).wait(function(){
|
||||||
|
historyView.set('diffLibraryLoaded', true);
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
loadSide: function(side) {
|
loadSide: function(side) {
|
||||||
if (this.get("version" + side)) {
|
if (this.get("version" + side)) {
|
||||||
|
@ -34,10 +47,23 @@ Discourse.HistoryView = Discourse.View.extend({
|
||||||
this.loadSide("Right");
|
this.loadSide("Right");
|
||||||
}.observes('versionRight'),
|
}.observes('versionRight'),
|
||||||
|
|
||||||
|
loadedPosts: function() {
|
||||||
|
if (this.get('diffLibraryLoaded') && this.get('postLeft') && this.get('postRight')) {
|
||||||
|
var dmp = new diff_match_patch(),
|
||||||
|
before = this.get("postLeft.cooked"),
|
||||||
|
after = this.get("postRight.cooked"),
|
||||||
|
diff = dmp.diff_main(before, after);
|
||||||
|
dmp.diff_cleanupSemantic(diff);
|
||||||
|
this.set('diff', dmp.diff_prettyHtml(diff));
|
||||||
|
}
|
||||||
|
}.observes('diffLibraryLoaded', 'postLeft', 'postRight'),
|
||||||
|
|
||||||
didInsertElement: function() {
|
didInsertElement: function() {
|
||||||
this.set('loading', true);
|
this.setProperties({
|
||||||
this.set('postLeft', null);
|
loading: true,
|
||||||
this.set('postRight', null);
|
postLeft: null,
|
||||||
|
postRight: null
|
||||||
|
});
|
||||||
|
|
||||||
var historyView = this;
|
var historyView = this;
|
||||||
this.get('originalPost').loadVersions().then(function(result) {
|
this.get('originalPost').loadVersions().then(function(result) {
|
||||||
|
@ -46,12 +72,12 @@ Discourse.HistoryView = Discourse.View.extend({
|
||||||
Em.String.i18n("changed_by", { author: item.display_username });
|
Em.String.i18n("changed_by", { author: item.display_username });
|
||||||
});
|
});
|
||||||
|
|
||||||
historyView.set('loading', false);
|
historyView.setProperties({
|
||||||
historyView.set('versionLeft', result.first());
|
loading: false,
|
||||||
historyView.set('versionRight', result.last());
|
versionLeft: result.first(),
|
||||||
historyView.set('versions', result);
|
versionRight: result.last(),
|
||||||
|
versions: result
|
||||||
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,6 +8,12 @@
|
||||||
width: 960px;
|
width: 960px;
|
||||||
margin-left: -460px;
|
margin-left: -460px;
|
||||||
min-height: 500px;
|
min-height: 500px;
|
||||||
|
ins {
|
||||||
|
background: #e6ffe6;
|
||||||
|
}
|
||||||
|
del {
|
||||||
|
background: #ffe6e6;
|
||||||
|
}
|
||||||
.modal-header {
|
.modal-header {
|
||||||
height: 42px;
|
height: 42px;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,8 @@
|
||||||
|
|
||||||
// TODO: automate this to grab from the manifest, Rails voodoo should be able to get it
|
// TODO: automate this to grab from the manifest, Rails voodoo should be able to get it
|
||||||
var map = {
|
var map = {
|
||||||
'defer/html-sanitizer-bundle': <%= asset_path('defer/html-sanitizer-bundle.js').inspect.html_safe %>
|
'defer/html-sanitizer-bundle': <%= asset_path('defer/html-sanitizer-bundle.js').inspect.html_safe %>,
|
||||||
|
'defer/google_diff_match_patch': <%= asset_path('defer/google_diff_match_patch.js').inspect.html_safe %>
|
||||||
};
|
};
|
||||||
|
|
||||||
var assetPath = function(asset){
|
var assetPath = function(asset){
|
||||||
|
|
|
@ -29,10 +29,12 @@ module Discourse
|
||||||
|
|
||||||
config.assets.paths += %W(#{config.root}/config/locales)
|
config.assets.paths += %W(#{config.root}/config/locales)
|
||||||
|
|
||||||
config.assets.precompile += [
|
config.assets.precompile += ['admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js', 'jquery.js']
|
||||||
'admin.js', 'admin.css', 'shiny/shiny.css', 'preload_store.js',
|
|
||||||
'jquery.js', 'defer/html-sanitizer-bundle.js'
|
# Precompile all defer
|
||||||
]
|
Dir.glob("app/assets/javascripts/defer/*.js").each do |file|
|
||||||
|
config.assets.precompile << file
|
||||||
|
end
|
||||||
|
|
||||||
# Precompile all available locales
|
# Precompile all available locales
|
||||||
Dir.glob("app/assets/javascripts/locales/*.js.erb").each do |file|
|
Dir.glob("app/assets/javascripts/locales/*.js.erb").each do |file|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user