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

CustomButtonSet - don't touch children/members directly, set button_order #5187

Merged
merged 1 commit into from
Mar 7, 2019
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
40 changes: 6 additions & 34 deletions app/controllers/application_controller/buttons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ def automate_button_field_changed
end
end

# AJAX driven routine to delete a user
def ab_button_delete
assert_privileges("ab_button_delete")
custom_button = CustomButton.find(params[:id])
Expand All @@ -152,14 +151,8 @@ def ab_button_delete
if custom_button.parent
automation_set = CustomButtonSet.find_by(:id => custom_button.parent.id)
if automation_set
mems = automation_set.members
if mems.length > 1
mems.each do |m|
automation_set.remove_member(custom_button) if m.id == custom_button
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

funnily enough, comparing integers and CustomButton instances probably didn't work

end
else
automation_set.remove_member(custom_button)
end
automation_set.set_data[:button_order].delete(custom_button.id)
automation_set.save!
end
end
if custom_button.destroy
Expand Down Expand Up @@ -234,12 +227,8 @@ def ab_group_delete
description = custom_button_set.description
audit = {:event => "custom_button_set_record_delete", :message => "[#{custom_button_set.description}] Record deleted", :target_id => custom_button_set.id, :target_class => "CustomButtonSet", :userid => session[:userid]}

mems = custom_button_set.members
mems.each do |mem|
uri = CustomButton.find(mem.id)
uri.save!
custom_button_set.remove_member(mem)
end
custom_button_set.set_data[:button_order] = []
custom_button_set.save!

if custom_button_set.destroy
AuditEvent.success(audit)
Expand Down Expand Up @@ -387,22 +376,8 @@ def group_button_add_save(typ)
end
group_set_record_vars(@custom_button_set)

member_ids = @edit[:new][:fields].collect { |field| field[1] }
mems = CustomButton.where(:id => member_ids)

if typ == "update"
org_mems = @custom_button_set.members # clean up existing members
org_mems.each do |m|
uri = CustomButton.find(m.id)
uri.save
end

if @custom_button_set.save
if mems.present? # replace children if members were added/updated
@custom_button_set.replace_children(mems)
else # remove members if nothing was selected
@custom_button_set.remove_all_children
end
add_flash(_("Button Group \"%{name}\" was saved") % {:name => @edit[:new][:description]})
@edit = session[:edit] = nil # clean out the saved info
ab_get_node_info(x_node) if x_active_tree == :ab_tree
Expand All @@ -425,7 +400,6 @@ def group_button_add_save(typ)
end
@custom_button_set.set_data[:group_index] = all_sets.length + 1
if @custom_button_set.save
@custom_button_set.replace_children(mems) if mems.present?
if x_active_tree == :sandt_tree
aset = CustomButtonSet.find_by(:id => @custom_button_set.id)
# push new button at the end of button_order array
Expand Down Expand Up @@ -539,7 +513,6 @@ def ab_button_add
# find custombutton set in ab_tree or when adding button under a group
group_id = x_active_tree == :ab_tree ? nodes[2].split('-').last : nodes[3].split('-').last
@aset = CustomButtonSet.find(group_id)
mems = @aset.members
end
end

Expand All @@ -549,8 +522,6 @@ def ab_button_add
au = CustomButton.find(@custom_button.id)
if @aset && nodes[0].split('-')[1] != "ub" && nodes.length >= 3
# if group is not unassigned group, add uri as a last member of the group
mems.push(au)
@aset.replace_children(mems)
@aset.set_data[:button_order] ||= []
@aset.set_data[:button_order].push(au.id)
@aset.save!
Expand Down Expand Up @@ -735,7 +706,8 @@ def group_set_form_vars
@edit[:new][:button_color] = @custom_button_set[:set_data] && @custom_button_set[:set_data][:button_color] ? @custom_button_set[:set_data][:button_color] : ""
@edit[:new][:display] = @custom_button_set[:set_data] && @custom_button_set[:set_data].key?(:display) ? @custom_button_set[:set_data][:display] : true
@edit[:new][:fields] = []
button_order = @custom_button_set[:set_data] && @custom_button_set[:set_data][:button_order] ? @custom_button_set[:set_data][:button_order] : nil

button_order = @custom_button_set[:set_data].try(:[], :button_order)
if button_order # show assigned buttons in order they were saved
button_order.each do |bidx|
@custom_button_set.members.each do |mem|
Expand Down
3 changes: 0 additions & 3 deletions app/controllers/generic_object_definition_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ def retrieve_distinct_instances_across_domains

def add_button_in_group
custom_button_set = CustomButtonSet.find(params[:id])
members = custom_button_set.members
members.push(CustomButton.find(params[:button_id]))
custom_button_set.replace_children(members)
custom_button_set.set_data[:button_order] ||= []
custom_button_set.set_data[:button_order].push(CustomButton.last.id)
custom_button_set.save!
Expand Down