From 940dea9acb34e497edf087e03574229739725b0d Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Mon, 11 Jun 2018 14:32:10 +0200 Subject: [PATCH 1/3] TextualSummary: fix TextualMultilabel. --- app/helpers/textual_multilabel.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/helpers/textual_multilabel.rb b/app/helpers/textual_multilabel.rb index 72104f044d3..5a655ebdd83 100644 --- a/app/helpers/textual_multilabel.rb +++ b/app/helpers/textual_multilabel.rb @@ -1,5 +1,5 @@ TextualMultilabel = Struct.new(:title, :options) do def locals - {:title => title, :values => options[:values], :rows => options[:values], :labels => options[:labels], :component => 'SimpleTable'} + {:title => title, :values => options[:values], :labels => options[:labels], :component => 'SimpleTable'} end end From cfefc83e79fcc818166bff6862373e4820a786d0 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Tue, 17 Jul 2018 14:37:52 +0200 Subject: [PATCH 2/3] TextualSummary: fix external links in PhysicalServer. --- .../physical_server_helper/textual_summary.rb | 21 +++++++++---------- app/javascript/react/textual_summary_click.js | 4 +++- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/app/helpers/physical_server_helper/textual_summary.rb b/app/helpers/physical_server_helper/textual_summary.rb index 4392bc35d8b..52e91f5407a 100644 --- a/app/helpers/physical_server_helper/textual_summary.rb +++ b/app/helpers/physical_server_helper/textual_summary.rb @@ -128,11 +128,18 @@ def textual_ipv4 # by commas, so first convert the array into a string, separating each array element # with a comma. Then split this string back into an array using a comma, possibly # followed by whitespace as the delimiter. Finally, iterate through the array - # and convert each element into a URL containing an IP address. + # and convert each element into link with an URL containing an IP address. ip_addresses = ip_addresses.join(",").split(/,\s*/) - ip_address_urls = ip_addresses.collect { |ip_address| create_https_url(ip_address) } - {:label => _("IPv4 Address"), :value => sanitize(ip_address_urls.join(", "), :attributes => %w(href target)) } + ip_address_links = ip_addresses.collect do |ip| + { + :link => URI::HTTPS.build(:host => ip).to_s, + :external => true, + :value => ip + } + end + + {:label => _("IPv4 Address"), :value => ip_address_links} end def textual_ipv6 @@ -203,12 +210,4 @@ def textual_compliance_name def textual_compliance_status {:label => _("Status"), :value => @record.ems_compliance_status } end - - private - - def create_https_url(ip) - # A target argument with a value of "_blank" is passed so that the - # page loads in a new tab when the link is clicked. - ip.present? ? link_to(ip, URI::HTTPS.build(:host => ip).to_s, :target => "_blank") : '' - end end diff --git a/app/javascript/react/textual_summary_click.js b/app/javascript/react/textual_summary_click.js index ec37ac38bd5..70036946bc3 100644 --- a/app/javascript/react/textual_summary_click.js +++ b/app/javascript/react/textual_summary_click.js @@ -5,7 +5,9 @@ export default function textualSummaryGenericClick(item, event) { return; } - if (item.explorer) { + if (item.external) { + window.open(item.link, '_blank'); + } else if (item.explorer) { $.ajax({ data: `authenticity_token=${encodeURIComponent($('meta[name=csrf-token]').attr('content'))}`, dataType: 'script', From 6f766064e648e686f89dc145523d1990eec95791 Mon Sep 17 00:00:00 2001 From: Martin Povolny Date: Tue, 17 Jul 2018 16:10:10 +0200 Subject: [PATCH 3/3] TextualSummary: fix external links in PhysicalServer test. --- .../textual_summary_spec.rb | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/spec/helpers/physical_server_helper/textual_summary_spec.rb b/spec/helpers/physical_server_helper/textual_summary_spec.rb index 5354f4b921f..a89ad16334a 100644 --- a/spec/helpers/physical_server_helper/textual_summary_spec.rb +++ b/spec/helpers/physical_server_helper/textual_summary_spec.rb @@ -8,21 +8,31 @@ result = helper.textual_ipv4 expect(result[:label]).to eq("IPv4 Address") - expect(result[:value]).to eq("192.168.1.1") + expect(result[:value]).to eq([{:link => "https://192.168.1.1", :external => true, :value => "192.168.1.1"}]) network.ipaddress = "192.168.1.1,192.168.1.2" result = helper.textual_ipv4 expect(result[:label]).to eq("IPv4 Address") - expect(result[:value]).to eq("192.168.1.1, 192.168.1.2") + expect(result[:value]).to eq( + [ + {:link => "https://192.168.1.1", :external => true, :value => "192.168.1.1"}, + {:link => "https://192.168.1.2", :external => true, :value => "192.168.1.2"} + ] + ) network.ipaddress = "192.168.1.1, 192.168.1.2" result = helper.textual_ipv4 expect(result[:label]).to eq("IPv4 Address") - expect(result[:value]).to eq("192.168.1.1, 192.168.1.2") + expect(result[:value]).to eq( + [ + {:link => "https://192.168.1.1", :external => true, :value => "192.168.1.1"}, + {:link => "https://192.168.1.2", :external => true, :value => "192.168.1.2"} + ] + ) network.ipaddress = "" result = helper.textual_ipv4 expect(result[:label]).to eq("IPv4 Address") - expect(result[:value]).to eq("") + expect(result[:value]).to eq([]) end end