Skip to content

Commit

Permalink
Merge pull request #15658 from jntullo/bug/fix_dialog_edit
Browse files Browse the repository at this point in the history
Fix service dialog edit
  • Loading branch information
martinpovolny authored Jul 27, 2017
2 parents 23c6fa0 + 5350e2a commit d110908
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 15 deletions.
22 changes: 12 additions & 10 deletions app/models/dialog.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,19 +123,21 @@ def content(target = nil, resource_action = nil, all_attributes = false)
# Creates a new item without an ID,
# Removes any items not passed in the content.
def update_tabs(tabs)
updated_tabs = []
tabs.each do |dialog_tab|
if dialog_tab.key?('id')
DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab|
tab.update_attributes(dialog_tab.except('dialog_groups'))
tab.update_dialog_groups(dialog_tab['dialog_groups'])
updated_tabs << tab
transaction do
updated_tabs = []
tabs.each do |dialog_tab|
if dialog_tab.key?('id')
DialogTab.find(self.class.uncompress_id(dialog_tab['id'])).tap do |tab|
tab.update_attributes(dialog_tab.except('id', 'href', 'dialog_id', 'dialog_groups'))
tab.update_dialog_groups(dialog_tab['dialog_groups'])
updated_tabs << tab
end
else
updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first
end
else
updated_tabs << DialogImportService.new.build_dialog_tabs('dialog_tabs' => [dialog_tab]).first
end
self.dialog_tabs = updated_tabs
end
self.dialog_tabs = updated_tabs
end

def deep_copy(new_attributes = {})
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_group.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def update_dialog_fields(fields)
DialogField.find(self.class.uncompress_id(field['id'])).tap do |dialog_field|
resource_action_fields = field.delete('resource_action') || {}
update_resource_fields(resource_action_fields, dialog_field)
dialog_field.update_attributes(field)
dialog_field.update_attributes(field.except('id', 'href', 'dialog_group_id'))
updated_fields << dialog_field
end
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/dialog_tab.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def update_dialog_groups(groups)
groups.each do |group|
if group.key?('id')
DialogGroup.find(self.class.uncompress_id(group['id'])).tap do |dialog_group|
dialog_group.update_attributes(group.except('dialog_fields'))
dialog_group.update_attributes(group.except('id', 'href', 'dialog_tab_id', 'dialog_fields'))
dialog_group.update_dialog_fields(group['dialog_fields'])
updated_groups << dialog_group
end
Expand Down
9 changes: 6 additions & 3 deletions spec/models/dialog_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -284,13 +284,16 @@
let(:updated_content) do
[
{
'id' => dialog_tab.first.id,
'id' => dialog_tab.first.compressed_id,
'label' => 'updated_label',
'dialog_groups' => [
{ 'id' => dialog_group.first.id,
{ 'id' => dialog_group.first.compressed_id,
'dialog_tab_id' => dialog_tab.first.compressed_id,
'dialog_fields' =>
[{
'id' => dialog_field.first.id}] },
'id' => dialog_field.first.id,
'dialog_group_id' => dialog_group.first.compressed_id
}] },
{
'label' => 'group 2',
'dialog_fields' => [{
Expand Down

0 comments on commit d110908

Please sign in to comment.