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

Add markdown widget for interactive app forms #3767

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions apps/dashboard/app/lib/smart_attributes/attribute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 9 additions & 2 deletions apps/dashboard/app/models/batch_connect/session_context.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {})
Expand All @@ -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 Expand Up @@ -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: {})
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.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
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.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
Loading