diff --git a/app/helpers/application_helper/button/refresh_workers.rb b/app/helpers/application_helper/button/refresh_workers.rb new file mode 100644 index 00000000000..b2a4006a9ee --- /dev/null +++ b/app/helpers/application_helper/button/refresh_workers.rb @@ -0,0 +1,7 @@ +class ApplicationHelper::Button::RefreshWorkers < ApplicationHelper::Button::Basic + needs :@record, :@sb + + def visible? + @view_context.x_active_tree == :diagnostics_tree && @sb[:active_tab] == 'diagnostics_workers' + end +end diff --git a/app/helpers/application_helper/toolbar/diagnostics_server_center.rb b/app/helpers/application_helper/toolbar/diagnostics_server_center.rb index 2e43e6cf608..0cc9f318bd3 100644 --- a/app/helpers/application_helper/toolbar/diagnostics_server_center.rb +++ b/app/helpers/application_helper/toolbar/diagnostics_server_center.rb @@ -9,7 +9,8 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T :refresh_workers, 'fa fa-repeat fa-lg', N_('Reload current workers display'), - nil), + nil, + :klass => ApplicationHelper::Button::RefreshWorkers), button( :refresh_audit_log, 'fa fa-repeat fa-lg', diff --git a/app/helpers/application_helper/toolbar_builder.rb b/app/helpers/application_helper/toolbar_builder.rb index 02a95accc84..0cf587b97e8 100644 --- a/app/helpers/application_helper/toolbar_builder.rb +++ b/app/helpers/application_helper/toolbar_builder.rb @@ -434,7 +434,7 @@ def hide_button_ops(id) when "diagnostics_summary" return !["refresh_server_summary", "restart_server"].include?(id) when "diagnostics_workers" - return !["refresh_workers", "restart_workers"].include?(id) + return !%w(restart_workers refresh_workers).include?(id) else return true end @@ -709,8 +709,6 @@ def hide_button?(id) case id when "role_start", "role_suspend", "promote_server", "demote_server" return true - when "log_download", "refresh_logs", "log_collect", "log_reload", "logdepot_edit", "processmanager_restart", "refresh_workers" - return true end when "ServerRole" case id @@ -734,23 +732,6 @@ def hide_button?(id) middleware_datasource_remove middleware_datasource_add).include?(id) && (@record.try(:product) == 'Hawkular' || @record.try(:middleware_server).try(:product) == 'Hawkular') - when "NilClass" - case id - when "log_download" - return true if ["workers", "download_logs"].include?(@lastaction) - when "log_collect" - return true if ["workers", "evm_logs", "audit_logs"].include?(@lastaction) - when "log_reload" - return true if ["workers", "download_logs"].include?(@lastaction) - when "logdepot_edit" - return true if ["workers", "evm_logs", "audit_logs"].include?(@lastaction) - when "processmanager_restart" - return true if ["download_logs", "evm_logs", "audit_logs"].include?(@lastaction) - when "refresh_workers" - return true if ["download_logs", "evm_logs", "audit_logs"].include?(@lastaction) - when "refresh_logs" - return true if ["audit_logs", "evm_logs", "workers"].include?(@lastaction) - end end false # No reason to hide, allow the button to show end diff --git a/spec/helpers/application_helper/buttons/refresh_workers_spec.rb b/spec/helpers/application_helper/buttons/refresh_workers_spec.rb new file mode 100644 index 00000000000..45d1c64affc --- /dev/null +++ b/spec/helpers/application_helper/buttons/refresh_workers_spec.rb @@ -0,0 +1,31 @@ +describe ApplicationHelper::Button::RefreshWorkers do + let(:view_context) { setup_view_context_with_sandbox({}) } + let(:record) { FactoryGirl.create(:miq_server) } + + describe '#visible?' do + context 'when x_active_tree == diagnostics_tree and active_tab != diagnostics_workers' do + it 'will be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'does not matter') + allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) + expect(button.visible?).to be_falsey + end + end + context 'when x_active_tree != diagnostics_tree and active_tab == diagnostics_workers' do + it 'will be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers') + allow(view_context).to receive(:x_active_tree).and_return(:does_not_matter) + expect(button.visible?).to be_falsey + end + end + context 'when x_active_tree == diagnostics_tree and active_tab == diagnostics_workers' do + it 'will not be skipped' do + button = described_class.new(view_context, {}, {'record' => record}, {}) + button.instance_variable_set(:@sb, :active_tab => 'diagnostics_workers') + allow(view_context).to receive(:x_active_tree).and_return(:diagnostics_tree) + expect(button.visible?).to be_truthy + end + end + end +end diff --git a/spec/helpers/application_helper/toolbar_builder_spec.rb b/spec/helpers/application_helper/toolbar_builder_spec.rb index f1e746e8abe..b92e08c3910 100644 --- a/spec/helpers/application_helper/toolbar_builder_spec.rb +++ b/spec/helpers/application_helper/toolbar_builder_spec.rb @@ -736,8 +736,7 @@ def method_missing(sym, *args) stub_user(:features => :all) end - ["role_start", "role_suspend", "promote_server", "demote_server", - "log_download", "refresh_logs", "log_collect", "log_reload", "logdepot_edit", "processmanager_restart", "refresh_workers"].each do |id| + %w(role_start role_suspend promote_server demote_server).each do |id| it "and id = #{id}" do @id = id expect(subject).to be_truthy @@ -783,83 +782,6 @@ def method_missing(sym, *args) end end - context "when with record = nil" do - before do - @record = nil - stub_user(:features => :all) - end - - ["log_download", "log_reload"].each do |id| - context "and id = #{id}" do - before { @id = id } - - it "and @lastaction = workers" do - @lastaction = "workers" - expect(subject).to be_truthy - end - - it "and @lastaction = download_logs" do - @lastaction = "download_logs" - expect(subject).to be_truthy - end - - it "otherwise" do - expect(subject).to be_falsey - end - end - end - - ["log_collect", "logdepot_edit", "refresh_logs"].each do |id| - context "and id = #{id}" do - before { @id = id } - - it "and @lastaction = workers" do - @lastaction = "workers" - expect(subject).to be_truthy - end - - it "and @lastaction = evm_logs" do - @lastaction = "evm_logs" - expect(subject).to be_truthy - end - - it "and @lastaction = audit_logs" do - @lastaction = "audit_logs" - expect(subject).to be_truthy - end - - it "otherwise" do - expect(subject).to be_falsey - end - end - end - - ["processmanager_restart", "refresh_workers"].each do |id| - context "and id = #{id}" do - before { @id = id } - - it "and @lastaction = download_logs" do - @lastaction = "download_logs" - expect(subject).to be_truthy - end - - it "and @lastaction = evm_logs" do - @lastaction = "evm_logs" - expect(subject).to be_truthy - end - - it "and @lastaction = audit_logs" do - @lastaction = "audit_logs" - expect(subject).to be_truthy - end - - it "otherwise" do - expect(subject).to be_falsey - end - end - end - end - context "NilClass" do before do @record = nil