Skip to content

Commit

Permalink
Merge pull request ManageIQ#11265 from cynepco3hahue/fix_rubocop_app/…
Browse files Browse the repository at this point in the history
…presenters/widget_presenter.rb

rubocop issues: widget_presenter.rb
  • Loading branch information
martinpovolny committed Oct 13, 2016
2 parents 1be308c + b1bf7c6 commit 90ffe5a
Showing 1 changed file with 38 additions and 37 deletions.
75 changes: 38 additions & 37 deletions app/presenters/widget_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,11 @@ def initialize(view, controller, widget)
@controller = controller
@widget = widget
@sb = controller.instance_eval { @sb }
@@chart_data ||= []
end

extend Forwardable
delegate [:current_user, :url_for, :initiate_wait_for_task, :session_init,
:session_reset, :get_vmdb_config, :start_url_for_user] => :@controller
def_delegators(:@controller, :current_user, :url_for, :initiate_wait_for_task,
:session_init, :session_reset, :get_vmdb_config, :start_url_for_user)

attr_reader :widget

Expand All @@ -21,36 +20,36 @@ def render_partial
:layout => false, :locals => {:presenter => self}).html_safe
end

def button_fullscreen
if @widget.content_type == "chart"
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-arrows-alt fa-fw') + _(" Full Screen"),
{:action => "report_only",
:type => "hybrid",
:rr_id => @widget.contents_for_user(current_user).miq_report_result_id},
:id => "w_#{@widget.id}_fullscreen",
:title => _("Open the chart and full report in a new window"),
"data-miq_confirm" => _("This will show the chart and the entire report " \
"(all rows) in your browser. Do you want to proceed?"),
:onclick => "return miqClickAndPop(this);")
def widget_html_options(widget_content_type)
if widget_content_type == "chart"
{:title => _("Open the chart and full report in a new window"),
:data_miq_confirm => _("This will show the chart and the entire report " \
"(all rows) in your browser. Do you want to proceed?")}
else
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-arrows-alt fa-fw') + _(" Full Screen"),
{:action => "report_only",
:type => "tabular",
:rr_id => @widget.contents_for_user(current_user).miq_report_result_id},
:id => "w_#{@widget.id}_fullscreen",
:title => _("Open the full report in a new window"),
"data-miq_confirm" => _("This will show the entire report (all rows) in your browser. " \
"Do you want to proceed?"),
:onclick => "return miqClickAndPop(this);")
{:title => _("Open the full report in a new window"),
:data_miq_confirm => _("This will show the entire report (all rows) in your browser. " \
"Do you want to proceed?")}
end
end

def button_fullscreen
options = {:action => "report_only",
:type => @widget.content_type == "chart" ? "hybrid" : "tabular",
:rr_id => @widget.contents_for_user(current_user).miq_report_result_id}
html_options = widget_html_options(@widget.content_type)
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-arrows-alt fa-fw') + _(" Full Screen"), options,
:id => "w_#{@widget.id}_fullscreen",
:title => html_options[:title],
"data-miq_confirm" => html_options[:data_miq_confirm],
:onclick => "return miqClickAndPop(this);")
end

def button_close
unless @sb[:dashboards][@sb[:active_db]][:locked]
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-times fa-fw') + _(" Remove Widget"),
{:controller => "dashboard",
:action => "widget_close",
:widget => @widget.id},
options = {:controller => "dashboard",
:action => "widget_close",
:widget => @widget.id}
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-times fa-fw') + _(" Remove Widget"), options,
:id => "w_#{@widget.id}_close",
:title => _("Remove from Dashboard"),
:remote => true,
Expand All @@ -64,33 +63,35 @@ def button_close
def button_minmax
minimized = @sb[:dashboards][@sb[:active_db]][:minimized].include?(@widget.id)
title = minimized ? _(" Maximize") : _(" Minimize")
options = {:controller => "dashboard",
:action => "widget_toggle_minmax",
:widget => @widget.id}
@view.link_to(@view.content_tag(:span, '',
:class => "fa fa-caret-square-o-#{minimized ? 'down' : 'up'} fa-fw") + title,
{:controller => "dashboard",
:action => "widget_toggle_minmax",
:widget => @widget.id},
options,
:id => "w_#{@widget.id}_minmax",
:title => title,
:remote => true,
'data-method' => :post)
end


def button_pdf
if PdfGenerator.available? && %w(report chart).include?(@widget.content_type)
options = {:action => "widget_to_pdf",
:rr_id => @widget.contents_for_user(current_user).miq_report_result_id}
@view.link_to(@view.content_tag(:span, '', :class => 'fa fa-file-pdf-o fa-fw') + _(" Download PDF"),
{:action => "widget_to_pdf",
:rr_id => @widget.contents_for_user(current_user).miq_report_result_id},
options,
:id => "w_#{@widget.id}_pdf",
:title => _("Download the full report (all rows) as a PDF file"))
end
end

def button_zoom
options = {:controller => "dashboard",
:action => "widget_zoom",
:widget => @widget.id}
@view.link_to(@view.content_tag(:span, '', :class => "fa fa-plus fa-fw") + _(" Zoom in"),
{:controller => "dashboard",
:action => "widget_zoom",
:widget => @widget.id},
options,
:id => "w_#{@widget.id}_zoom",
:title => _("Zoom in on this chart"),
"data-miq_sparkle_on" => true,
Expand All @@ -99,6 +100,6 @@ def button_zoom
end

def self.chart_data
@@chart_data ||= []
@chart_data ||= []
end
end

0 comments on commit 90ffe5a

Please sign in to comment.