Skip to content

Commit

Permalink
Merge pull request #1077 from isimluk/rhbz#1442158
Browse files Browse the repository at this point in the history
Do not store openshift env in the controller, use lookup helper instead
  • Loading branch information
martinpovolny authored Apr 20, 2017
2 parents 39f6b87 + ee2d8b3 commit 287dc37
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 32 deletions.
8 changes: 0 additions & 8 deletions app/controllers/report_controller/reports/editor.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1405,17 +1405,9 @@ def set_form_vars

def cb_entities_by_provider
@edit[:cb_providers] = { :container_project => {}, :container_image => {} }
@cb_entities_by_provider_id = { :container_project => {}, :container_image => {} }
ManageIQ::Providers::ContainerManager.includes(:container_projects, :container_images).all.each do |provider|
@edit[:cb_providers][:container_project][provider.name] = provider.id
@edit[:cb_providers][:container_image][provider.name] = provider.id
@cb_entities_by_provider_id[provider.id] = {:container_project => {}, :container_image => {}}
provider.container_projects.all.each do |project|
@cb_entities_by_provider_id[provider.id][:container_project][project.id] = project.name
end
provider.container_images.all.each do |image|
@cb_entities_by_provider_id[provider.id][:container_image][image.id] = image.name
end
end
end

Expand Down
2 changes: 2 additions & 0 deletions app/helpers/report_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module ReportHelper
include_concern 'Editor'

STYLE_CLASSES = {
:miq_rpt_red_text => _("Red Text"),
:miq_rpt_red_bg => _("Red Background"),
Expand Down
12 changes: 12 additions & 0 deletions app/helpers/report_helper/editor.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
module ReportHelper::Editor
def cb_entities_by_provider_id(provider_id, entity_type)
provider = ManageIQ::Providers::ContainerManager.find(provider_id)
return [] if provider.nil?
case entity_type.underscore.to_sym
when :container_project
provider.container_projects.order(:name).pluck(:name, :id)
when :container_image
provider.container_images.order(:name).pluck(:name, :id)
end
end
end
3 changes: 1 addition & 2 deletions app/views/report/_form_filter_chargeback.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,7 @@
.col-md-8
- opts = [["<#{_('Choose %{entity}')}>" % {:entity => ui_lookup(:model => @edit[:new][:cb_model])}, nil],
[_("All %{chargeback_type}") % {:chargeback_type => ui_lookup(:tables => @edit[:new][:cb_model].to_s)}, :all]]
- if @cb_entities_by_provider_id[@edit[:new][:cb_provider_id].to_i].present?
- opts += Array(@cb_entities_by_provider_id[@edit[:new][:cb_provider_id].to_i][@edit[:new][:cb_model].underscore.to_sym].invert).sort_by { |a| a.first.downcase }
- opts += cb_entities_by_provider_id(@edit[:new][:cb_provider_id].to_i, @edit[:new][:cb_model])
= select_tag('cb_entity_id',
options_for_select(opts, @edit[:new][:cb_entity_id]),
:class => "selectpicker")
Expand Down
22 changes: 0 additions & 22 deletions spec/controllers/report_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1285,28 +1285,6 @@
expect(MiqReport.last.db).to eq(chosen_model)
end

it "cb_entities_by_provider_id is set for chargeback based reports" do
post :x_button, :params => {:pressed => "miq_report_new"}
post :form_field_changed, :params => {:id => "new", :chosen_model => "ChargebackContainerImage"}
post :form_field_changed, :params => {:id => "new", :title => "test"}
post :form_field_changed, :params => {:id => "new", :name => "test"}
post :form_field_changed, :params => {:button => "right", :available_fields => ["ChargebackContainerImage-archived"]}

post :miq_report_edit, :params => {:button => "add"}
expect(assigns(:cb_entities_by_provider_id)).not_to be_nil
end

it "cb_entities_by_provider_id is not set for not chargeback reports" do
post :x_button, :params => {:pressed => "miq_report_new"}
post :form_field_changed, :params => {:id => "new", :chosen_model => "Host"}
post :form_field_changed, :params => {:id => "new", :title => "test"}
post :form_field_changed, :params => {:id => "new", :name => "test"}
post :form_field_changed, :params => {:button => "right", :available_fields => ["Host-name"]}

post :miq_report_edit, :params => {:button => "add"}
expect(assigns(:cb_entities_by_provider_id)).to be_nil
end

it 'allows user to remove columns while editing' do
post :x_button, :params => {:pressed => 'miq_report_new'}
post :form_field_changed, :params => {:id => 'new', :chosen_model => chosen_model}
Expand Down

0 comments on commit 287dc37

Please sign in to comment.