Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Dropdown menu to component #2009

Merged
merged 5 commits into from Oct 19, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/assets/javascripts/components/dropdown-menu.js
@@ -0,0 +1,16 @@
ManageIQ.angular.app.component('dropdownMenu', {
bindings: {
id: '<',
buttonsData: '@',
},
controllerAs: 'vm',
controller: function() {
var vm = this;

this.$onInit = function() {
vm.dropdown_id = 'btn_' + vm.id;
vm.buttons = JSON.parse(vm.buttonsData);
};
},
templateUrl: "/static/dropdown-menu.html.haml",
});
10 changes: 10 additions & 0 deletions app/assets/javascripts/miq_ujs_bindings.js
Expand Up @@ -40,10 +40,20 @@ $(document).ready(function () {

// Bind the MIQ spinning Q to configured links
$(document).on('ajax:beforeSend', 'a[data-miq_sparkle_on]', function () {
// Return only if data-miq_sparkle_on is set to false
if ($(this).data('miq_sparkle_on') === false) {
return;
}

// Call to miqSparkleOn since miqSparkle(true) checks XHR count, which is 0 before send
miqSparkleOn();
});
$(document).on('ajax:complete', 'a[data-miq_sparkle_off]', function () {
// Return only if data-miq_sparkle_off is set to false
if ($(this).data('miq_sparkle_off') === false) {
return;
}

miqSparkle(false);
});

Expand Down
131 changes: 60 additions & 71 deletions app/presenters/widget_presenter.rb
Expand Up @@ -20,84 +20,73 @@ 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,
:sparkleOn => 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,
:sparkleOn => 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-data" => presenter.widget_buttons}
%h2.card-pf-title.sortable-handle{:style => "cursor:move"}
= h(presenter.widget.title)

Expand Down
19 changes: 19 additions & 0 deletions app/views/static/dropdown-menu.html.haml
@@ -0,0 +1,19 @@
.dropdown.pull-right.dropdown-kebab-pf
%button.btn.btn-link.dropdown-toggle{'aria-haspopup' => "true",
'data-toggle' => "dropdown",
'id' => "{{vm.dropdown_id}}",
'type' => "button",
'aria-expanded' => "false"}
%span.fa.fa-ellipsis-v

%ul.dropdown-menu.dropdown-menu-right{'aria-labelledby' => "{{vm.dropdown_id}}"}
%li{'ng-repeat' => "button in vm.buttons"}
%a{'id' => "{{button.id}}",
'title' => "{{button.title}}",
'data-method' => "{{button.dataMethod}}",
'data-remote' => "{{button.dataRemote}}",
'data-confirm' => "{{button.confirm}}",
'href' => "{{button.href}}",
'data-miq_sparkle_on' => "{{button.sparkleOn ? 'true' : 'false'}}"}
%span{'ng-class' => "button.fonticon"}
{{button.name}}