Skip to content

Commit

Permalink
expose provider disable for containers providers
Browse files Browse the repository at this point in the history
  • Loading branch information
Ari Zellner committed Jul 10, 2017
1 parent d95587a commit 94a5efe
Show file tree
Hide file tree
Showing 3 changed files with 126 additions and 1 deletion.
106 changes: 106 additions & 0 deletions app/controllers/ems_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,8 @@ def button
redirect_to :action => "new" if params[:pressed] == "new"
deleteemss if params[:pressed] == "#{table_name}_delete"
refreshemss if params[:pressed] == "#{table_name}_refresh"
pauseemss if params[:pressed] == "#{table_name}_pause"
resumeemss if params[:pressed] == "#{table_name}_resume"
# scanemss if params[:pressed] == "scan"
tag(model) if params[:pressed] == "#{table_name}_tag"

Expand Down Expand Up @@ -548,6 +550,46 @@ def process_emss(emss, task)
:product => I18n.t('product.name'),
:model => ui_lookup(:table => table_name),
:models => ui_lookup(:tables => table_name)}) if @flash_array.nil?
elsif task == "pause_ems"
model.where(:id => emss).order("lower(name)").each do |ems|
id = ems.id
ems_name = ems.name
audit = {:event => "ems_record_pause_initiated",
:message => _("[%{name}] Record pause initiated") % {:name => ems_name},
:target_id => id,
:target_class => model.to_s,
:userid => session[:userid]}
AuditEvent.success(audit)

ems.disable!
end

add_flash(n_("Pause initiated for %{count} %{model} from the %{product} Database",
"Pause initiated for %{count} %{models} from the %{product} Database", emss.length) %
{:count => emss.length,
:product => I18n.t('product.name'),
:model => ui_lookup(:table => table_name),
:models => ui_lookup(:tables => table_name)}) if @flash_array.nil?
elsif task == "resume_ems"
model.where(:id => emss).order("lower(name)").each do |ems|
id = ems.id
ems_name = ems.name
audit = {:event => "ems_record_pause_initiated",
:message => _("[%{name}] Record resume initiated") % {:name => ems_name},
:target_id => id,
:target_class => model.to_s,
:userid => session[:userid]}
AuditEvent.success(audit)

ems.enable!
end

add_flash(n_("Resume initiated for %{count} %{model} from the %{product} Database",
"Resume initiated for %{count} %{models} from the %{product} Database", emss.length) %
{:count => emss.length,
:product => I18n.t('product.name'),
:model => ui_lookup(:table => table_name),
:models => ui_lookup(:tables => table_name)}) if @flash_array.nil?
else
model.where(:id => emss).order("lower(name)").each do |ems|
id = ems.id
Expand Down Expand Up @@ -678,6 +720,70 @@ def refreshemss
end
end

def call_ems_pause(emss)
process_emss(emss, "pause_ems") unless emss.empty?
return if @flash_array.present?

add_flash(n_("Disable initiated for %{count} %{model} from the %{product} Database",
"Disable initiated for %{count} %{models} from the %{product} Database", emss.length) %
{:count => emss.length,
:product => I18n.t('product.name'),
:model => ui_lookup(:table => table_name),
:models => ui_lookup(:tables => table_name)})
end

def call_ems_resume(emss)
process_emss(emss, "resume_ems") unless emss.empty?
return if @flash_array.present?

add_flash(n_("Resume initiated for %{count} %{model} from the %{product} Database",
"Resume initiated for %{count} %{models} from the %{product} Database", emss.length) %
{:count => emss.length,
:product => I18n.t('product.name'),
:model => ui_lookup(:table => table_name),
:models => ui_lookup(:tables => table_name)})
end

def pauseemss
assert_privileges(params[:pressed])
if @lastaction == "show_list"
emss = find_checked_items
if emss.empty?
add_flash(_("No %{model} were selected for pause") % {:model => ui_lookup(:table => table_name)}, :error)
end
call_ems_pause(emss)
show_list
@refresh_partial = "layouts/gtl"
else
if params[:id].nil? || model.find_by_id(params[:id]).nil?
add_flash(_("%{record} no longer exists") % {:record => ui_lookup(:table => table_name)}, :error)
else
call_ems_pause([params[:id]])
end
params[:display] = @display
end
end

def resumeemss
assert_privileges(params[:pressed])
if @lastaction == "show_list"
emss = find_checked_items
if emss.empty?
add_flash(_("No %{model} were selected for resume") % {:model => ui_lookup(:table => table_name)}, :error)
end
call_ems_resume(emss)
show_list
@refresh_partial = "layouts/gtl"
else
if params[:id].nil? || model.find_by_id(params[:id]).nil?
add_flash(_("%{record} no longer exists") % {:record => ui_lookup(:table => table_name)}, :error)
else
call_ems_resume([params[:id]])
end
params[:display] = @display
end
end

# true, if any of the given fields are either missing from or blank in hash
def any_blank_fields?(hash, fields)
fields = [fields] unless fields.kind_of? Array
Expand Down
19 changes: 19 additions & 0 deletions app/helpers/application_helper/toolbar/ems_container_center.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,25 @@ class ApplicationHelper::Toolbar::EmsContainerCenter < ApplicationHelper::Toolba
'pficon pficon-edit fa-lg',
t = N_('Edit this Containers Provider'),
t,),
button(
:ems_container_resume,
'pficon pficon-trend-up fa-lg',
t = N_('Resume this Containers Provider'),
t,
:confirm => N_("Resume this Containers Provider?"),
:enabled => proc do
!@record.enabled?
end),
button(
:ems_container_pause,
'pficon pficon-trend-down fa-lg',
t = N_('Pause this Containers Provider'),
t,
:confirm => N_("Warning: While this provider is paused no data will be collected from it. " \
"This may cause gaps in inventory, metrics and events!"),
:enabled => proc do
@record.enabled?
end),
button(
:ems_container_delete,
'pficon pficon-delete fa-lg',
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/application_helper/toolbar_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def apply_common_props(button, input)
)

button[:enabled] = input[:enabled]
%i(title text confirm).each do |key|
%i(title text confirm enabled).each do |key|
unless input[key].blank?
button[key] = button.localized(key, input[key])
end
Expand Down

0 comments on commit 94a5efe

Please sign in to comment.