Skip to content

Commit

Permalink
Merge pull request #417 from vecerek/toolbar_refactoring__ops
Browse files Browse the repository at this point in the history
Toolbar refactoring: Ops
  • Loading branch information
mzazrivec authored Feb 24, 2017
2 parents e72650b + 0cd906f commit ef884b3
Show file tree
Hide file tree
Showing 33 changed files with 257 additions and 157 deletions.
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/db_refresh.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DbRefresh < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tab?(%w(db_connections db_details db_indexes db_settings))
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DiagnosticsAuditLogs < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_audit_log')
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/diagnostics_evm_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DiagnosticsEvmLogs < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_evm_log')
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/diagnostics_logs.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DiagnosticsLogs < ApplicationHelper::Button::CollectLogs
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_collect_logs')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DiagnosticsProductionLogs < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_production_log')
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/diagnostics_summary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::DiagnosticsSummary < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_summary')
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module ApplicationHelper::Button::Mixins::ActiveContextMixin
def active_tree?(tree)
if tree.kind_of?(Array)
tree.include?(@view_context.x_active_tree)
else
tree == @view_context.x_active_tree
end
end

def active_tab?(tab)
if tab.kind_of?(Array)
tab.include?(@view_context.active_tab)
else
tab == @view_context.active_tab
end
end
end
4 changes: 2 additions & 2 deletions app/helpers/application_helper/button/refresh_workers.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class ApplicationHelper::Button::RefreshWorkers < ApplicationHelper::Button::Basic
needs :@record, :@sb
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
@view_context.x_active_tree == :diagnostics_tree && @sb[:active_tab] == 'diagnostics_workers'
active_tree?(:diagnostics_tree) && active_tab?('diagnostics_workers')
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/reload_server_tree.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::ReloadServerTree < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:diagnostics_tree) && active_tab?(%w(diagnostics_roles_servers diagnostics_servers_roles))
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/schedule_run_now.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::ScheduleRunNow < ApplicationHelper::Button::Basic
include ApplicationHelper::Button::Mixins::ActiveContextMixin

def visible?
active_tree?(:settings_tree)
end
end
6 changes: 3 additions & 3 deletions app/helpers/application_helper/button/tenant_add.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
class ApplicationHelper::Button::TenantAdd < ApplicationHelper::Button::GenericFeatureButton
needs :@record
delegate :role_allows?, :rbac_common_feature_for_buttons, :to => :@view_context
delegate :rbac_common_feature_for_buttons, :to => :@view_context

def role_allows_feature?
role_allows?(:feature => rbac_common_feature_for_buttons(self[:child_id]))
role_allows?(:feature => rbac_common_feature_for_buttons(@feature))
end

def visible?
true
!@record.project?
end
end
7 changes: 7 additions & 0 deletions app/helpers/application_helper/button/zone_log_depot_edit.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ApplicationHelper::Button::ZoneLogDepotEdit < ApplicationHelper::Button::DiagnosticsLogs
def visible?
return false if active_tree?(:diagnostics_tree) &&
(active_tab?('diagnostics_roles_servers') || active_tab?('diagnostics_servers_roles'))
super
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ApplicationHelper::Toolbar::DiagnosticsRegionCenter < ApplicationHelper::T
:reload_server_tree,
'fa fa-repeat fa-lg',
N_('Reload Current Display'),
nil),
nil,
:klass => ApplicationHelper::Button::ReloadServerTree),
])
button_group('ldap_domain_vmdb', [
select(
Expand Down
34 changes: 22 additions & 12 deletions app/helpers/application_helper/toolbar/diagnostics_server_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
:refresh_server_summary,
'fa fa-repeat fa-lg',
N_('Reload Current Display'),
nil),
nil,
:klass => ApplicationHelper::Button::DiagnosticsSummary),
button(
:refresh_workers,
'fa fa-repeat fa-lg',
Expand All @@ -15,39 +16,45 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
:refresh_audit_log,
'fa fa-repeat fa-lg',
N_('Reload the Audit Log Display'),
nil),
nil,
:klass => ApplicationHelper::Button::DiagnosticsAuditLogs),
button(
:fetch_audit_log,
'fa fa-download fa-lg',
N_('Download the Entire Audit Log File'),
nil,
:url => "/fetch_audit_log"),
:url => "/fetch_audit_log",
:klass => ApplicationHelper::Button::DiagnosticsAuditLogs),
button(
:refresh_log,
'fa fa-repeat fa-lg',
N_('Reload the EVM Log Display'),
nil),
nil,
:klass => ApplicationHelper::Button::DiagnosticsEvmLogs),
button(
:fetch_log,
'fa fa-download fa-lg',
N_('Download the Entire EVM Log File'),
nil,
:url => "/fetch_log"),
:url => "/fetch_log",
:klass => ApplicationHelper::Button::DiagnosticsEvmLogs),
button(
:refresh_production_log,
'fa fa-repeat fa-lg',
proc do
_('Reload the %{log_type} Log Display') % {:log_type => _(@sb[:rails_log])}
end,
nil),
nil,
:klass => ApplicationHelper::Button::DiagnosticsProductionLogs),
button(
:fetch_production_log,
'fa fa-download fa-lg',
proc do
_('Download the Entire %{log_type} Log File') % {:log_type => _(@sb[:rails_log])}
end,
nil,
:url => "/fetch_production_log"),
:url => "/fetch_production_log",
:klass => ApplicationHelper::Button::DiagnosticsProductionLogs),
])
button_group('ldap_domain_vmdb', [
select(
Expand All @@ -61,22 +68,23 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
'fa fa-filter fa-lg',
N_('Collect the current logs from the selected Server'),
N_('Collect current logs'),
:klass => ApplicationHelper::Button::CollectLogs
:klass => ApplicationHelper::Button::DiagnosticsLogs
),
button(
:collect_logs,
'fa fa-filter fa-lg',
N_('Collect all logs from the selected Server'),
N_('Collect all logs'),
:klass => ApplicationHelper::Button::CollectLogs
:klass => ApplicationHelper::Button::DiagnosticsLogs
),
]
),
button(
:log_depot_edit,
'pficon pficon-edit fa-lg',
N_('Edit the Log Depot settings for the selected Server'),
N_('Edit')),
N_('Edit'),
:klass => ApplicationHelper::Button::DiagnosticsLogs),
select(
:restart_vmdb_choice,
'fa fa-cog fa-lg',
Expand All @@ -88,13 +96,15 @@ class ApplicationHelper::Toolbar::DiagnosticsServerCenter < ApplicationHelper::T
'pficon pficon-restart',
t = N_('Restart server'),
t,
:confirm => N_("Warning: Server will be restarted, do you want to continue?")),
:confirm => N_("Warning: Server will be restarted, do you want to continue?"),
:klass => ApplicationHelper::Button::DiagnosticsSummary),
button(
:restart_workers,
'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?")),
:confirm => N_("Warning: Selected node will be restarted, do you want to continue?"),
:klass => ApplicationHelper::Button::RefreshWorkers),
]
),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ class ApplicationHelper::Toolbar::DiagnosticsZoneCenter < ApplicationHelper::Too
:reload_server_tree,
'fa fa-repeat fa-lg',
N_('Reload Current Display'),
nil),
nil,
:klass => ApplicationHelper::Button::ReloadServerTree),
])
button_group('ldap_domain_vmdb', [
select(
Expand Down Expand Up @@ -109,21 +110,22 @@ class ApplicationHelper::Toolbar::DiagnosticsZoneCenter < ApplicationHelper::Too
'fa fa-filter fa-lg',
N_('Collect the current logs from the selected Zone'),
N_('Collect current logs'),
:klass => ApplicationHelper::Button::CollectLogs
:klass => ApplicationHelper::Button::ZoneLogDepotEdit
),
button(
:zone_collect_logs,
'fa fa-filter fa-lg',
N_('Collect all logs from the selected Zone'),
N_('Collect all logs'),
:klass => ApplicationHelper::Button::CollectLogs
:klass => ApplicationHelper::Button::ZoneLogDepotEdit
),
]
),
button(
:zone_log_depot_edit,
'pficon pficon-edit fa-lg',
N_('Edit the Log Depot settings for the selected Zone'),
N_('Edit')),
N_('Edit'),
:klass => ApplicationHelper::Button::ZoneLogDepotEdit),
])
end
5 changes: 3 additions & 2 deletions app/helpers/application_helper/toolbar/miq_schedule_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,10 @@ class ApplicationHelper::Toolbar::MiqScheduleCenter < ApplicationHelper::Toolbar
separator,
button(
:schedule_run_now,
'collect',
'fa fa-play-circle-o fa-lg',
t = N_('Queue up this Schedule to run now'),
t),
t,
:klass => ApplicationHelper::Button::ScheduleRunNow),
]
),
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ class ApplicationHelper::Toolbar::MiqSchedulesCenter < ApplicationHelper::Toolba
t,
:url_parms => "main_div",
:enabled => false,
:onwhen => "1+"),
:onwhen => "1+",
:klass => ApplicationHelper::Button::ScheduleRunNow),
]
),
])
Expand Down
3 changes: 2 additions & 1 deletion app/helpers/application_helper/toolbar/vmdb_table_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ApplicationHelper::Toolbar::VmdbTableCenter < ApplicationHelper::Toolbar::
:db_refresh,
'fa fa-repeat fa-lg',
N_('Reload Current Display'),
nil),
nil,
:klass => ApplicationHelper::Button::DbRefresh),
])
end
3 changes: 2 additions & 1 deletion app/helpers/application_helper/toolbar/vmdb_tables_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class ApplicationHelper::Toolbar::VmdbTablesCenter < ApplicationHelper::Toolbar:
:db_refresh,
'fa fa-repeat fa-lg',
N_('Reload Current Display'),
nil),
nil,
:klass => ApplicationHelper::Button::DbRefresh),
])
end
50 changes: 2 additions & 48 deletions app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -364,48 +364,6 @@ def get_image(img, b_name)
img
end

def hide_button_ops(id)
case x_active_tree
when :settings_tree
return ["schedule_run_now"].include?(id)
when :diagnostics_tree
case @sb[:active_tab]
when "diagnostics_audit_log"
return !["fetch_audit_log", "refresh_audit_log"].include?(id)
when "diagnostics_collect_logs"
return !%w(collect_current_logs collect_logs log_depot_edit
zone_collect_current_logs zone_collect_logs
zone_log_depot_edit).include?(id)
when "diagnostics_evm_log"
return !["fetch_log", "refresh_log"].include?(id)
when "diagnostics_production_log"
return !["fetch_production_log", "refresh_production_log"].include?(id)
when "diagnostics_roles_servers", "diagnostics_servers_roles"
case id
when "reload_server_tree"
return false
when "zone_collect_current_logs", "zone_collect_logs", "zone_log_depot_edit"
return true
end
return false
when "diagnostics_summary"
return !["refresh_server_summary", "restart_server"].include?(id)
when "diagnostics_workers"
return !%w(restart_workers refresh_workers).include?(id)
else
return true
end
when :rbac_tree
return true unless role_allows?(:feature => rbac_common_feature_for_buttons(id))
return true if %w(rbac_project_add rbac_tenant_add).include?(id) && @record.project?
return false
when :vmdb_tree
return !["db_connections", "db_details", "db_indexes", "db_settings"].include?(@sb[:active_tab])
else
return true
end
end

# Determine if a button should be hidden
def hide_button?(id)
# need to hide add buttons when on sub-list view screen of a CI.
Expand All @@ -424,19 +382,15 @@ def hide_button?(id)
return false if id == "miq_request_reload" && # Show the request reload button
(@lastaction == "show_list" || @showtype == "miq_provisions")

if @layout == "ops"
res = hide_button_ops(id)
return res
end

return false if id.starts_with?("miq_capacity_") && @sb[:active_tab] == "report"

# don't check for feature RBAC if id is miq_request_approve/deny
unless %w(miq_policy catalogs).include?(@layout)
return true if !role_allows?(:feature => id) && !["miq_request_approve", "miq_request_deny"].include?(id) &&
id !~ /^history_\d*/ &&
!id.starts_with?("dialog_") && !id.starts_with?("miq_task_") &&
!(id == "show_summary" && !@explorer) && id != "summary_reload"
!(id == "show_summary" && !@explorer) && id != "summary_reload" &&
@layout != "ops"
end

# Check buttons with other restriction logic
Expand Down
18 changes: 18 additions & 0 deletions spec/helpers/application_helper/buttons/db_refresh_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
describe ApplicationHelper::Button::DbRefresh do
let(:view_context) { setup_view_context_with_sandbox(:active_tab => tab) }
let(:button) { described_class.new(view_context, {}, {}, {}) }

describe '#visible?' do
subject { button.visible? }
%w(db_details db_indexes db_settings db_connections).each do |tree|
context "when active_tree == #{tree}" do
let(:tab) { tree }
it { expect(subject).to be_truthy }
end
end
context 'when !active_tree.in?(%w(db_details db_indexes db_settings db_connections))' do
let(:tab) { 'something_else' }
it { expect(subject).to be_falsey }
end
end
end
Loading

0 comments on commit ef884b3

Please sign in to comment.