Skip to content

Commit

Permalink
Merge pull request #4621 from h-kataria/schedule_add_edit_accordion_s…
Browse files Browse the repository at this point in the history
…wap_fix

Fixed Schedules accordion swapping logic.
  • Loading branch information
Dan Clarizio authored Sep 7, 2018
2 parents 6767be2 + 62aec06 commit 0484125
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
3 changes: 1 addition & 2 deletions app/assets/javascripts/miq_explorer.js
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,7 @@ ManageIQ.explorer.processReplaceRightCell = function(data) {
ManageIQ.explorer.miqButtons(data);

if (_.isString(data.clearTreeCookies)) { miqDeleteTreeCookies(data.clearTreeCookies); }

if (_.isString(data.accordionSwap) && ! data.activateNode.activeTree.includes(data.accordionSwap)) {
if (_.isString(data.accordionSwap)) {
miqAccordionSwap('#accordion .panel-collapse.collapse.in', '#' + data.accordionSwap + '_accord');
}

Expand Down
1 change: 1 addition & 0 deletions app/controllers/report_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -847,6 +847,7 @@ def replace_right_cell(options = {}) # :replace_trees key can be an array of tre
end
presenter.show(:paging_div)
else
presenter.hide(:form_buttons_div)
presenter.hide(:paging_div)
end
if (@sb[:active_tab] == 'report_info' && x_node.split('-').length == 5 && !@in_a_form) || %w(xx-exportwidgets xx-exportcustomreports).include?(x_node)
Expand Down
3 changes: 1 addition & 2 deletions app/controllers/report_controller/schedules.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,11 +223,10 @@ def schedule_edit
# ensure we land in the right accordion with the right tree and
# with the listing opened even when entering 'add' from the reports
# menu

@_params[:accord] = "schedules" unless x_active_accord == :schedules
self.x_active_tree = "schedules_tree"
self.x_active_accord = "schedules"
self.x_node = "msc-#{schedule.id}"
@_params[:accord] = "schedules"
replace_right_cell(:replace_trees => [:schedules])
else
schedule.errors.each do |field, msg|
Expand Down
31 changes: 31 additions & 0 deletions spec/controllers/report_controller/schedules_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
let(:admin_user) { FactoryGirl.create(:user, :role => "super_administrator") }

let(:schedule) { FactoryGirl.create(:miq_schedule, :name => "tester1") }
let(:report) { FactoryGirl.create(:miq_report, :name => "report1") }

before do
EvmSpecHelper.create_guid_miq_server_zone
Expand All @@ -14,6 +15,15 @@
allow(controller).to receive(:assert_privileges)
allow(controller).to receive(:checked_or_params).and_return(MiqSchedule.all.ids)
allow(controller).to receive(:replace_right_cell).and_return(true)

timer = ReportHelper::Timer.new('hourly', 1, 1, 1, 1, Time.now.utc, '00', '00')
edit = {:key => "schedule_edit__#{schedule.id}",
:sched_id => schedule.id,
:new => {:name => "foo", :description => "Foo", :repfilter => report.id, :timer => timer}}
controller.instance_variable_set(:@edit, edit)
controller.instance_variable_set(:@sb, {})
session[:edit] = edit
allow(controller).to receive(:drop_breadcrumb)
end

it "reset rbac testing" do
Expand All @@ -22,5 +32,26 @@
expected_id = controller.instance_variable_get(:@schedule).id
expect(expected_id).to eq(schedule.id)
end

it "sets params accord only when schedule is added from Reports accordion" do
allow(controller).to receive(:x_active_accord).and_return(:reports)
post :schedule_edit, :params => { :button => "add", :id => schedule.id }
params = ActionController::Parameters.new('button' => 'add',
'id' => schedule.id.to_s,
'controller' => 'report',
'action' => 'schedule_edit',
'accord' => 'schedules')
expect(controller.params).to eq(params)
end

it "does not set params accord when adding/editing schedule from Schedules accordion" do
allow(controller).to receive(:x_active_accord).and_return(:schedules)
post :schedule_edit, :params => { :button => "add", :id => schedule.id }
params = ActionController::Parameters.new('button' => 'add',
'id' => schedule.id.to_s,
'controller' => 'report',
'action' => 'schedule_edit')
expect(controller.params).to eq(params)
end
end
end

0 comments on commit 0484125

Please sign in to comment.