Skip to content

Commit

Permalink
Merge pull request #4111 from martinpovolny/textual_summary_fixes
Browse files Browse the repository at this point in the history
Textual summary fixes
  • Loading branch information
mzazrivec authored Jul 17, 2018
2 parents 7963502 + 6f76606 commit a447554
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 17 deletions.
21 changes: 10 additions & 11 deletions app/helpers/physical_server_helper/textual_summary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,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
Expand Down Expand Up @@ -209,12 +216,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
2 changes: 1 addition & 1 deletion app/helpers/textual_multilabel.rb
Original file line number Diff line number Diff line change
@@ -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
4 changes: 3 additions & 1 deletion app/javascript/react/textual_summary_click.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
18 changes: 14 additions & 4 deletions spec/helpers/physical_server_helper/textual_summary_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,31 @@

result = helper.textual_ipv4
expect(result[:label]).to eq("IPv4 Address")
expect(result[:value]).to eq("<a target=\"_blank\" href=\"https://192.168.1.1\">192.168.1.1</a>")
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("<a target=\"_blank\" href=\"https://192.168.1.1\">192.168.1.1</a>, <a target=\"_blank\" href=\"https://192.168.1.2\">192.168.1.2</a>")
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("<a target=\"_blank\" href=\"https://192.168.1.1\">192.168.1.1</a>, <a target=\"_blank\" href=\"https://192.168.1.2\">192.168.1.2</a>")
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

0 comments on commit a447554

Please sign in to comment.