diff --git a/apps/dashboard/app/helpers/batch_connect/session_contexts_helper.rb b/apps/dashboard/app/helpers/batch_connect/session_contexts_helper.rb index daf23edc33..f1a4c92252 100644 --- a/apps/dashboard/app/helpers/batch_connect/session_contexts_helper.rb +++ b/apps/dashboard/app/helpers/batch_connect/session_contexts_helper.rb @@ -35,6 +35,8 @@ def create_widget(form, attrib, format: nil, hide_excludable: true, hide_fixed: end when 'file_attachments' render :partial => "batch_connect/session_contexts/file_attachments", :locals => { form: form, attrib: attrib, field_options: field_options } + when 'markdown' + OodAppkit.markdown.render(attrib.value.to_s).html_safe else form.send widget, attrib.id, all_options end diff --git a/apps/dashboard/app/lib/smart_attributes/attribute.rb b/apps/dashboard/app/lib/smart_attributes/attribute.rb index 735bcf53d0..866668f864 100644 --- a/apps/dashboard/app/lib/smart_attributes/attribute.rb +++ b/apps/dashboard/app/lib/smart_attributes/attribute.rb @@ -68,6 +68,10 @@ def widget (opts[:widget] || 'text_field').to_s end + def serialize? + !!opts.fetch(:serialize, widget != "markdown") + end + # Form label for this attribute # @param fmt [String, nil] formatting of form label # @return [String] form label diff --git a/apps/dashboard/app/models/batch_connect/session_context.rb b/apps/dashboard/app/models/batch_connect/session_context.rb index 7523bf9e94..5313c469a6 100644 --- a/apps/dashboard/app/models/batch_connect/session_context.rb +++ b/apps/dashboard/app/models/batch_connect/session_context.rb @@ -14,7 +14,7 @@ class SessionContext # Attributes used for serialization # @return [Hash{String => String, nil}] attributes to be serialized def attributes - @attributes.reject(&:fixed?).map { |a| [a.id.to_s, nil] }.to_h + @attributes.reject(&:fixed?).select(&:serialize?).map { |a| [a.id.to_s, nil] }.to_h end def attributes=(params = {}) @@ -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 @@ -69,7 +76,7 @@ def update_with_cache(cache) end def to_h - Hash[*map { |a| [a.id.to_sym, a.value] }.flatten] + Hash[*select(&:serialize?).map { |a| [a.id.to_sym, a.value] }.flatten] end def to_openstruct(addons: {}) diff --git a/apps/dashboard/app/models/batch_connect/settings.rb b/apps/dashboard/app/models/batch_connect/settings.rb index fe38be0ac8..26a186f8f5 100644 --- a/apps/dashboard/app/models/batch_connect/settings.rb +++ b/apps/dashboard/app/models/batch_connect/settings.rb @@ -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.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 { |attribute| attribute.id.to_sym == attribute_id }.empty? + outdated = true if attributes.select { |attribute| attribute.id.to_sym == attribute_id }.empty? end outdated diff --git a/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb b/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb index 0b5d387772..66a4b9eba1 100644 --- a/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb +++ b/apps/dashboard/app/views/batch_connect/session_contexts/_form.html.erb @@ -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 %> diff --git a/apps/dashboard/app/views/batch_connect/settings/show.html.erb b/apps/dashboard/app/views/batch_connect/settings/show.html.erb index 75e1fc864a..53013c9597 100644 --- a/apps/dashboard/app/views/batch_connect/settings/show.html.erb +++ b/apps/dashboard/app/views/batch_connect/settings/show.html.erb @@ -68,7 +68,7 @@ locals: { end %> - <% @settings.app.attributes.each do |attribute| %> + <% @settings.app.build_session_context.each do |attribute| %>
<%= attribute.label %>: <%= @settings.values[attribute.id.to_sym] %>