Skip to content

Commit

Permalink
Redesign form
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 15, 2024
1 parent b0b73e8 commit d418554
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 146 deletions.
63 changes: 12 additions & 51 deletions app/views/controllers/observations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,6 @@ data = {
form_images_target: "form",
exif_used: create ? false : true
}
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
show_projects = @projects.any? || @error_checked_projects.any? ||
@suspect_checked_projects.any?
show_lists = @lists.any?
Expand All @@ -65,48 +53,19 @@ show_lists = @lists.any?
<%= hidden_field_tag(:field_code, @field_code) %>
<% end %>

<%# tab_content do %>
<%= render(partial: "observations/form/record_step",
locals: { f:, button_name:, location: @location,
logging_optional: }) %>

<%= render(partial: "observations/form/identify_step",
locals: { f:, action:, button_name:, include_naming: }) %>

<% if projects_lists %>
<%= render(partial: "observations/form/add_to_step",
locals: { f:, button_name: }) %>
<% end %>
<%# 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"
) do %>
<%= render(partial: "observations/form/images", locals: { f: }) %>
id: "observation_images_details", content:
) %>

<%= render(partial: "observations/form/details",
locals: { f:, button_name:, location:, logging_optional: }) %>
<% end %>

<%= panel_block(
heading: :IDENTIFICATION.l,
id: "observation_identification",
collapse: "observation_identification_inner",
open: false
) do
render(partial: "observations/namings/fields", locals: naming_locals)
end %>

<%= panel_block(
heading: :SPECIMEN.l,
id: "observation_specimen",
collapse: "observation_specimen_inner",
open: false
) do
render(partial: "observations/form/specimen_section",
locals: { f:, action: })
end %>
<%= render(partial: "observations/form/identify_specimen",
locals: { f:, action:, button_name:, include_naming: }) %>

<%= panel_block(
heading: :NOTES.l,
Expand All @@ -118,6 +77,8 @@ 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
101 changes: 57 additions & 44 deletions app/views/controllers/observations/form/_details.html.erb
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
<%# locals: (f:, button_name:, location:, logging_optional:) -%>
<%# locals: (f:, action:, button_name:, location:, logging_optional:, include_naming: false) -%>

<%# When and Where (location) section of create_observation form
including location autocomplete, map, lat/long/alt %>
including location autocomplete, map, lat/long/alt, naming %>
<%
t_s = {
lat: { abbr: :LAT.l, full: :LATITUDE.l, addon: "º" },
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 All @@ -21,44 +33,13 @@ t_s = {
<!-- /WHEN -->

<%= tag.div(id: "observation_where") do %>
<%= tag.p do
[tag.strong("#{:WHERE_GROUP.l}:"),
collapse_info_trigger("geolocation_help")].safe_join(" ")
end %>

<!-- LAT_LONG_ALT -->
<%= tag.div(class: "row no-gutters",
id: "observation_lat_lng_alt") do %>
<% [:lat, :lng, :alt].each do |key| %>
<%= tag.div(class: "col-xs-4") do
text_field_with_label(
form: f, field: key, class: "mb-0", addon: t_s[key][:addon],
label: [
tag.span("#{t_s[key][:full]}:", class: "d-none d-sm-inline"),
tag.span("#{t_s[key][:abbr]}:", class: "d-inline d-sm-none")
].safe_join,
data: { map_target: "#{key}Input", action: "map#bufferInputs" }
)
end %>
<% end %>
<% end %>

<%= collapse_help_block(nil, id: "geolocation_help") do %>
<%= tag.p(:form_observations_click_point.l) %>
<%= tag.p(:form_observations_lat_long_help.t) %>
<% end %>

<%= check_box_with_label(form: f, field: :gps_hidden,
label: :form_observations_gps_hidden.l) %>
<!-- /LAT_LONG_ALT -->

<!-- WHERE_REASONS -->
<%= render(partial: "shared/form_location_feedback",
locals: { button: button_name } ) %>
<!-- /WHERE_REASONS -->

<%= autocompleter_field(
form: f, field: :place_name, type: :location,
form: f, field: :place_name, type: :location, class: "mb-0",
label: [tag.span("#{:WHERE.l}:", class: "unconstrained-label"),
tag.span("#{:form_observations_locality_contains.l}:",
class: "constrained-label"),
Expand All @@ -85,38 +66,70 @@ t_s = {
}
) %>

<%= render(partial: "locations/form/bounds_hidden_fields",
locals: { location: @location, target_controller: :map }) %>
<!-- /WHERE -->

<!-- IS_COLLECTION_LOCATION -->
<%= check_box_with_label(
form: f, field: :is_collection_location,
label: :form_observations_is_collection_location.l,
help: :form_observations_is_collection_location_help.t
help: :form_observations_is_collection_location_help.t,
class: "ml-5 mb-5"
) %>
<!-- /IS_COLLECTION_LOCATION -->

<%= render(partial: "locations/form/bounds_hidden_fields",
locals: { location: @location, target_controller: :map }) %>
<!-- /WHERE -->

<!-- LAT_LONG_ALT -->
<%= tag.p do
[tag.strong("#{:GEOLOCATION.l}:"),
collapse_info_trigger("geolocation_help")].safe_join(" ")
end %>

<%= tag.div(class: "row no-gutters",
id: "observation_lat_lng_alt") do %>
<% [:lat, :lng, :alt].each do |key| %>
<%= tag.div(class: "col-xs-4") do
text_field_with_label(
form: f, field: key, class: "mb-0", addon: t_s[key][:addon],
label: [
tag.span("#{t_s[key][:full]}:", class: "d-none d-sm-inline"),
tag.span("#{t_s[key][:abbr]}:", class: "d-inline d-sm-none")
].safe_join,
data: { map_target: "#{key}Input", action: "map#bufferInputs" }
)
end %>
<% end %>
<% end %>

<%= collapse_help_block(nil, id: "geolocation_help") do %>
<%= tag.p(:form_observations_click_point.l) %>
<%= tag.p(:form_observations_lat_long_help.t) %>
<% end %>

<%= check_box_with_label(
form: f, field: :gps_hidden, label: :form_observations_gps_hidden.l,
class: "ml-5 mb-5"
) %>
<!-- /LAT_LONG_ALT -->

<% if logging_optional %>
<%= check_box_with_label(
form: f, field: :log_change, checked: "checked",
label: :form_observations_log_change.t
) %>
<% end %>

<% end %>
<% end %><!--.col-->

<!-- MAP -->
<%= tag.div(class: "col-xs-12 col-md-6",
id: "observation_geolocation") do %>
<%= render(
partial: "shared/form_location_map",
locals: { id: "observation_form_map", map_type: "observation" }
) %>
partial: "shared/form_location_map",
locals: { id: "observation_form_map", map_type: "observation" }
) %>
<% end %>
<!-- /MAP -->

<% end %><!--.row-->

<% end %>
29 changes: 29 additions & 0 deletions app/views/controllers/observations/form/_identify_specimen.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<%# locals: (f:, action:, button_name:, include_naming:) -%>

<%= panel_block(
id: "observation_identification",
heading: "#{:IDENTIFICATION.l} + #{:SPECIMEN.l}",
collapse: "observation_specimen_inner",
open: false
) do %>
<%= tag.div(class: "row mt-3") do %>
<%= tag.div(class: "col-xs-12 col-lg-6") do %>
<% if include_naming
naming_locals = {
f: f,
action: action,
button_name: button_name,
show_reasons: false,
unfocused: true,
name_help: :form_naming_name_help_leave_blank.t
} %>
<%= render(partial: "observations/namings/fields",
locals: naming_locals) %>
<% end %>
<% end %>
<%= tag.div(class: "col-xs-12 col-lg-6") do %>
<%= render(partial: "observations/form/specimen_section",
locals: { f:, action: }) %>
<% end %>
<% end %>
<% end %>
38 changes: 0 additions & 38 deletions app/views/controllers/observations/form/_identify_step.erb

This file was deleted.

14 changes: 6 additions & 8 deletions app/views/controllers/observations/form/_images.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@ i.e. not observation[good_image_ids]. It's a top-level field. --%>

<%= tag.div(id: "observation_images") do %>

<%= hidden_field_tag(:good_image_ids,
@good_images.map { |img| img.id }.join(" "),
data: { form_images_target: "goodImageIds" }) %>

<%= f.hidden_field(:thumb_image_id,
data: { form_images_target: "thumbImageId" }) %>

<%= tag.div(class: "panel-body border-bottom") do
[
tag.h4(:IMAGES.l, class: "panel-title d-inline-block mr-4"),
Expand All @@ -32,7 +25,12 @@ i.e. not observation[good_image_ids]. It's a top-level field. --%>
data: { action: "change->form-images#addSelectedFiles" }
)
].safe_join
end
end,
hidden_field_tag(:good_image_ids,
@good_images.map { |img| img.id }.join(" "),
data: { form_images_target: "goodImageIds" }),
f.hidden_field(:thumb_image_id,
data: { form_images_target: "thumbImageId" })
].safe_join
end %>

Expand Down
6 changes: 6 additions & 0 deletions app/views/controllers/observations/form/_record_step.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,11 @@
<%= render(partial: "observations/form/details",
locals: { f:, button_name:, location:, logging_optional: }) %>

<%= tag.div(class: "panel-body mt-4") do
tag.div(class: "text-center", id: "step-nav-1") do
tab_link(:NEXT.l, id: "identify", button: true)
end
end %>

<% end %>
<% end %>
15 changes: 10 additions & 5 deletions app/views/controllers/observations/namings/_fields.erb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ 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
feedback = if @given_name.present?
tag.div do
render(partial: "shared/form_name_feedback",
locals: feedback_locals)
end
else
""
end
%>

<%=
[
tag.div do
render(partial: "shared/form_name_feedback",
locals: feedback_locals) if @given_name.present?
end,
feedback,
fields_for(:naming) do |f_n|
[
autocompleter_field(
Expand All @@ -49,5 +54,5 @@ name_help ||= :form_naming_name_help.t
].safe_join
end,
hidden_field_tag(:context, context)
].safe_join
].compact.safe_join
%>

0 comments on commit d418554

Please sign in to comment.