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 22, 2017
1 parent 0f118fd commit 5ed7f4c
Show file tree
Hide file tree
Showing 17 changed files with 323 additions and 114 deletions.
21 changes: 0 additions & 21 deletions app/assets/javascripts/about.js

This file was deleted.

104 changes: 13 additions & 91 deletions app/views/about/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<% title _("About") %>
<%= javascript 'proxy_status', 'charts', 'about' %>

<div class="row" id="about">
<div class="col-md-7">
Expand All @@ -16,105 +15,28 @@
</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 %>
<%= data = @smart_proxies.map {|proxy| {:id => {:name => proxy.name, :id => proxy.id},
:features => h(proxy.features.map(&:name).to_sentence)}} %>
<%= mount_react_component('AboutProxyTable', '#smart_proxies', data.to_json) %>
</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>
<%= data = @providers.map {|provider| {:provider => provider[:friendly_name],
:status => provider[:status] == :installed}}%>
<%= mount_react_component('AboutProviderTable', '#available_providers', data.to_json) %>

<%= _('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 %>
<%= data = @compute_resources.map {|compute| {:id => {:name => compute.name, :id => compute.id},
:type => compute.provider_friendly_name }} %>
<%= mount_react_component('AboutComputeTable', '#compute_resources', data.to_json) %>
</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 %>
<%= data = @plugins.map {|plugin| {:name => plugin.name, :description => plugin.description,
:author => plugin.author, :version => plugin.version }}%>
<%= mount_react_component('AboutPluginTable', '#plugins', data.to_json) %>
</div>
</div>
</div>
Expand Down
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
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@
post 'template_selected'
post 'cluster_selected'
get 'resource_pools'
post 'ping'
get 'ping'
put 'associate'
put 'refresh_cache'
end
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@
"react-numeric-input": "^2.0.7",
"react-onclickoutside": "^6.6.2",
"react-redux": "^5.0.2",
"react-table": "^6.7.4",
"redux": "^3.6.0",
"redux-form": "^7.0.3",
"redux-form-validators": "^2.0.1",
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}`;
},
perPageQuery(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,45 @@
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',
Cell: props => (
<a href={helpers.urlBuilder('compute_resources', '', props.value.id)}>
{props.value.name}
</a>
),
},
{
Header: 'Type',
accessor: 'type',
},
{
Header: 'Status',
accessor: 'id',
Cell: props => (
<Status
data={{
id: `compute_${props.value.id}`,
url: helpers.urlBuilder(
'compute_resources',
'ping',
props.value.id,
),
}}
/>
),
},
];

return (
<Table data={this.props.data} columns={columns} showPagination={false} />
);
}
}
export default AboutComputeTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import React from 'react';
import Table from '../../common/table';

class AboutPluginTable extends React.Component {
render() {
const columns = [
{
Header: 'Name',
accessor: 'name',
},
{
Header: 'Description',
accessor: 'description',
},
{
Header: 'Author',
accessor: 'author',
},
{
Header: 'Version',
accessor: 'version',
},
];

return (
<Table data={this.props.data} columns={columns} showPagination={false} />
);
}
}
export default AboutPluginTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import React from 'react';
import Table from '../../common/table';
import Icon from '../../common/Icon';

class AboutProviderTable extends React.Component {
render() {
const columns = [
{
Header: 'Provider',
accessor: 'provider',
},
{
Header: 'Installed',
accessor: 'status',
Cell: data => <Icon type={data.value ? 'ok' : 'error'} />,
},
];

return (
<Table data={this.props.data} columns={columns} showPagination={false} />
);
}
}
export default AboutProviderTable;
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import React from 'react';
import { connect } from 'react-redux';
import Status from '../../common/status';
import { simpleLoader } from '../../common/Loader';
import Table from '../../common/table';
import helpers from '../../../common/helpers';

class AboutProxyTable extends React.Component {
render() {
const columns = [
{
Header: 'Name',
accessor: 'id',
width: 100,
Cell: data => (
<a href={helpers.urlBuilder('smart_proxies', '', data.value.id)}>
{data.value.name}
</a>
),
},
{
Header: 'Features',
accessor: 'features',
width: 250,
},
{
Header: 'Status',
accessor: 'id',
width: 50,
Cell: data => (
<Status
data={{
id: `proxy_${data.value.id}`,
url: helpers.urlBuilder('smart_proxies', 'ping', data.value.id),
}}
/>
),
},
{
Header: 'Version',
accessor: 'id',
width: 100,
Cell: data => (
<span>
{this.props.status[`proxy_${data.value.id}`]
? this.props.status[`proxy_${data.value.id}`].message.version
: simpleLoader('xs')}
</span>
),
},
];

return (
<Table data={this.props.data} columns={columns} showPagination={false} />
);
}
}
const mapStateToProps = ({ status }) => ({ status });

export default connect(mapStateToProps)(AboutProxyTable);
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import React from 'react';
import { connect } from 'react-redux';
import { simpleLoader } from '../../common/Loader';
import * as StatusAction from '../../../redux/actions/status/';
import Icon from '../../common/Icon';

class Status extends React.Component {
componentDidMount() {
const { data: { id, url }, getStatus } = this.props;

getStatus({ id, url });
}

render() {
const {
status, message, error, success,
} = this.props.status;

if (status || success !== undefined) {
return (
<div title={message}>
<Icon type={status === 'OK' || success ? 'ok' : 'error'} />
</div>
);
}

if (error) {
return (
<div title={message}>
<Icon type="error" />
</div>
);
}

return simpleLoader('xs');
}
}

const mapStateToProps = (state, ownProps) => ({
status: state.status[ownProps.data.id] || {},
});

export default connect(mapStateToProps, StatusAction)(Status);
Loading

0 comments on commit 5ed7f4c

Please sign in to comment.