Skip to content

Commit

Permalink
Fixes #33484 - add setting for opt-in/out the new host details
Browse files Browse the repository at this point in the history
  • Loading branch information
amirfefer authored and ezr-ondrej committed Nov 2, 2021
1 parent 02a057b commit 2876578
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 12 deletions.
6 changes: 6 additions & 0 deletions app/assets/javascripts/host_edit.js
Expand Up @@ -159,6 +159,7 @@ function update_capabilities(capabilities) {
var stop_pooling;

function submit_with_all_params() {
var fqdn = $('.fqdn')[0].textContent;
$('form.hostresource-form input[type="submit"]').attr('disabled', true);
stop_pooling = false;
$('body').css('cursor', 'progress');
Expand All @@ -170,6 +171,11 @@ function submit_with_all_params() {
url: $('form').attr('action'),
data: serializeForm(),
success: function(response) {
// workaround for redirecting to the new host details page
if (!response.includes('id="main"')) {
return tfm.nav.pushUrl('/new/hosts/' + fqdn);
}

$('#host-progress').hide();
$('#content').replaceWith($('#content', response));
$(document.body).trigger('ContentLoad');
Expand Down
8 changes: 6 additions & 2 deletions app/controllers/hosts_controller.rb
Expand Up @@ -96,7 +96,7 @@ def create
@host.managed = true if (params[:host] && params[:host][:managed].nil?)
forward_url_options
if @host.save
process_success :success_redirect => host_path(@host)
process_success :success_redirect => current_host_details_path(@host)
else
load_vars_for_ajax
offer_to_overwrite_conflicts
Expand All @@ -114,7 +114,7 @@ def update
attributes = @host.apply_inherited_attributes(host_params)
attributes.delete(:compute_resource_id)
if @host.update(attributes)
process_success :success_redirect => host_path(@host)
process_success :success_redirect => current_host_details_path(@host)
else
taxonomy_scope
load_vars_for_ajax
Expand Down Expand Up @@ -921,4 +921,8 @@ def redirection_url_on_host_deletion
return default_redirection if (path_hash.nil? || (path_hash && path_hash[:action] != 'index'))
{ :success_redirect => saved_redirect_url_or(send("#{controller_name}_url")) }
end

def current_host_details_path(host)
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host)
end
end
4 changes: 4 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -441,4 +441,8 @@ def app_metadata
def ui_settings
{ perPage: Setting['entries_per_page'], destroyVmOnHostDelete: Setting['destroy_vm_on_host_delete'] }
end

def current_host_details_path(host)
Setting['host_details_ui'] ? host_details_page_path(host) : host_path(host)
end
end
4 changes: 2 additions & 2 deletions app/helpers/audits_helper.rb
Expand Up @@ -203,7 +203,7 @@ def nested_host_audit_breadcrumbs
},
{
caption: @host.name,
url: (host_path(@host) if authorized_for(hash_for_host_path(@host))),
url: (current_host_details_path(@host) if authorized_for(hash_for_host_path(@host))),
},
{
caption: _('Audits'),
Expand Down Expand Up @@ -366,7 +366,7 @@ def host_details_action(host, options = {})
auth_options = send("hash_for_#{host_path_name}", :id => host.to_param).merge(
:auth_object => host, :auth_action => 'view')
if authorized_for(auth_options)
action_details[:url] = send(host_path_name, :id => host.to_param)
action_details[:url] = current_host_details_path(host)
else
action_details.merge!(:url => '#', :css_class => 'btn btn-default disabled', :disabled => true)
end
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/hosts_helper.rb
Expand Up @@ -92,7 +92,7 @@ def name_column(host)
tooltip = displayable_statuses.sort_by(&:type).map { |status| "#{_(status.name)}: #{_(status.to_label)}" }.join(', ')

content = content_tag(:span, "", {:rel => "twipsy", :class => style, :"data-original-title" => tooltip})
content += link_to(" #{host}", host_path(host))
content += link_to(" #{host}", current_host_details_path(host))
content
end

Expand Down
5 changes: 5 additions & 0 deletions app/registries/foreman/settings/general.rb
Expand Up @@ -99,5 +99,10 @@
description: N_('Duration in days to preserve audits for. Leave empty to disable the audits cleanup.'),
default: nil,
full_name: N_('Saved audits interval'))
setting('host_details_ui',
type: :boolean,
description: N_("Foreman will load the new UI for host details"),
default: false,
full_name: N_('New host details UI'))
end
end
2 changes: 1 addition & 1 deletion app/views/config_reports/index.html.erb
Expand Up @@ -6,7 +6,7 @@
},
{
caption: @host.name,
url: (host_path(@host) if authorized_for(hash_for_host_path(@host)))
url: (current_host_details_path(@host) if authorized_for(hash_for_host_path(@host)))
},
{
caption: _('Reports'),
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Expand Up @@ -545,7 +545,7 @@

match 'host_statuses' => 'react#index', :via => :get
constraints(id: /[^\/]+/) do
match 'experimental/hosts/:id' => 'react#index', :via => :get, :as => :host_details_page
match 'new/hosts/:id' => 'react#index', :via => :get, :as => :host_details_page
end
get 'links/:type(/:section)' => 'links#show', :as => 'external_link', :constraints => { section: %r{.*} }
end
47 changes: 47 additions & 0 deletions test/integration/host_js_test.rb
Expand Up @@ -61,6 +61,53 @@ class HostJSTest < IntegrationTestWithJavascript
end
end

describe 'new host details page' do
setup do
Setting[:host_details_ui] = true
end

teardown do
Setting[:host_details_ui] = false
end

test "new show page" do
visit hosts_path
click_link @host.fqdn
find('h5', :text => @host.fqdn)
end

test "create new host and redirect to the new host details page" do
compute_resource = FactoryBot.create(:compute_resource, :libvirt)
os = FactoryBot.create(:ubuntu14_10, :with_associations)
Nic::Managed.any_instance.stubs(:dns_conflict_detected?).returns(true)
visit new_host_path

fill_in 'host_name', :with => 'newhost1'
select2 'Organization 1', :from => 'host_organization_id'
wait_for_ajax
select2 'Location 1', :from => 'host_location_id'
wait_for_ajax
select2 compute_resource.name, :from => 'host_compute_resource_id'

click_link 'Operating System'
wait_for_ajax
select2 os.architectures.first.name, :from => 'host_architecture_id'
select2 os.title, :from => 'host_operatingsystem_id'
uncheck('host_build')
select2 os.media.first.name, :from => 'host_medium_id'
select2 os.ptables.first.name, :from => 'host_ptable_id'
fill_in 'host_root_pass', :with => '12345678'

switch_form_tab_to_interfaces
click_button 'Edit'
select2 domains(:mydomain).name, :from => 'host_interfaces_attributes_0_domain_id'
fill_in 'host_interfaces_attributes_0_ip', :with => '1.1.1.1'
close_interfaces_modal
click_button('Submit')
find('h5', :text => /newhost1.*/) # wait for the new host details page
end
end

describe 'multiple hosts selection' do
setup do
@entries = Setting[:entries_per_page]
Expand Down
4 changes: 3 additions & 1 deletion test/integration/model_js_test.rb
Expand Up @@ -2,7 +2,9 @@

class ModelIntegrationTest < IntegrationTestWithJavascript
test "create new page" do
assert_new_button(models_path, "Create model", new_model_path)
visit models_path
click_on "Create model", class: 'pf-c-button'
assert_current_path new_model_path
fill_in "model_name", :with => "IBM 123"
fill_in "model_hardware_model", :with => "IBMabcde"
fill_in "model_vendor_class", :with => "ABCDE"
Expand Down
2 changes: 1 addition & 1 deletion webpack/assets/javascripts/foreman_tools.js
Expand Up @@ -140,7 +140,7 @@ export { foremanUrl } from './react_app/common/helpers';

export const setTab = () => {
const urlHash = document.location.hash.split('?')[0];
if (urlHash.length) {
if (urlHash.length && !urlHash.startsWith('#/')) {
const tabContent = $(urlHash);
const parentTab = tabContent.closest('.tab-pane');
if (parentTab.exists()) {
Expand Down
@@ -1 +1 @@
export const HOST_DETAILS_PATH = '/experimental/hosts/:id';
export const HOST_DETAILS_PATH = '/new/hosts/:id';
Expand Up @@ -15,8 +15,8 @@ exports[`Routes rendering routes with children renders routes with chidlren 1`]
render={[Function]}
/>
<Route
key="/experimental/hosts/:id"
path="/experimental/hosts/:id"
key="/new/hosts/:id"
path="/new/hosts/:id"
render={[Function]}
/>
<Route
Expand Down

0 comments on commit 2876578

Please sign in to comment.