Skip to content

Commit

Permalink
Fix save for unchanged segements
Browse files Browse the repository at this point in the history
  • Loading branch information
beque committed Apr 12, 2024
1 parent 1f69b8e commit 309a6d1
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions app/usecases/device_descriptions/update.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ def execute
attributes = remove_ontologies_marked_as_deleted
attributes = add_matching_segment_klasses(attributes)

device_description.update!(attributes.except(:segments))
save_segments
device_description.reload
device_description.update!(attributes.except(:segments))

device_description
end
Expand Down Expand Up @@ -122,11 +123,23 @@ def extract_segments(ontology, segment_klass, segments)
segments
end

def segments_to_save
segments = []
@segments.each_with_index do |segment, i|
dd_index = device_description.segments.index { |s| s[:id] == segment[:id] }
dd_segment = device_description.segments[dd_index ||= i]
layer = dd_segment.present? ? dd_segment.properties['layers'] : []
next if dd_index.present? && layer == segment['properties']['layers']

segments << segment
end
segments
end

def save_segments
return if @segments.blank?

# wenn es keine Änderungen gibt, werden segmente trotzdem nochmal geupdate
device_description.save_segments(segments: @segments, current_user_id: current_user.id)
device_description.save_segments(segments: segments_to_save, current_user_id: current_user.id)
end
end
end
Expand Down

0 comments on commit 309a6d1

Please sign in to comment.