From 9fcbffcff100a9e091b1177c01459672f6516a25 Mon Sep 17 00:00:00 2001 From: David Roetzel Date: Wed, 6 Mar 2024 14:32:55 +0100 Subject: [PATCH] Add diff view to lookup results #301 Just like with regular value display from a single file this now checks if a node is from a different environment than the selected one. If it is, the same tabbed view with a diff is presented, showing the lookup result in the selected environment and the diff to the lookup in the original environment. --- app/controllers/lookups_controller.rb | 6 ++++++ app/views/keys/_value.html.erb | 21 +++------------------ app/views/lookups/show.html.erb | 10 +++++++++- app/views/{keys => shared}/_diff.html.erb | 2 +- app/views/shared/_tabbed_diff.html.erb | 18 ++++++++++++++++++ 5 files changed, 37 insertions(+), 20 deletions(-) rename app/views/{keys => shared}/_diff.html.erb (69%) create mode 100644 app/views/shared/_tabbed_diff.html.erb diff --git a/app/controllers/lookups_controller.rb b/app/controllers/lookups_controller.rb index 31220e68..e724ff57 100644 --- a/app/controllers/lookups_controller.rb +++ b/app/controllers/lookups_controller.rb @@ -5,6 +5,7 @@ class LookupsController < ApplicationController def show @result = @key.lookup(@node) + lookup_in_original_environment if @node.environment != @environment rescue Hdm::Error => e @error = e @@ -19,4 +20,9 @@ def load_keys @key = Key.new(environment: @environment, name: params[:key_id]) authorize! :show, @key end + + def lookup_in_original_environment + original_key = Key.new(environment: @node.environment, name: params[:key_id]) + @original_result = original_key.lookup(@node) + end end diff --git a/app/views/keys/_value.html.erb b/app/views/keys/_value.html.erb index 15392f29..cfbccadf 100644 --- a/app/views/keys/_value.html.erb +++ b/app/views/keys/_value.html.erb @@ -1,22 +1,7 @@ <% if file.has_differing_value_in_original_environment?(@key) %> - - -
-
" class="tab-pane fade show active" role="tabpanel" aria-labelledby="<%= "tab-value-#{dom_id(file)}" %>"> - <%= render "form", file: file, value: value %> -
- -
" class="tab-pane fade" role="tabpanel" aria-labelledby="<%= "tab-diff-#{dom_id(file)}" %>"> - <%= render "diff", file: file, value: value %> -
-
+ <%= render "shared/tabbed_diff", dom_id: dom_id(file), original_value:file.value_from_original_environment(key: @key).value, current_value: value.value do %> + <%= render "form", file: file, value: value %> + <% end %> <% else %> <%= render "form", file: file, value: value %> <% end %> diff --git a/app/views/lookups/show.html.erb b/app/views/lookups/show.html.erb index 65526e1c..73d4b0d0 100644 --- a/app/views/lookups/show.html.erb +++ b/app/views/lookups/show.html.erb @@ -1,3 +1,11 @@ <%= turbo_frame_tag "lookup-result-frame" do %> -
<%= HieraData::Util.yaml_format(@result) %>
+ <% if @original_result && @original_result != @result %> + <%= render "shared/tabbed_diff", dom_id: "lookup-#{dom_id(@key)}", original_value: @original_result, current_value: @result do %> +
+
<%= HieraData::Util.yaml_format(@result) %>
+
+ <% end %> + <% else %> +
<%= HieraData::Util.yaml_format(@result) %>
+ <% end %> <% end %> diff --git a/app/views/keys/_diff.html.erb b/app/views/shared/_diff.html.erb similarity index 69% rename from app/views/keys/_diff.html.erb rename to app/views/shared/_diff.html.erb index 5f7f40f1..7ac89852 100644 --- a/app/views/keys/_diff.html.erb +++ b/app/views/shared/_diff.html.erb @@ -1,4 +1,4 @@ -<% split_diff = Diffy::SplitDiff.new(file.value_from_original_environment(key: @key).value, value.value, format: :html) %> +<% split_diff = Diffy::SplitDiff.new(original_value, current_value, format: :html) %> diff --git a/app/views/shared/_tabbed_diff.html.erb b/app/views/shared/_tabbed_diff.html.erb new file mode 100644 index 00000000..8f3026ff --- /dev/null +++ b/app/views/shared/_tabbed_diff.html.erb @@ -0,0 +1,18 @@ + + +
+
" class="tab-pane fade show active" role="tabpanel" aria-labelledby="<%= "tab-value-#{dom_id}" %>"> + <%= yield %> +
+ +
" class="tab-pane fade" role="tabpanel" aria-labelledby="<%= "tab-diff-#{dom_id}" %>"> + <%= render "shared/diff", current_value:, original_value: %> +
+