Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Diagnostics workers - fix GTL and toolbar #3181

Merged
merged 12 commits into from
Jan 11, 2018
21 changes: 2 additions & 19 deletions app/assets/javascripts/controllers/report_data_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
}

function constructSuffixForTreeUrl(initObject, item) {
var itemId = initObject.showUrl.indexOf('xx-') !== -1 ? '_-' + item.id : '-' + item.id;
var itemId = _.isString(initObject.showUrl) && initObject.showUrl.indexOf('xx-') !== -1 ? '_-' + item.id : '-' + item.id;
if (item.parent_id && item.parent_id[item.parent_id.length - 1] !== '-') {
itemId = item.parent_id + '_' + item.tree_id;
} else if (isAllowedParent(initObject)) {
Expand All @@ -37,22 +37,6 @@
return splitUrl && (splitUrl[1] === ManageIQ.controller || splitUrl[2] === 'policies');
}

function isCurrentOpsWorkerSelected(items, initObject) {
if (initObject.activeTree === 'diagnostics_tree' && ManageIQ.controller === 'ops') {
var lastSlash = initObject.showUrl.indexOf('/', 5) + 1;
var itemId = initObject.showUrl.substring(lastSlash);
if (itemId.indexOf('?id=') === -1) {
initObject.showUrl = initObject.showUrl.substring(0, lastSlash);
if (itemId) {
itemId = itemId[itemId.length - 1] === '/' ? itemId.substring(0, itemId.length - 1) : itemId;
return _.find(items, {id: itemId});
}
}
}

return;
}

/**
* Method for init paging component for GTL.
* Default paging has 5, 10, 20, 50, 100, 1000
Expand Down Expand Up @@ -215,7 +199,7 @@
this.$window.DoNav(item.parent_path + '/' + item.parent_id);
} else if (this.initObject.isExplorer && isCurrentControllerOrPolicies(splitUrl)) {
var itemId = item.id;
if (this.initObject.showUrl.indexOf('?id=') !== -1 ) {
if (_.isString(this.initObject.showUrl) && this.initObject.showUrl.indexOf('?id=') !== -1) {
itemId = constructSuffixForTreeUrl(this.initObject, item);
this.activateNodeSilently(itemId);
}
Expand Down Expand Up @@ -454,7 +438,6 @@
this.initObject.showUrl = splitUrl.join('/');
}
}
this.onItemSelect(isCurrentOpsWorkerSelected(this.gtlData.rows, this.initObject), true);
gtlData.messages && gtlData.messages.forEach(function(oneMessage) {
add_flash(oneMessage.msg, oneMessage.level);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ class ApplicationController
:lastaction,
:display,
:gtl_type,
:supported_features_filter
:supported_features_filter,
:clickable,
) do
def self.from_options(options)
additional_options = new
Expand All @@ -36,6 +37,7 @@ def self.from_options(options)
additional_options.view_suffix = options[:view_suffix]
additional_options.parent_method = options[:parent_method]
additional_options.supported_features_filter = options[:supported_features_filter]
additional_options.clickable = options[:clickable]
additional_options
end

Expand Down
36 changes: 11 additions & 25 deletions app/controllers/ops_controller/diagnostics.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def restart_server
def pm_restart_workers
assert_privileges("restart_workers")
@refresh_partial = "#{@sb[:active_tab]}_tab"
worker = MiqWorker.find_by_id(@sb[:selected_worker_id])
worker = MiqWorker.find(checked_or_params.first)
wtype = worker.normalized_type
case wtype
when "ems_vimbroker"
Expand Down Expand Up @@ -417,23 +417,6 @@ def diagnostics_server_list
update_gtl_div('diagnostics_server_list') if pagination_or_gtl_request?
end

def diagnostics_worker_selected
@explorer = true
@sb[:selected_worker_id] = params[:id]
get_workers

render :update do |page|
page << javascript_prologue
page.replace_html(@sb[:active_tab], :partial => "#{@sb[:active_tab]}_tab")
if center_toolbar_filename.present?
page << "$('#toolbar').show();"
page << javascript_reload_toolbars
else
page << "$('#toolbar').hide();"
end
end
end

private ############################

# Build the Utilization screen for a server
Expand Down Expand Up @@ -543,20 +526,23 @@ def refresh_server_summary
end

def pm_get_workers
@sb[:selected_worker_id] = nil
get_workers
end

def get_workers
@lastaction = "pm_workers_list"
@force_no_grid_xml = true
@no_checkboxes = true
@gtl_type = "list"
@embedded = @pages = false
@showlinks = true
status = ["started", "ready", "working"]
# passing all_pages option to show all records on same page
@view, @pages = get_view(MiqWorker, :named_scope => [[:with_miq_server_id, @sb[:selected_server_id]], [:with_status, status]], :all_pages => true) # Get the records (into a view) and the paginator

view_options = {
:named_scope => [[:with_miq_server_id, @sb[:selected_server_id]],
[:with_status, status]],
# passing all_pages option to show all records on same page
:all_pages => true,
:clickable => false,
}
@view, @pages = get_view(MiqWorker, view_options)

# setting @embedded and @pages to nil, we don't want to show sorting/paging bar on the screen'
@embedded = @pages = nil
end
Expand Down
1 change: 0 additions & 1 deletion app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,6 @@ def db_to_controller(db, action = "show")
controller = "ansible_credential"
when "MiqWorker"
controller = request.parameters[:controller]
action = "diagnostics_worker_selected"
when "OrchestrationStackOutput", "OrchestrationStackParameter", "OrchestrationStackResource",
"ManageIQ::Providers::CloudManager::OrchestrationStack",
"ManageIQ::Providers::AnsibleTower::AutomationManager::Job", "ConfigurationScriptBase"
Expand Down
6 changes: 0 additions & 6 deletions app/helpers/application_helper/button/restart_workers.rb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,11 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
'pficon pficon-restart',
N_('Select a worker to restart'),
N_('Restart selected worker'),
:confirm => N_("Warning: Selected node will be restarted, do you want to continue?"),
:klass => ApplicationHelper::Button::RestartWorkers),
:confirm => N_("Warning: Selected node will be restarted, do you want to continue?"),
:klass => ApplicationHelper::Button::RefreshWorkers,
:send_checked => true,
:enabled => false,
:onwhen => "1"),
]
),
])
Expand Down
14 changes: 13 additions & 1 deletion app/helpers/gtl_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -121,9 +121,21 @@ def render_gtl_javascripts(options)
isExplorer: '#{options[:explorer]}' === 'true' ? true : false,
records: #{!options[:selected_records].nil? ? h(j_str(options[:selected_records].to_json)) : "\'\'"},
hideSelect: #{options[:selected_records].kind_of?(Array)},
showUrl: '#{view_to_url(options[:view], options[:parent]) if options[:view].present? && options[:view].db.present?}'
showUrl: '#{gtl_show_url(options)}'
}
}});
EOJ
end

def gtl_show_url(options)
# FIXME: fetch_path doesn't work on structs in a hash
if options[:report_data_additional_options].present?
# only false, nil is true
return false if options[:report_data_additional_options].clickable == false
end

# TODO: the "what happens on nil" logic should probably live here, not in ReportDataController.prototype.initObjects

view_to_url(options[:view], options[:parent]) if options[:view].present? && options[:view].db.present?
end
end
6 changes: 0 additions & 6 deletions app/views/layouts/gtl/_list.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,6 @@
- table.data.each do |row|
- @id = to_cid(row['id'])
- classes = []
- if view.db == "MiqWorker" && @sb[:selected_worker_id].to_i == row['id'].to_i
- classes.append("selected")
- if %w(MiqEventDefinition MiqTask VmdbDatabaseConnection VmdbDatabaseSetting).include?(view.db) || @embedded
- classes.append("no-hover")
%tr{:class => classes.join(' ')}
Expand Down Expand Up @@ -156,8 +154,6 @@
- click = "miqTreeActivateNode('#{x_active_tree}', '#{x_node}_cr-#{to_cid(row['id'])}');"
- when "MiqDialog"
- click = "miqTreeActivateNode('old_dialogs_tree', '#{TreeBuilder.get_prefix_for_model("MiqDialog")}-#{to_cid(row['id'])}');"
- when "MiqWorker"
- click = remote_function(:url => {:action => 'diagnostics_worker_selected', :id => "#{row['id']}"})
- else
- click = "DoNav('#{url_for_db(view.db)}');"
%td.table-view-pf-select{:title => title, :onclick => click}
Expand Down Expand Up @@ -252,8 +248,6 @@
- click = "miqTreeActivateNode('#{x_active_tree}', '#{x_node}_cr-#{to_cid(row['id'])}');"
- when "MiqDialog"
- click = "miqTreeActivateNode('old_dialogs_tree', '#{TreeBuilder.get_prefix_for_model("MiqDialog")}-#{to_cid(row['id'])}');"
- when "MiqWorker"
- click = remote_function(:url => {:action => 'diagnostics_worker_selected', :id => "#{row['id']}"})
- else
- if view.db == "Action"
- click = "DoNav('#{url_for_db("miq_action")}');"
Expand Down
1 change: 0 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2678,7 +2678,6 @@
db_list
diagnostics_server_list
diagnostics_tree_select
diagnostics_worker_selected
edit_rhn
explorer
fetch_build
Expand Down
17 changes: 0 additions & 17 deletions spec/helpers/application_helper/buttons/restart_workers_spec.rb

This file was deleted.

1 change: 0 additions & 1 deletion spec/routing/ops_routing_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@
db_list
diagnostics_server_list
diagnostics_tree_select
diagnostics_worker_selected
edit_rhn
explorer
fetch_build
Expand Down