diff options
| -rw-r--r-- | app/controllers/revisions_controller.rb | 7 | ||||
| -rw-r--r-- | app/views/revisions/diff.html.erb | 25 | ||||
| -rw-r--r-- | test/controllers/revisions_controller_test.rb | 32 |
3 files changed, 59 insertions, 5 deletions
diff --git a/app/controllers/revisions_controller.rb b/app/controllers/revisions_controller.rb index 4b0c549..0aed243 100644 --- a/app/controllers/revisions_controller.rb +++ b/app/controllers/revisions_controller.rb | |||
| @@ -29,8 +29,13 @@ class RevisionsController < ApplicationController | |||
| 29 | redirect_to(node_path(@node)) and return | 29 | redirect_to(node_path(@node)) and return |
| 30 | end | 30 | end |
| 31 | 31 | ||
| 32 | @locale_summary = @end.locale_diff_summary(@start) | ||
| 33 | requested_locale = params[:locale].presence&.to_sym | ||
| 34 | default_locale = @locale_summary.find { |s| s[:changed] }&.dig(:locale) || I18n.default_locale | ||
| 35 | @locale = @locale_summary.any? { |s| s[:locale] == requested_locale } ? requested_locale : default_locale | ||
| 36 | |||
| 32 | @diff_view = params[:view] == "side_by_side" ? :side_by_side : :inline | 37 | @diff_view = params[:view] == "side_by_side" ? :side_by_side : :inline |
| 33 | @diff = @end.diff_against(@start, view: @diff_view) | 38 | @diff = @end.diff_against(@start, view: @diff_view, locale: @locale) |
| 34 | @available_layer_pairs = @node.available_layer_pairs | 39 | @available_layer_pairs = @node.available_layer_pairs |
| 35 | @locked_by_other = @node.locked? && @node.lock_owner != current_user | 40 | @locked_by_other = @node.locked? && @node.lock_owner != current_user |
| 36 | end | 41 | end |
diff --git a/app/views/revisions/diff.html.erb b/app/views/revisions/diff.html.erb index 5638b7a..149b17c 100644 --- a/app/views/revisions/diff.html.erb +++ b/app/views/revisions/diff.html.erb | |||
| @@ -7,20 +7,37 @@ | |||
| 7 | <p class="diff_comparison_label"> | 7 | <p class="diff_comparison_label"> |
| 8 | Comparing <strong><%= describe_page_reference(params[:start_revision]) %></strong> | 8 | Comparing <strong><%= describe_page_reference(params[:start_revision]) %></strong> |
| 9 | against <strong><%= describe_page_reference(params[:end_revision]) %></strong> | 9 | against <strong><%= describe_page_reference(params[:end_revision]) %></strong> |
| 10 | — showing the <strong><%= @locale.to_s.upcase %></strong> translation | ||
| 10 | </p> | 11 | </p> |
| 11 | 12 | ||
| 13 | <% if @locale_summary.size > 1 %> | ||
| 14 | <p class="diff_locale_toggle"> | ||
| 15 | Locale: | ||
| 16 | <% @locale_summary.each_with_index do |s, i| %> | ||
| 17 | <%= " · ".html_safe if i > 0 %> | ||
| 18 | <% label = "#{s[:locale].to_s.upcase}#{' *' if s[:changed]}" %> | ||
| 19 | <% if s[:locale] == @locale %> | ||
| 20 | <strong><%= label %></strong> | ||
| 21 | <% else %> | ||
| 22 | <%= link_to label, diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: @diff_view, locale: s[:locale]) %> | ||
| 23 | <% end %> | ||
| 24 | <% end %> | ||
| 25 | </p> | ||
| 26 | <p class="field_hint">* has a difference between these two versions.</p> | ||
| 27 | <% end %> | ||
| 28 | |||
| 12 | <p class="diff_view_toggle"> | 29 | <p class="diff_view_toggle"> |
| 13 | View: | 30 | View: |
| 14 | <% if @diff_view == :inline %> | 31 | <% if @diff_view == :inline %> |
| 15 | <strong>Inline</strong> | 32 | <strong>Inline</strong> |
| 16 | <% else %> | 33 | <% else %> |
| 17 | <%= link_to 'Inline', diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'inline') %> | 34 | <%= link_to 'Inline', diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'inline', locale: @locale) %> |
| 18 | <% end %> | 35 | <% end %> |
| 19 | · | 36 | · |
| 20 | <% if @diff_view == :side_by_side %> | 37 | <% if @diff_view == :side_by_side %> |
| 21 | <strong>Side by side</strong> | 38 | <strong>Side by side</strong> |
| 22 | <% else %> | 39 | <% else %> |
| 23 | <%= link_to 'Side by side', diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'side_by_side') %> | 40 | <%= link_to 'Side by side', diff_node_revisions_path(@node, start_revision: params[:start_revision], end_revision: params[:end_revision], view: 'side_by_side', locale: @locale) %> |
| 24 | <% end %> | 41 | <% end %> |
| 25 | </p> | 42 | </p> |
| 26 | 43 | ||
| @@ -31,6 +48,7 @@ | |||
| 31 | <%= select_tag :start_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:start_revision].to_i) %> | 48 | <%= select_tag :start_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:start_revision].to_i) %> |
| 32 | <%= select_tag :end_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:end_revision].to_i) %> | 49 | <%= select_tag :end_revision, options_for_select(@node.pages.map{|x| x.revision}, params[:end_revision].to_i) %> |
| 33 | <%= hidden_field_tag :view, @diff_view %> | 50 | <%= hidden_field_tag :view, @diff_view %> |
| 51 | <%= hidden_field_tag :locale, @locale %> | ||
| 34 | <%= submit_tag 'Diff' %> | 52 | <%= submit_tag 'Diff' %> |
| 35 | <% end %> | 53 | <% end %> |
| 36 | <% else %> | 54 | <% else %> |
| @@ -44,10 +62,9 @@ | |||
| 44 | <%= button_to "Diff #{pair.first.to_s.capitalize} vs. #{pair.last.to_s.capitalize}", | 62 | <%= button_to "Diff #{pair.first.to_s.capitalize} vs. #{pair.last.to_s.capitalize}", |
| 45 | diff_node_revisions_path(@node), | 63 | diff_node_revisions_path(@node), |
| 46 | method: :get, | 64 | method: :get, |
| 47 | params: { start_revision: pair.first, end_revision: pair.last, view: @diff_view }, | 65 | params: { start_revision: pair.first, end_revision: pair.last, view: @diff_view, locale: @locale }, |
| 48 | form: { class: 'button_to computation' } %> | 66 | form: { class: 'button_to computation' } %> |
| 49 | <% end %> | 67 | <% end %> |
| 50 | |||
| 51 | <% if !@locked_by_other && (@node.autosave || @node.draft) %> | 68 | <% if !@locked_by_other && (@node.autosave || @node.draft) %> |
| 52 | <%= button_to revert_node_path(@node), method: :put, | 69 | <%= button_to revert_node_path(@node), method: :put, |
| 53 | params: { return_to: request.fullpath }, | 70 | params: { return_to: request.fullpath }, |
diff --git a/test/controllers/revisions_controller_test.rb b/test/controllers/revisions_controller_test.rb index 76d4e8c..e5726f7 100644 --- a/test/controllers/revisions_controller_test.rb +++ b/test/controllers/revisions_controller_test.rb | |||
| @@ -168,4 +168,36 @@ class RevisionsControllerTest < ActionController::TestCase | |||
| 168 | assert_response :success | 168 | assert_response :success |
| 169 | assert_select "a[href=?]", node_path(@node) | 169 | assert_select "a[href=?]", node_path(@node) |
| 170 | end | 170 | end |
| 171 | |||
| 172 | test "diff defaults to a locale that actually changed, not the ambient default" do | ||
| 173 | login_as :quentin | ||
| 174 | node = Node.root.children.create!(:slug => "diff_default_locale_test") | ||
| 175 | node.draft.save! | ||
| 176 | node.publish_draft! | ||
| 177 | |||
| 178 | node.find_or_create_draft(@user) | ||
| 179 | Globalize.with_locale(:en) { node.draft.update!(:title => "Changed in English only") } | ||
| 180 | node.draft.save! | ||
| 181 | |||
| 182 | post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft" }) | ||
| 183 | |||
| 184 | assert_response :success | ||
| 185 | assert_match(/Changed/, response.body) | ||
| 186 | end | ||
| 187 | |||
| 188 | test "diff respects an explicitly requested locale over the auto-detected one" do | ||
| 189 | login_as :quentin | ||
| 190 | node = Node.root.children.create!(:slug => "diff_explicit_locale_test") | ||
| 191 | node.draft.save! | ||
| 192 | node.publish_draft! | ||
| 193 | |||
| 194 | node.find_or_create_draft(@user) | ||
| 195 | Globalize.with_locale(:en) { node.draft.update!(:title => "English changed") } | ||
| 196 | node.draft.save! | ||
| 197 | |||
| 198 | post(:diff, params: { :node_id => node.id, :start_revision => "head", :end_revision => "draft", :locale => "de" }) | ||
| 199 | |||
| 200 | assert_response :success | ||
| 201 | assert_no_match(/English changed/, response.body) | ||
| 202 | end | ||
| 171 | end | 203 | end |
