From 30e31f768a2657ec66383a86120786784d5463e0 Mon Sep 17 00:00:00 2001 From: lpichler Date: Mon, 14 Jan 2019 22:03:54 +0100 Subject: [PATCH] Display widget's title in full screen of widget result there is used title from report for report result --- app/controllers/application_controller.rb | 1 + app/views/layouts/_show_report.html.haml | 2 +- app/views/layouts/report_only.html.haml | 2 +- .../application_controller_spec.rb | 43 +++++++++++++++++++ 4 files changed, 46 insertions(+), 2 deletions(-) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 37920184b1dd..35dbf95033e1 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -491,6 +491,7 @@ def report_only session[:rpt_task_id] = nil # Clear out report task id, using a saved report @report = rr.report + @report_title = rr.full_screen_title @html = report_build_html_table(rr.report_results, rr.html_rows.join) @ght_type = params[:type] || (@report.graph.blank? ? 'tabular' : 'hybrid') @render_chart = (@ght_type == 'hybrid') diff --git a/app/views/layouts/_show_report.html.haml b/app/views/layouts/_show_report.html.haml index 249829aa3399..9ffd5ef0bffb 100644 --- a/app/views/layouts/_show_report.html.haml +++ b/app/views/layouts/_show_report.html.haml @@ -2,6 +2,6 @@ %h3= _("Choose a Report to view.") - else %fieldset - %h3= @report.title + %h3= @report_title = render :partial => "layouts/flash_msg" = render :partial => "shared/report_chart_and_html", :locals => {:html => @html, :chart => @render_chart, :report => @report} diff --git a/app/views/layouts/report_only.html.haml b/app/views/layouts/report_only.html.haml index 88073db561c7..3d0f5f5c9d7f 100644 --- a/app/views/layouts/report_only.html.haml +++ b/app/views/layouts/report_only.html.haml @@ -2,7 +2,7 @@ %html.layout-pf.layout-pf-fixed.transitions{:lang => I18n.locale.to_s.sub('-', '_')} %head %title - = "%{product}: %{title}" % {:product => Vmdb::Appliance.PRODUCT_NAME, :title => @report.title} + = "%{product}: %{title}" % {:product => Vmdb::Appliance.PRODUCT_NAME, :title => @report_title} = favicon_link_tag = stylesheet_link_tag 'application' = stylesheet_link_tag '/custom.css' diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb index bef047a11955..ab10434f227c 100644 --- a/spec/controllers/application_controller_spec.rb +++ b/spec/controllers/application_controller_spec.rb @@ -1,6 +1,49 @@ require 'ostruct' describe ApplicationController do + describe "#report_only" do + let(:group) { FactoryBot.create(:miq_group, :miq_user_role => FactoryBot.create(:miq_user_role)) } + let(:user) { FactoryBot.create(:user, :miq_groups => [group]) } + let(:report_title) { "VMs using thin provisioned disks" } + let(:report) { FactoryBot.create(:miq_report, :title => report_title) } + let(:report_result_for_report) { FactoryBot.create(:miq_report_result, :miq_group => group, :miq_report_id => report.id, :report => report) } + let(:widget_title) { "Widget: VMs using thin provisioned disks" } + let(:widget) { FactoryBot.create(:miq_widget, :widget => widget_title) } + let(:widget_content) { FactoryBot.create(:miq_widget_content, :miq_widget => widget) } + let(:report_for_widget) { FactoryBot.create(:miq_report, :title => widget_title) } + let(:report_result_for_widget) { FactoryBot.create(:miq_report_result, :miq_group => group, :miq_report => report_for_widget, :report => report_for_widget, :report_source => MiqWidget::WIDGET_REPORT_SOURCE) } + + before do + login_as user + end + + it "uses correct variables for rendering result of report" do + controller.instance_variable_set(:@sb, :pages => { :rr_id => report_result_for_report.id }) + controller.instance_variable_set(:@_params, :rr_id => report_result_for_report.id) + + expect(controller).to receive(:render).with('shared/show_report', :layout => 'report_only') + controller.send(:report_only) + + expect(controller.instance_variable_get(:@report_title)).to eq(report_title) + expect(controller.instance_variable_get(:@report)).to eq(report) + expect(controller.instance_variable_get(:@ght_type)).to eq('tabular') + expect(controller.instance_variable_get(:@render_chart)).to be_falsey + end + + it "uses correct variables for rendering result of report" do + controller.instance_variable_set(:@sb, :pages => { :rr_id => report_result_for_widget.id }) + controller.instance_variable_set(:@_params, :rr_id => report_result_for_widget.id) + + expect(controller).to receive(:render).with('shared/show_report', :layout => 'report_only') + controller.send(:report_only) + + expect(controller.instance_variable_get(:@report_title)).to eq(widget_title) + expect(controller.instance_variable_get(:@report)).to eq(report_for_widget) + expect(controller.instance_variable_get(:@ght_type)).to eq('tabular') + expect(controller.instance_variable_get(:@render_chart)).to be_falsey + end + end + describe "#find_record_with_rbac" do before do EvmSpecHelper.create_guid_miq_server_zone