From 16464e7e34725f12f3bf0edbca5f0f85bfc702ec Mon Sep 17 00:00:00 2001 From: uu59 Date: Wed, 24 Dec 2014 18:04:05 +0900 Subject: [PATCH] Display basically diff --- app/assets/stylesheets/common.css.scss | 8 ++++++++ .../concerns/setting_history_concern.rb | 3 +++ .../fluentd/settings/histories/_diff.html.erb | 15 +++++++++++++++ .../fluentd/settings/histories/show.html.haml | 15 ++++++++++++++- 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 app/views/fluentd/settings/histories/_diff.html.erb diff --git a/app/assets/stylesheets/common.css.scss b/app/assets/stylesheets/common.css.scss index 9e890e5..654efa5 100644 --- a/app/assets/stylesheets/common.css.scss +++ b/app/assets/stylesheets/common.css.scss @@ -169,3 +169,11 @@ label { .datetime { white-space: nowrap; } +.diff { + .deleted { + background-color: #fdd; + } + .added { + background-color: #dfd; + } +} diff --git a/app/controllers/concerns/setting_history_concern.rb b/app/controllers/concerns/setting_history_concern.rb index b043140..b1c46cb 100644 --- a/app/controllers/concerns/setting_history_concern.rb +++ b/app/controllers/concerns/setting_history_concern.rb @@ -8,6 +8,9 @@ module SettingHistoryConcern end def show + @current = @fluentd.agent.config + target = @backup_file.content + @sdiff = Diff::LCS.sdiff(@current.split("\n").map(&:rstrip), target.split("\n").map(&:rstrip)) end def reuse diff --git a/app/views/fluentd/settings/histories/_diff.html.erb b/app/views/fluentd/settings/histories/_diff.html.erb new file mode 100644 index 0000000..0015e2b --- /dev/null +++ b/app/views/fluentd/settings/histories/_diff.html.erb @@ -0,0 +1,15 @@ +
+<% @sdiff.each do |diff| %>
+<% case diff.action %>
+<% when "=" %>
+<%= diff.new_element %>
+<% when "!" %>
+- <%= diff.old_element %>
++ <%= diff.new_element %>
+<% when "-" %>
+- <%= diff.old_element %>
+<% when "+" %>
++ <%= diff.new_element %>
+<% end %>
+<% end %>
+
diff --git a/app/views/fluentd/settings/histories/show.html.haml b/app/views/fluentd/settings/histories/show.html.haml index 93b2186..f5dea73 100644 --- a/app/views/fluentd/settings/histories/show.html.haml +++ b/app/views/fluentd/settings/histories/show.html.haml @@ -14,8 +14,21 @@ %p= @backup_file.note.content .row - .col-xs-12 + .col-xs-6 + %h2 Current + %pre + = preserve do + = @current + .col-xs-6 + %h2 Target %pre = preserve do = @backup_file.content + .col-xs-12.diff + %h2 + Diff: + current + = ".." + = params[:id] + = preserve render "diff"