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

Display info about unavailable fields while adding/editing report #5418

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,24 @@ def miq_report_add_edit
replace_right_cell
end

# Get string with unavailable fields while adding/editing report
def unavailable_fields_for_model(model)
case model
when 'ChargebackVm'
_('* Caution: CPU Cores Allocated Metric, CPU Cores Used Metric are not supported for Chargeback for Vms.')
when 'ChargebackContainerImage'
_('* Caution: CPU Allocated Metric, CPU Used Metric, Disk I/O Used Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric are not supported for Chargeback for Images.')
when 'ChargebackContainerProject'
_('* Caution: CPU Allocated Metric, CPU Used Metric, CPU Cores Allocated Metric, Disk I/O Used Metric, Memory Allocated Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric are not supported for Chargeback for Projects.')
end
end

# AJAX driven routine to check for changes in ANY field on the form
def form_field_changed
return unless load_edit("report_edit__#{params[:id]}", "replace_cell__explorer")
get_form_vars
build_edit_screen
@unavailable_fields = unavailable_fields_for_model(@edit[:new][:model])
@changed = (@edit[:new] != @edit[:current])
render :update do |page|
page << javascript_prologue
Expand Down
6 changes: 6 additions & 0 deletions app/views/report/_form_columns.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@
= render :partial => "column_lists"
%strong
= _('* Caution: Changing these fields will clear all selected values below them!')
- if @unavailable_fields
%br
%p{:style => "max-width: 850px;"}
%strong
= @unavailable_fields

%hr
%h3
= _('Report Creation Timeout')
Expand Down
46 changes: 42 additions & 4 deletions spec/controllers/miq_report_controller/reports/editor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
end
end

context "::Reports::Editor" do
context "#set_form_vars" do
describe "::Reports::Editor" do
describe "#set_form_vars" do
let(:user) { stub_user(:features => :all) }

let(:chargeback_report) do
Expand Down Expand Up @@ -109,14 +109,15 @@

describe '#reportable_models' do
subject { controller.send(:reportable_models) }

it 'does not contain duplicate items' do
duplicates = subject.group_by(&:first).select { |_, v| v.size > 1 }.map(&:first)
expect(duplicates).to be_empty
end
end
end

context "#miq_report_edit" do
describe "#miq_report_edit" do
it "should build tabs with correct tab id after reset button is pressed to prevent error when changing tabs" do
user = stub_user(:features => :all)
user.save!
Expand Down Expand Up @@ -200,7 +201,7 @@
end
end

describe "set_form_vars" do
describe "#set_form_vars" do
let(:admin_user) { FactoryBot.create(:user, :role => "super_administrator") }
let(:chargeback_report) do
FactoryBot.create(:miq_report, :db => "ChargebackVm", :col_order => ["name"], :headers => ["Name"])
Expand Down Expand Up @@ -282,6 +283,43 @@ def empty_category(attrs = {})
expect(controller.send(:entries_hash, "no_such_name")).to eq({})
end
end

describe '#form_field_changed' do
before do
allow(controller).to receive(:build_edit_screen)
allow(controller).to receive(:get_form_vars)
allow(controller).to receive(:load_edit).and_return(true)
allow(controller).to receive(:render)
controller.instance_variable_set(:@edit, :new => {:model => model})
end

context 'configuring Report Columns and Chargeback for VMs' do
let(:model) { 'ChargebackVm' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unavailable_fields)).to include('CPU Cores Allocated Metric, CPU Cores Used Metric')
end
end

context 'configuring Report Columns and Chargeback for Images' do
let(:model) { 'ChargebackContainerImage' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unavailable_fields)).to include('CPU Allocated Metric, CPU Used Metric, Disk I/O Used Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric')
end
end

context 'configuring Report Columns and Chargeback for Projects' do
let(:model) { 'ChargebackContainerProject' }

it 'sets string with unavailable fields while adding/editing report' do
controller.send(:form_field_changed)
expect(controller.instance_variable_get(:@unavailable_fields)).to include('CPU Allocated Metric, CPU Used Metric, CPU Cores Allocated Metric, Disk I/O Used Metric, Memory Allocated Metric, Fixed Storage Metric, Storage Allocated Metric, Storage Used Metric')
end
end
end
end

describe '#verify is_valid? flash messages' do
Expand Down
2 changes: 1 addition & 1 deletion spec/helpers/report_helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def create_and_generate_report_for_user(report_name, user_id)
end

describe ReportHelper do
context '#chart_fields_options' do
describe '#chart_fields_options' do
it 'should return fields with models and aggregate functions from summary when "Show Sort Breaks" is not "No"' do
@edit = {
:new => {
Expand Down