Skip to content

Commit

Permalink
Buttons to components
Browse files Browse the repository at this point in the history
  • Loading branch information
ZitaNemeckova committed Sep 29, 2017
1 parent 65c1301 commit b204549
Show file tree
Hide file tree
Showing 3 changed files with 90 additions and 89 deletions.
31 changes: 31 additions & 0 deletions app/assets/javascripts/components/dropdown-menu.js
@@ -0,0 +1,31 @@
ManageIQ.angular.app.component('dropdownMenu', {
bindings: {
id: '<',
buttons: '@',
},
controllerAs: 'vm',
controller: function() {
var vm = this;

this.$onInit = function() {
vm.dropdown_id = 'btn_' + vm.id;
vm.buttons = JSON.parse(vm.buttons);
};
},
template: [
'<div class="dropdown pull-right dropdown-kebab-pf">' +
' <button aria-haspopup="true" class="btn btn-link dropdown-toggle" data-toggle="dropdown" id="{{vm.dropdown_id}}" type="button" aria-expanded="false">' +
' <span class="fa fa-ellipsis-v">' +
' </span>' +
' </button>' +
' <ul aria-labelledby="{{vm.dropdown_id}}" class="dropdown-menu dropdown-menu-right">' +
' <li ng-repeat="button in vm.buttons">' +
' <a id="{{button.id}}" title="{{button.title}}" data-method="{{button.dataMethod}}" data-remote="{{button.dataRemote}}" confirm="{{button.confirm}}" href="{{button.href}}" data-miq_spark_on="{{button.sparkleOn}}">' +
' <span ng-class="{{button.fonticon}}"></span>' +
'{{button.name}}' +
' </a>' +
' </li>' +
' </ul>' +
'</div>',
].join("\n"),
});
129 changes: 58 additions & 71 deletions app/presenters/widget_presenter.rb
Expand Up @@ -20,84 +20,71 @@ def render_partial
:layout => false, :locals => {:presenter => self}).html_safe
end

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
{: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?")}
def widget_buttons
buttons = []
if role_allows?(:feature => "dashboard_add")
unless @sb[:dashboards][@sb[:active_db]][:locked]
buttons.push(:id => "w_#{@widget.id}_close",
:title => _("Remove from Dashboard"),
:name => _("Remove Widget"),
:confirm => _("Are you sure you want to remove '%{title}'" \
"from the Dashboard?") % {:title => @widget.title},
:dataRemote => true,
:href =>'/dashboard/widget_close?widget=' + @widget.id.to_s,
:fonticon => 'fa fa-times fa-fw',
:dataMethod => 'post')
end
minimized = @sb[:dashboards][@sb[:active_db]][:minimized].include?(@widget.id)
title = minimized ? _("Maximize") : _("Minimize")
buttons.push(:id => "w_#{@widget.id}_minmax",
:title => title,
:name => title,
:confirm => false,
:dataRemote => true,
:href =>'/dashboard/widget_toggle_minmax?widget=' + @widget.id.to_s,
:fonticon => "fa fa-caret-square-o-#{minimized ? 'down' : 'up'} fa-fw",
:dataMethod => 'post')
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]
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,
'data-method' => :post,
:confirm => _("Are you sure you want to remove '%{title}'" \
"from the Dashboard?") % {:title => @widget.title},
'data-miq_sparkle_on' => true)
if @widget.contents_for_user(current_user).present? && %w(report chart).include?(@widget.content_type)
title = if @widget.content_type == "chart"
_("Open the chart and full report in a new window")
else
_("Open the full report in a new window")
end
confirm = if @widget.content_type == "chart"
_("This will show the chart and the entire report (all rows) in your browser. Do you want to proceed?")
else
_("This will show the entire report (all rows) in your browser. Do you want to proceed?")
end
buttons.push(:id => "w_#{@widget.id}_fullscreen",
:title => title,
:name => _("Full Screen"),
:confirm => confirm,
:href =>"/dashboard/report_only?rr_id=#{@widget.id}&type=#{@widget.content_type == "chart" ? 'hybrid' : 'tabular'}",
:fonticon => 'fa fa-arrows-alt fa-fw',
:clickAction => "return miqClickAndPop(this);")
if PdfGenerator.available?
buttons.push(:id => "w_#{@widget.id}_pdf",
:title => _("Download the full report (all rows) as a PDF file"),
:name => _("Download PDF"),
:href =>'/dashboard/widget_to_pdf?rr_id=' + @widget.id.to_s,
:fonticon => 'fa fa-file-pdf-o fa-fw')
end
end
end

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,
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"),
options,
:id => "w_#{@widget.id}_pdf",
:title => _("Download the full report (all rows) as a PDF file"))
if @widget.content_type == 'chart'
buttons.push(:id => "w_#{@widget.id}_zoom",
:title => _("Zoom in on this chart"),
:name => _("Zoom in"),
:href =>'/dashboard/widget_zoom?widget=' + @widget.id.to_s,
:fonticon => 'fa fa-plus fa-fw',
:dataRemote => true,
:dataMethod => 'post')
end
buttons.to_json
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"),
options,
:id => "w_#{@widget.id}_zoom",
:title => _("Zoom in on this chart"),
"data-miq_sparkle_on" => true,
:remote => true,
'data-method' => :post)
end

def self.chart_data
@chart_data ||= []
Expand Down
19 changes: 1 addition & 18 deletions app/views/dashboard/_widget.html.haml
Expand Up @@ -5,24 +5,7 @@
.card-pf.card-pf-view
.card-pf-body
.card-pf-heading-kebab
.dropdown.pull-right.dropdown-kebab-pf
%button.btn.btn-link.dropdown-toggle{:type => "button", :id => button_id, "data-toggle" => "dropdown", "aria-haspopup" => "true"}
%span.fa.fa-ellipsis-v
%ul.dropdown-menu.dropdown-menu-right{"aria-labelledby" => button_id}
- if role_allows?(:feature => "dashboard_add")
%li
= presenter.button_close
%li
= presenter.button_minmax
- if presenter.widget.contents_for_user(current_user).present?
- if %w(report chart).include?(presenter.widget.content_type)
%li
= presenter.button_fullscreen
%li
= presenter.button_pdf
- if %w(chart).include?(presenter.widget.content_type)
%li
= presenter.button_zoom
%dropdown-menu{:id => button_id, :buttons => presenter.widget_buttons}
%h2.card-pf-title.sortable-handle{:style => "cursor:move"}
= h(presenter.widget.title)

Expand Down

0 comments on commit b204549

Please sign in to comment.