Skip to content

Commit

Permalink
Refactor serializable SmartAttributes
Browse files Browse the repository at this point in the history
  • Loading branch information
robinkar committed Sep 2, 2024
1 parent 72b171d commit e90533b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
7 changes: 7 additions & 0 deletions apps/dashboard/app/models/batch_connect/session_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def [](id)
# @yield [SmartAttribute::Attribute] Gives the next attribute object in the
# list
def each(&block)
@attributes.select(&:serialize?).each(&block)
end

# For a block {|attribute| ...}
# @yield [SmartAttribute::Attribute] Gives the next attribute object in the
# list. Includes non-serializable attributes.
def each_form_attribute(&block)
@attributes.each(&block)
end

Expand Down
6 changes: 4 additions & 2 deletions apps/dashboard/app/models/batch_connect/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@ def app

def outdated?
outdated = false

attributes = app.build_session_context
# CHECK IF THERE ARE NEW ATTRIBUTES NOT IN THE VALUES HASH
app.attributes.select(&:serialize?).each do |attribute|
attributes.each do |attribute|
outdated = true unless values.key?(attribute.id.to_sym)
end
# CHECK IF THERE ARE OLD VALUES NO LONGER IN THE APP ATTRIBUTES STILL IN THE VALUES HASH
values.each_key do |attribute_id|
outdated = true if app.attributes.select(&:serialize?).select { |attribute| attribute.id.to_sym == attribute_id }.empty?
outdated = true if attributes.select { |attribute| attribute.id.to_sym == attribute_id }.empty?
end

outdated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<%= render "prefill_templates" if Configuration.bc_saved_settings? %>

<%= bootstrap_form_for(@session_context, html: { autocomplete: "off" }) do |f| %>
<% f.object.each do |attrib| %>
<% f.object.each_form_attribute do |attrib| %>
<%= create_widget(f, attrib, format: @render_format) %>
<% end %>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ locals: {
end
%>
</div>
<% @settings.app.attributes.select(&:serialize?).each do |attribute| %>
<% @settings.app.build_session_context.each do |attribute| %>
<p>
<strong><%= attribute.label %>:</strong>
<span><%= @settings.values[attribute.id.to_sym] %></span>
Expand Down

0 comments on commit e90533b

Please sign in to comment.