Skip to content

Commit

Permalink
Merge pull request #11879 from vecerek/toolbar_refactoring__miq_serve…
Browse files Browse the repository at this point in the history
…r_and_region

Toolbar refactoring  miq server and region
  • Loading branch information
martinpovolny authored Nov 2, 2016
2 parents 81d9f00 + 2797d55 commit af903bf
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 100 deletions.
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/refresh_workers.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 1 addition & 20 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
31 changes: 31 additions & 0 deletions spec/helpers/application_helper/buttons/refresh_workers_spec.rb
Original file line number Diff line number Diff line change
@@ -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
80 changes: 1 addition & 79 deletions spec/helpers/application_helper/toolbar_builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit af903bf

Please sign in to comment.