Skip to content

Commit

Permalink
Merge branch 'main' into herbarium-form-modal
Browse files Browse the repository at this point in the history
  • Loading branch information
nimmolo committed Aug 20, 2024
2 parents 2d98814 + 38692dc commit 42bdf78
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 70 deletions.
18 changes: 1 addition & 17 deletions app/helpers/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ def url_field_with_label(**args)
end

# Bootstrap file input field with client-side size validation.
# This could be redone as an input group with a "browse" button, in BS4.
def file_field_with_label(**args)
args = check_for_help_block(args)
opts = separate_field_options_from_args(args)
Expand Down Expand Up @@ -426,23 +427,6 @@ def file_field_with_label(**args)
end
end

# To be retired in favor of the above:
# Create stylable file input field with client-side size validation.
def custom_file_field(obj, attr, opts = {})
max_size = MO.image_upload_max_size
max_size_in_mb = (max_size.to_f / 1024 / 1024).round
file_field = file_field(
obj,
attr,
opts.merge(
max_upload_msg: :validate_image_file_too_big.l(max: max_size_in_mb),
max_upload_size: max_size
)
)
tag.span(:select_file.t + file_field, class: "file-field btn btn-default") +
tag.span(:no_file_selected.t)
end

# Unused
# def search_field_with_submit(args)
# opts = separate_field_options_from_args(args)
Expand Down
6 changes: 1 addition & 5 deletions app/helpers/observations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,7 @@ def observation_map_coordinates(obs:)
def observation_show_image_links(obs:)
return "" unless check_permission(obs)

[
icon_link_with_query(*new_image_for_observation_tab(obs)),
icon_link_with_query(*reuse_images_for_observation_tab(obs)),
icon_link_with_query(*remove_images_from_observation_tab(obs))
].safe_join(" | ")
icon_link_with_query(*reuse_images_for_observation_tab(obs))
end

# The following sections of the observation_details partial are also needed as
Expand Down
17 changes: 1 addition & 16 deletions app/helpers/tabs/observations_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -105,24 +105,12 @@ def observation_hide_thumbnail_map_tab(obs)
{ class: tab_id(__method__.to_s), icon: :hide }]
end

def new_image_for_observation_tab(obs)
[:show_observation_add_images.l,
new_image_for_observation_path(obs.id),
{ class: tab_id(__method__.to_s), icon: :add }]
end

def reuse_images_for_observation_tab(obs)
[:show_observation_reuse_image.l,
reuse_images_for_observation_path(obs.id),
{ class: tab_id(__method__.to_s), icon: :reuse }]
end

def remove_images_from_observation_tab(obs)
[:show_observation_remove_images.l,
remove_images_from_observation_path(obs.id),
{ class: tab_id(__method__.to_s), icon: :remove }]
end

############################################
# INDEX

Expand Down Expand Up @@ -286,10 +274,7 @@ def obs_change_tabs(obs)
end

def obs_details_links(obs)
return print_labels_button(obs) unless check_permission(obs)

[print_labels_button(obs),
obs_change_links(obs)].safe_join(" | ")
print_labels_button(obs)
end

# Buttons in "Details" panel header
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ left_cols = add_right_tabs ? "col-xs-8 col-lg-7" : "col-xs-12"
<%= content_tag_if(add_right_tabs, :div, id: "right_tabs",
class: "hidden-print text-right col-sm-4 col-lg-5 mb-3") do
concat(yield(:interest_icons))
concat(yield(:edit_icons))
concat(yield(:tab_set))
end %>

Expand Down
12 changes: 8 additions & 4 deletions app/views/controllers/images/test_add_image.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ through this page are not saved and no database changes are made.</p>

<%= form_tag({action: :test_upload_image, log_id: @log_entry.id}, {multipart: true}) do %>
<div class="form-group form-inline">
<% label_tag(:upload_image1, :IMAGE.t + " 1:") %> <%= custom_file_field(:upload, :image1) %><br/>
<% label_tag(:upload_image2, :IMAGE.t + " 2:") %> <%= custom_file_field(:upload, :image2) %><br/>
<% label_tag(:upload_image3, :IMAGE.t + " 3:") %> <%= custom_file_field(:upload, :image3) %><br/>
<% label_tag(:upload_image4, :IMAGE.t + " 4:") %> <%= custom_file_field(:upload, :image4) %><br/>
<%= fields_for(:upload) do |f_u| %>
<% [1,2,3,4].each do |i| %>
<%= file_field_with_label(
form: f_u, field: "image#{i}".to_sym, class: "mt-3",
label: :image_add_image.t + " #{i}:",
) %>
<% end %>
<% end %>
</div>

<%= submit_tag(:UPLOAD.l, class: "btn btn-default center-block mt-3") %>
Expand Down
4 changes: 2 additions & 2 deletions app/views/controllers/observations/images/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ form_action = { controller: "/observations/images",
<div class="col-xs-12 col-sm-8 col-md-6 col-lg-4">
<%= form_with(model: @image, url: form_action, method: :put) do |f| %>

<%= submit_button(form: f, button: :SAVE_EDITS.l, center: true) %>

<%= render(partial: "observations/images/form/fields_for_images",
locals: { f: f, leave_out_original_file_name: false }) %>

<%= submit_button(form: f, button: :SAVE_EDITS.l, center: true) %>

<% if @projects.any? %>
<div class="form-group form-inline">
<%= content_tag(:p, :PROJECTS.t + ":", class: "font-weight-bold") %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
<div class="form-group form-inline mt-3">
<%= fields_for(:upload) do |f_u| %>
<%= f_u.label(:image1, :image_add_image.t + " 1:") %>
<%= custom_file_field(:upload, :image1) %>
(<%= :image_add_default.t %>)<br/>
<%= f_u.label(:image2, :image_add_image.t + " 2:") %>
<%= custom_file_field(:upload, :image2) %>
(<%= :image_add_optional.t %>)<br/>
<%= f_u.label(:image3, :image_add_image.t + " 3:") %>
<%= custom_file_field(:upload, :image3) %>
(<%= :image_add_optional.t %>)<br/>
<%= f_u.label(:image4, :image_add_image.t + " 4:") %>
<%= custom_file_field(:upload, :image4) %>
(<%= :image_add_optional.t %>)<br/>
<% [1,2,3,4].each do |i| %>
<%= file_field_with_label(
form: f_u, field: "image#{i}".to_sym, class: "mt-3",
label: :image_add_image.t + " #{i}:",
) %>
<% end %>
<% end %>
</div>
4 changes: 2 additions & 2 deletions app/views/controllers/observations/images/new.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ add_tab_set(observation_images_new_tabs(obs: @observation))

<div id="license-notice mt-3"><%= :image_add_warning.tp %></div>

<%= submit_button(form: f, button: :image_add_upload.l, center: true) %>

<%= render(partial: "observations/images/form/fields_for_upload") %>

<%= submit_button(form: f, button: :image_add_upload.l, center: true) %>

<%= render(partial: "observations/images/form/fields_for_images",
locals: { f: f, leave_out_original_file_name: true }) %>

Expand Down
4 changes: 4 additions & 0 deletions app/views/controllers/observations/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@ add_page_title(show_obs_title(obs: @observation, owner_naming: @owner_naming))
add_owner_naming(@owner_naming)
add_pager_for(@observation)
add_interest_icons(@user, @observation)
content_for(:edit_icons) do
tag.span(obs_change_links(@observation),
class: "h4 ml-3 d-inline-block text-nowrap")
end
# add_tab_set(show_observation_tabs(obs: @observation, user: @user))

@container = :double
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,6 @@ def test_show_observation_edit_links
get(:show, params: { id: obs.id })
assert_select("a:match('href',?)", edit_observation_path(obs.id), count: 0)
assert_select(".destroy_observation_link_#{obs.id}", count: 0)
assert_select("a:match('href',?)",
new_image_for_observation_path(obs.id), count: 0)
assert_select("a:match('href',?)",
remove_images_from_observation_path(obs.id), count: 0)
assert_select("a:match('href',?)",
reuse_images_for_observation_path(obs.id), count: 0)
get(:edit, params: { id: obs.id })
Expand All @@ -314,10 +310,6 @@ def test_show_observation_edit_links
assert_select("a[href=?]", edit_observation_path(obs.id), minimum: 1)
# Destroy button is in a form, not a link_to
assert_select(".destroy_observation_link_#{obs.id}", minimum: 1)
assert_select("a[href=?]",
new_image_for_observation_path(obs.id), minimum: 1)
assert_select("a[href=?]",
remove_images_from_observation_path(obs.id), minimum: 1)
assert_select("a[href=?]",
reuse_images_for_observation_path(obs.id), minimum: 1)
get(:edit, params: { id: obs.id })
Expand All @@ -328,10 +320,6 @@ def test_show_observation_edit_links
assert_select("a[href=?]", edit_observation_path(obs.id), minimum: 1)
# Destroy button is in a form, not a link_to
assert_select(".destroy_observation_link_#{obs.id}", minimum: 1)
assert_select("a[href=?]",
new_image_for_observation_path(obs.id), minimum: 1)
assert_select("a[href=?]",
remove_images_from_observation_path(obs.id), minimum: 1)
assert_select("a[href=?]",
reuse_images_for_observation_path(obs.id), minimum: 1)
get(:edit, params: { id: obs.id })
Expand Down

0 comments on commit 42bdf78

Please sign in to comment.