Skip to content

Commit

Permalink
Fixes #21737 - move about page to react
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer committed Jun 21, 2018
1 parent bde92a1 commit c1a6ed5
Show file tree
Hide file tree
Showing 33 changed files with 925 additions and 155 deletions.
21 changes: 0 additions & 21 deletions app/assets/javascripts/about.js

This file was deleted.

35 changes: 35 additions & 0 deletions app/helpers/about_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
module AboutHelper
def plugins
@plugins.map do |plugin|
{:name => {name: plugin.name, url: plugin.url}, :description => plugin.description,
:author => plugin.author, :version => plugin.version }
end
end

def proxies
@smart_proxies.map do |proxy|
{:id => {:name => proxy.name, :id => proxy.id},
:features => proxy.features.map(&:name).to_sentence}
end
end

def providers
nil unless SETTINGS[:unattended]
@providers.map do |provider|
{:provider => provider[:friendly_name],
:status => provider[:status] == :installed}
end
end

def compute_resources
nil unless SETTINGS[:unattended]
@compute_resources.map do |compute|
{:id => {:name => compute.name, :id => compute.id},
:type => compute.provider_friendly_name}
end
end

def about_data
{:compute => compute_resources, :proxy => proxies, :plugin => plugins, :provider => providers }
end
end
117 changes: 3 additions & 114 deletions app/views/about/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,122 +1,12 @@
<% title _("About") %>
<%= javascript 'proxy_status', 'charts', 'about' %>

<div class="row" id="about">
<div class="col-md-7">

<div class="stats-well">
<h4><%=_("System Status")%></h4>
<ul class="nav nav-tabs" data-tabs="tabs">
<li class="active"><a href="#smart_proxies" data-toggle="tab"><%= _('Smart Proxies') %></a></li>
<% if SETTINGS[:unattended] %>
<li><a href="#available_providers" data-toggle="tab"><%= _('Available Providers') %></a></li>
<li><a href="#compute_resources" data-toggle="tab"><%= _('Compute Resources') %></a></li>
<% end %>
<li><a href="#plugins" data-toggle="tab"><%= _('Plugins') %></a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="smart_proxies">
<% if @smart_proxies.empty? %>
<p class="ca"><%= _("No smart proxies to show") %></p>
<% else %>
<table class="table table-striped">
<thead>
<tr>
<th><%= _("Name") %></th>
<th><%= _("Features") %></th>
<th><%= _("Status") %></th>
<th><%= _("Version") %></th>
</tr>
</thead>
<tbody>
<% @smart_proxies.each do |proxy| %>
<tr class="proxy-show" data-url="<%= ping_smart_proxy_path(proxy) %>">
<td><%= link_to_if_authorized proxy.name, hash_for_smart_proxy_path(proxy) %></td>
<td><%=h proxy.features.map(&:name).to_sentence %></td>
<td><div class="proxy-show-status"><%= spinner %></div></td>
<td><div class="proxy-version"><%= spinner %></div></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<% if SETTINGS[:unattended] %>
<div class="tab-pane" id="available_providers">
<table class="table table-striped">
<thead>
<tr>
<th><%= _("Provider") %></th>
<th><%= _("Status") %></th>
</tr>
</thead>
<tbody>
<% @providers.sort_by { |prov| prov[:friendly_name].downcase }.each do |provider| %>
<tr>
<td><%= provider[:friendly_name] %></td>
<% if provider[:status] == :installed %>
<td><div class="label label-success"><%= _('Installed') %></div></td>
<% else %>
<td><div class="label label-default"><%= _('Not Installed') %></div></td>
<% end %>
</tr>
<% end %>
</tbody>
</table>
<%= _('To enable a provider, either install the OS package (e.g. foreman-libvirt) or enable the bundler group for development setup (e.g. ovirt).') %>
</div>
<div class="tab-pane" id="compute_resources">
<% if @compute_resources.empty? %>
<p class="ca"><%= _("No compute resource to show") %></p>
<% else %>
<table class="table table-striped table-fixed">
<thead>
<tr>
<th class="col-md-4"><%= _("Name") %></th>
<th class="col-md-4"><%= _("Type") %></th>
<th class="col-md-4"><%= _("Status") %></th>
</tr>
</thead>
<tbody>
<% @compute_resources.each do |compute| %>
<tr>
<td class="ellipsis"><%= link_to(compute.name, compute) %></td>
<td><%= compute.provider_friendly_name %></td>
<td><div class="compute-status" data-url=<%= ping_compute_resource_path(compute) %>><%= spinner %></div></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
<% end %>
<div class="tab-pane" id="plugins">
<% if @plugins.empty? %>
<p class="ca"><%= _("No plugins found") %></p>
<% else %>
<table class="table table-striped table-fixed">
<thead>
<tr>
<th class="col-md-4"><%= _("Name") %></th>
<th class="col-md-6"><%= _("Description") %></th>
<th class="col-md-2"><%= _("Author") %></th>
<th class="col-md-2"><%= _("Version") %></th>
</tr>
</thead>
<tbody>
<% @plugins.each do |plugin| %>
<tr>
<td><%= plugin.url.blank? ? plugin.name : link_to(plugin.name, plugin.url, :rel=>'external')%></td>
<td class="ellipsis"><%= _(plugin.description) %></td>
<td class="ellipsis"><%= plugin.author_url.blank? ? plugin.author : link_to(plugin.author, plugin.author_url)%></td>
<td><%= plugin.version %></td>
</tr>
<% end %>
</tbody>
</table>
<% end %>
</div>
</div>
<div id="tabs"></div>
<%= mount_react_component('About', '#tabs', about_data.compact.to_json) %>
</div>
</div>
<div class="col-md-5">
Expand Down Expand Up @@ -144,5 +34,4 @@
<p id="copyright-p"><%= (_("Version %{version} %{copyright} 2009-%{year} Paul Kelly and %{author}") % {:version => SETTINGS[:version], :copyright => "&copy;", :year=>DateTime.now.year, :author=>mail_to("ohadlevy@gmail.com", "Ohad Levy" )}).html_safe %></p>
</div>
</div>
</div>
</div>
</div>
1 change: 0 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ class << self
subnets
hidden_values
proxy_status
about
parameter_override)

javascript += FastGettext.default_available_locales.map { |loc| "locale/#{loc}/app" }
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@
post 'instance_type_selected'
post 'cluster_selected'
get 'resource_pools'
post 'ping'
get 'ping'
put 'associate'
put 'refresh_cache'
end
Expand Down
1 change: 0 additions & 1 deletion config/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ var pluginUtils = require('../script/plugin_webpack_directories');
var vendorEntry = require('./webpack.vendor');



module.exports = env => {
// must match config.webpack.dev_server.port
var devServerPort = 3808;
Expand Down
19 changes: 2 additions & 17 deletions test/integration/about_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,12 @@ class AboutIntegrationTest < IntegrationTestWithJavascript
assert page.has_selector?('h4', :text => "System Status"), "System Status was expected in the <h4> tag, but was not found"
assert page.has_selector?('h4', :text => "Support"), "Support was expected in the <h4> tag, but was not found"
assert page.has_selector?('h4', :text => "System Information"), "System Information was expected in the <h4> tag, but was not found"
assert page.has_link?("Smart Proxies", :href => "#smart_proxies")
assert page.has_link?("Compute Resources", :href => "#compute_resources")
assert page.has_link?("Smart Proxies", :href => "#")
assert page.has_link?("Compute Resources", :href => "#")
assert page.has_link?("Foreman Users", :href => "http://groups.google.com/group/foreman-users")
assert page.has_link?("Foreman Developers", :href => "http://groups.google.com/group/foreman-dev")
assert page.has_link?("issue tracker", :href => "http://projects.theforeman.org/projects/foreman/issues")
assert page.has_link?("Wiki", :href => "http://projects.theforeman.org")
assert page.has_link?("Ohad Levy", :href => "mailto:ohadlevy@gmail.com")
assert page.has_content?("Version")
end

test "about page proxies should have version" do
visit about_index_path
wait_for_ajax
assert page.has_selector?('th', :text => "Version")
assert page.has_selector?('div.proxy-version', :text => '1.13.0')
end

private

def wait_for_ajax
super
assert page.has_no_selector?('div.spinner'), 'AJAX spinners still active'
end
end
32 changes: 32 additions & 0 deletions webpack/assets/javascripts/react_app/common/EmptyStates.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
export const computeResource = () => ({
header: __('Compute Resource'),
description: __('Foreman supports creating and managing hosts on a number of virtualization and cloud services - referred to as “compute resources” - as well as bare metal hosts.'),
// eslint-disable-next-line no-undef
docUrl: `https://www.theforeman.org/manuals/${VERSION}/index.html#5.2ComputeResources`,
action: {
title: __('Create a compute resource'),
url: '/compute_resources/new',
},
});

export const plugin = () => ({
header: __('Plugin'),
description: __('Plugins are tools to extend and modify the functionality of Foreman. Plugins offer custom functions and features so that each user can tailor their environment to their specific needs.'),
// eslint-disable-next-line no-undef
docUrl: `https://www.theforeman.org/manuals/${VERSION}/index.html#Plugins`,
action: {
title: __('Get a plugin'),
url: 'https://projects.theforeman.org/projects/foreman/wiki/List_of_Plugins',
},
});

export const smartProxy = () => ({
header: __('Smart Proxy'),
description: __('The Smart Proxy provides an easy way to add or extended existing subsystems, via DHCP, DNS, Puppet, etc.'),
// eslint-disable-next-line no-undef
docUrl: `https://www.theforeman.org/manuals/${VERSION}/index.html#Smart-Proxy`,
action: {
title: __('Create a smart proxy'),
url: '/smart_proxies/new',
},
});
3 changes: 3 additions & 0 deletions webpack/assets/javascripts/react_app/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,7 @@ export default {
});
},
noop,
urlBuilder(controller, action, id = undefined) {
return `/${controller}/${id ? `${id}/` : ''}${action}`;
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`about page should render 1`] = `
<TabsWrapper
id="about_tabs"
tabs={
Array [
"Smart Proxies",
"Available Providers",
"Compute Resources",
"Plugins",
]
}
>
<AboutProxyTable
data={
Array [
Object {
"features": "Facts, Logs, DNS, DHCP, and Puppet",
"id": Object {
"id": 1,
"name": "regular",
},
},
]
}
/>
<AboutProviderTable
data={
Array [
Object {
"provider": "Libvirt",
"status": true,
},
Object {
"provider": "oVirt",
"status": true,
},
Object {
"provider": "EC2",
"status": true,
},
Object {
"provider": "VMware",
"status": true,
},
Object {
"provider": "OpenStack",
"status": true,
},
Object {
"provider": "Rackspace",
"status": true,
},
Object {
"provider": "Google",
"status": true,
},
]
}
/>
<AboutComputeTable
data={
Array [
Object {
"id": Object {
"id": 1,
"name": "Libvirt",
},
"type": "Libvirt",
},
Object {
"id": Object {
"id": 2,
"name": "Ovirt",
},
"type": "Ovirt",
},
]
}
/>
<AboutPluginTable
data={
Array [
Object {
"author": "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ex ea difficultate illae fallaciloquae",
"description": "MaaS Discovery Plugin engine for Foreman",
"name": "foreman_discovery",
"version": "11.0.0",
},
]
}
/>
</TabsWrapper>
`;
Loading

0 comments on commit c1a6ed5

Please sign in to comment.