Skip to content

Commit

Permalink
Remove steps, simplify locals, panel formatted_content
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 15, 2024
1 parent 7f735ee commit 3fb4682
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 149 deletions.
4 changes: 2 additions & 2 deletions app/helpers/panel_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def panel_block(**args, &block)
concat(heading)
if args[:panel_bodies].present?
concat(panel_bodies(args))
elsif args[:content].present?
concat(args[:content])
elsif args[:formatted_content].present?
concat(content)
elsif args[:collapse].present?
concat(panel_collapse_body(args, content))
else
Expand Down
56 changes: 38 additions & 18 deletions app/views/controllers/observations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,19 @@
create = (action == :create)
method = create ? :post : :patch
button_name = create ? :CREATE.l : :SAVE_EDITS.l
include_naming = create ? true : false
has_specimen = create ? false : @observation.herbarium_records.length > 0
logging_optional = create ? false : true
naming_locals = {
create:,
button_name:,
show_reasons: false,
unfocused: true,
name_help: :form_naming_name_help_leave_blank.t
}
naming_locals = {} unless create
show_projects = @projects.any? || @error_checked_projects.any? ||
@suspect_checked_projects.any?
show_lists = @lists.any?

# Data for the form-images Stimulus controller.
# Controller element is the form, so image dropzone can cover the whole form.
Expand All @@ -20,7 +30,7 @@ image_upload_localization = {
something_went_wrong: :form_observations_upload_error.t
}.to_json
# Outlets are how the stimulus controllers call each others' methods.
data = {
form_element_data = {
controller: "form-images form-exif map",
map_autocompleter_outlet: "#observation_location_autocompleter",
map_open: false,
Expand All @@ -32,9 +42,6 @@ data = {
form_images_target: "form",
exif_used: create ? false : true
}
show_projects = @projects.any? || @error_checked_projects.any? ||
@suspect_checked_projects.any?
show_lists = @lists.any?
%>

<%= form_with(
Expand All @@ -45,27 +52,42 @@ show_lists = @lists.any?
method:,
multipart: true,
id: "observation_form",
data:
data: form_element_data
) do |f| %>

<% if @field_code %>
<%= tag.p("#{:form_observations_field_code.t} #{@field_code}") %>
<%= hidden_field_tag(:field_code, @field_code) %>
<% end %>

<% content = [
render(partial: "observations/form/images", locals: { f: }),
render(partial: "observations/form/details",
locals: { f:, button_name:, location: @location, logging_optional:,
action:, include_naming: }),
].safe_join %>
<%= panel_block(
heading: "#{:IMAGES.l} + #{:show_observation_details.l}",
id: "observation_images_details", content:
) %>
id: "observation_images_details", formatted_content: true
) do
concat(render(partial: "observations/form/images", locals: { f: }))
concat(render(partial: "observations/form/details",
locals: { f:, action:, button_name:, location: @location,
logging_optional: }))
end %>

<%= panel_block(
id: "observation_identification",
heading: "#{:IDENTIFICATION.l} + #{:SPECIMEN.l}",
collapse: "observation_specimen_inner",
open: true # @given_name.present?
) do
tag.div(class: "row mt-3") do
concat(tag.div(class: "col-xs-12 col-md-6") do
render(partial: "observations/namings/fields", locals: naming_locals)
end)
concat(tag.div(class: "col-xs-12 col-md-6") do
render(partial: "observations/form/specimen_section",
locals: { f:, action: })
end)
end
end %>

<%= render(partial: "observations/form/identify_specimen",
locals: { f:, action:, button_name:, include_naming: }) %>
<%= submit_button(form: f, button: button_name, center: true) %>

<%= panel_block(
heading: :NOTES.l,
Expand All @@ -77,8 +99,6 @@ show_lists = @lists.any?
locals: { form: f, fields: @observation.form_notes_parts(@user) })
end %>

<%= submit_button(form: f, button: button_name, center: true) %>

<% if show_projects %>
<%= panel_block(
heading: :PROJECTS.l,
Expand Down
30 changes: 0 additions & 30 deletions app/views/controllers/observations/form/_add_to_step.erb

This file was deleted.

12 changes: 0 additions & 12 deletions app/views/controllers/observations/form/_details.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ t_s = {
lng: { abbr: :LNG.l, full: :LONGITUDE.l, addon: "º" },
alt: { abbr: :ALT.l, full: :ALTITUDE.l, addon: "m" }
}
naming_locals = if include_naming
{
f: f,
action: action,
button_name: button_name,
show_reasons: false,
unfocused: true,
name_help: :form_naming_name_help_leave_blank.t
}
else
{}
end
%>

<%= tag.div(class: "panel-body border-top", id: "observation_details") do %>
Expand Down
29 changes: 0 additions & 29 deletions app/views/controllers/observations/form/_identify_specimen.erb

This file was deleted.

26 changes: 0 additions & 26 deletions app/views/controllers/observations/form/_record_step.erb

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ herbarium_record. Fields hidden unless box checked. %>
<%= tag.div(id: "specimen_fields",
class: ("hidden" if !@observation.specimen),
data: { specimen_target: "fields" }) do %>
<%= render(partial: "observations/form/collection_number") %>
<%= render(partial: "observations/form/herbarium_record") %>
<%= render(partial: "observations/form/specimen/collection_number") %>
<%= render(partial: "observations/form/specimen/herbarium_record") %>
<% end %>
<!-- /specimen_fields -->
<% end %>
Expand Down
17 changes: 7 additions & 10 deletions app/views/controllers/observations/namings/_fields.erb
Original file line number Diff line number Diff line change
@@ -1,28 +1,25 @@
<%# locals: (create:, button_name:, show_reasons:, unfocused: false, name_help: :form_naming_name_help.t, context: "blank" ) -%>

<%
# This is included by obs form, naming new/edit form + lightbox identifier

unfocused ||= false
focus_on_name = !unfocused && (button_name != :CREATE.l || @given_name.empty?)
focus_on_vote = !unfocused && (button_name == :CREATE.l && @given_name.present?)
focus_on_name = !unfocused && (!create || @given_name.empty?)
focus_on_vote = !unfocused && (create && @given_name.present?)

feedback_locals = {
f: f,
button_name: button_name,
given_name: @given_name,
names: @names,
valid_names: @valid_names,
suggest_corrections: @suggest_corrections,
parent_deprecated: @parent_deprecated,
names: @names
parent_deprecated: @parent_deprecated
}
menu = unless @vote&.value&.nonzero?
Vote.opinion_menu
else
Vote.confidence_menu
end
confidences = options_for_select(menu, @vote&.value)
select_opts = { include_blank: ["new", "create"].include?(action_name) }
context ||= "blank"
name_help ||= :form_naming_name_help.t
select_opts = { include_blank: create }
feedback = if @given_name.present?
tag.div do
render(partial: "shared/form_name_feedback",
Expand Down
16 changes: 10 additions & 6 deletions app/views/controllers/observations/namings/_form.erb
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<%# locals: (local:, show_reasons: true, form_locals: {}) -%>

<%
# Fields must be separate because they're included in the obs form too.
# HTML ID's may seem overly precise, but there may be more than one of
# these forms open on a page if modal. IDs must be unique.
case action_name
when "new", "create"
create = true
button_name = :CREATE.l
method = :post
id = "obs_#{@observation.id}_naming_form"
url = observation_namings_path(observation_id: @observation.id,
approved_name: @given_name,
q: get_query_param)
when "edit", "update"
create = false
button_name = :SAVE_EDITS.l
method = :patch
id = "obs_#{@observation.id}_naming_#{@naming.id}_form"
Expand All @@ -20,23 +24,23 @@ when "edit", "update"
q: get_query_param)
end

# `local` true means do not send via Turbo.
form_args = { model: @naming, url: url, method: method, id: id }
if local_assigns[:local] == true
form_args = form_args.merge({ local: true })
else
form_args = form_args.deep_merge({ data: { turbo: true } })
end

# Note: the form needs local_assigns[:form_locals].
# I can't find where show_reasons is ever false - AN 20230801
form_locals = local_assigns[:form_locals] || {}
# `naming_locals`: modal forms can accept a `form_locals` local. The controller
# may send `context` (i.e. where the form appears), which defaults to "blank".
# `show_reasons` is false on the obs form, true on the naming form.
naming_locals = { create:, button_name:, show_reasons: }.merge(form_locals)
%>

<%= form_with(**form_args) do |f| %>

<%= render(partial: "observations/namings/fields", locals: naming_locals) %>
<%= submit_button(form: f, button: button_name, center: true) %>

<%= render(partial: "observations/namings/fields",
locals: { f: f, button_name: button_name }.merge(form_locals)) %>

<% end # form %>
3 changes: 1 addition & 2 deletions app/views/controllers/observations/namings/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ add_tab_set(naming_form_edit_tabs(obs: @observation))

<div class="mt-3">
<%= render(partial: "observations/namings/form",
locals: { action: :update, show_reasons: true,
local: true }) %>
locals: { show_reasons: true, local: true }) %>
</div>
</div><!--.col-->

Expand Down
3 changes: 1 addition & 2 deletions app/views/controllers/observations/namings/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ add_tab_set(naming_form_new_tabs(obs: @observation))

<div class="mt-3">
<%= render(partial: "observations/namings/form",
locals: { action: :create, show_reasons: true,
local: true }) %>
locals: { show_reasons: true, local: true }) %>
</div>
</div><!--.col-->

Expand Down
15 changes: 5 additions & 10 deletions app/views/controllers/shared/_form_name_feedback.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<%# locals: (given_name:, button_name:, names:, valid_names:, suggest_corrections:, parent_deprecated:) -%>

<%#
Handling deprecated, new & multiple Names
Used by Name and Naming create and edit pages
Feedback if the user entered deprecated, new or multiple Names
Used by Observation, Name and Naming create and edit pages
Does two things:
Describes the issue - Deprecated, Parent Deprecated, or Not Recognized
Adds Help how to proceed - depends on issue and the button
Expand All @@ -12,18 +14,11 @@ names - Name(s) corresponding to given_name
valid_names - Name(s) that are valid synonyms
suggest_corrections - t/f whether to suggest correction(s)
parent_deprecated - t/f
TODO:
Differentiate warning (valid_names) from error (!valid_names)
A conditional to watch is `if @params[:given_name].present?`.
Also, views/observations/namings/fields is doing too much work,
the multiple local_assigns for this partial should be set upstream.
%>

<%=
##### Warnings #####
if valid_names
##### Warnings #####

tag.div(class: "alert alert-warning", id: "name_messages") do
concat(tag.div do
if suggest_corrections || names.blank?
Expand Down

0 comments on commit 3fb4682

Please sign in to comment.