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 Nov 30, 2017
1 parent 0f118fd commit 766996a
Show file tree
Hide file tree
Showing 28 changed files with 515 additions and 142 deletions.
21 changes: 0 additions & 21 deletions app/assets/javascripts/about.js

This file was deleted.

4 changes: 2 additions & 2 deletions app/assets/stylesheets/base.scss
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ select {

table {
clear: both;
margin-bottom: 6px !important;
//margin-bottom: 6px !important;

tr td:last-child {
.btn {
Expand Down Expand Up @@ -335,7 +335,7 @@ table {
}

#pagination {
margin-top: -6px;
margin-top: -19px !important;
}

.audits-pagination {
Expand Down
7 changes: 7 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@ def welcome
not_found
end

def empty_state
@klass = model_of_controller.new
rescue
not_found
end

def api_request?
request.format.try(:json?) || request.format.try(:yaml?)
end
Expand Down Expand Up @@ -98,6 +104,7 @@ def not_found(exception = nil)
logger.debug "not found: #{exception}" if exception
respond_to do |format|
format.html { render "common/404", :status => :not_found }
format.json { render json: {:error => "404 Not found", :status => :not_found} }
format.any { head :not_found}
end
true
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/plugins_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class PluginsController < ApplicationController
def empty_state
end
end
31 changes: 31 additions & 0 deletions app/helpers/about_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
module AboutHelper
def plugins
@plugins.map do |plugin|
{:name => plugin.name, :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
end
118 changes: 4 additions & 114 deletions app/views/about/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,122 +1,13 @@
<% 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', {:compute => compute_resources, :proxy => proxies,
:plugin => plugins, :provider => providers}.compact.to_json) %>
</div>
</div>
<div class="col-md-5">
Expand Down Expand Up @@ -144,5 +35,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>
5 changes: 5 additions & 0 deletions app/views/compute_resources/empty_state.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extends "layouts/empty_state"
object false
node do |u|
{: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."}
end
6 changes: 6 additions & 0 deletions app/views/layouts/empty_state.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object false
node do |u|
klass_name = @klass.class.name.underscore
{ :header => klass_name.humanize, :docUrl => "https://www.theforeman.org/manuals/1.15/index.html##{klass_name}",
:action => {:title => _("Create #{klass_name.humanize}"), :url => self.send("new_#{klass_name}_path") } }
end
6 changes: 6 additions & 0 deletions app/views/plugins/empty_state.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object false
node do |u|
{ :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.",
:docUrl => "https://www.theforeman.org/manuals/1.15/index.html#Plugins",
:action => {:title => _("Get a plugin"), :url => "https://projects.theforeman.org/projects/foreman/wiki/List_of_Plugins" } }
end
6 changes: 6 additions & 0 deletions app/views/smart_proxies/empty_state.json.rabl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extends "layouts/empty_state"
object false
node do |u|
{:description => "The Smart Proxy provides an easy way to add or extended existing subsystems, via
DHCP, DNS, Puppet, etc."}
end
1 change: 0 additions & 1 deletion config/initializers/assets.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
hidden_values
password_strength
proxy_status
about
parameter_override)

javascript += FastGettext.default_available_locales.map { |loc| "locale/#{loc}/app" }
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
end

get '(:controller)/help', :action => 'welcome', :as => "help"
get '(:controller)/empty_state', :action => 'empty_state'

constraints(:id => /[^\/]+/) do
resources :hosts do
member do
Expand Down Expand Up @@ -404,7 +406,7 @@
post 'template_selected'
post 'cluster_selected'
get 'resource_pools'
post 'ping'
get 'ping'
put 'associate'
put 'refresh_cache'
end
Expand Down
7 changes: 4 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@
"lodash": "~4.15.0",
"multiselect": "~0.9.12",
"patternfly": "^3.29.5",
"patternfly-react": "^0.8.1",
"patternfly-react": "^0.11.0",
"prop-types": "^15.6.0",
"raf": "^3.4.0",
"react": "^16.0.0",
"react": "^16.1.1",
"react-bootstrap": "^0.31.0",
"react-dom": "^16.0.0",
"react-bootstrap-table": "^4.1.5",
"react-dom": "^16.1.1",
"react-numeric-input": "^2.0.7",
"react-onclickoutside": "^6.6.2",
"react-redux": "^5.0.2",
Expand Down
8 changes: 8 additions & 0 deletions webpack/assets/javascripts/react_app/common/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,12 @@ export default {
});
},
noop: Function.prototype, // empty function
urlBuilder(controller, action, id = undefined) {
return `/${controller}/${id ? `${id}/` : ''}${action}`;
},
getQueryParam(query) {
const urlParams = new URLSearchParams(window.location.search);

return urlParams.get(query);
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import React from 'react';
import Status from '../../common/status';
import Table from '../../common/table';
import helpers from '../../../common/helpers';

class AboutComputeTable extends React.Component {
render() {
const columns = [
{
header: 'Name',
accessor: 'id',
isKey: true,
width: '40%',
formatter: (cell, row) => (
<a href={helpers.urlBuilder('compute_resources', '', cell.id)}>
{cell.name}
</a>
),
},
{
header: 'Type',
accessor: 'type',
width: '40%',
},
{
header: 'Status',
accessor: 'id',
width: '20%',
formatter: (cell, row) => (
<Status
data={{
type: 'compute_resurce',
id: cell.id,
url: helpers.urlBuilder(
'compute_resources',
'ping',
cell.id,
),
}}
/>
),
},
];

return (
<Table emptyState={{ model: 'compute_resources' }} data={this.props.data} columns={columns} />
);
}
}
export default AboutComputeTable;
25 changes: 25 additions & 0 deletions webpack/assets/javascripts/react_app/components/about/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import React from 'react';
import ForemanTabs from '../common/tabs';
import AboutComputeTable from './compute';
import AboutPluginTable from './plugin';
import AboutProviderTable from './provider';
import AboutProxyTable from './proxies';

class About extends React.Component {
render() {
const {
compute, proxy, provider, plugin,
} = this.props.data;
const tabs = [__('Smart Proxies'), __('Available Providers'), __('Compute Resources'), __('Plugins')];

return <ForemanTabs id='about_tabs' tabs={tabs} >
<AboutProxyTable data={proxy} />
<AboutProviderTable data={provider} />
<AboutComputeTable data={compute} />
<AboutPluginTable data={plugin} />
</ForemanTabs>;
}
}

export default About;
Loading

0 comments on commit 766996a

Please sign in to comment.