diff --git a/app/controllers/observations/namings_controller.rb b/app/controllers/observations/namings_controller.rb index 9a28f5da79..12e4141954 100644 --- a/app/controllers/observations/namings_controller.rb +++ b/app/controllers/observations/namings_controller.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true # Controller for handling the naming of observations -# rubocop:disable Metrics/ClassLength + module Observations - class NamingsController < ApplicationController + class NamingsController < ApplicationController # rubocop:disable Metrics/ClassLength before_action :login_required before_action :pass_query_params @@ -37,7 +37,7 @@ def create save_changes respond_to_successful_create else # If anything failed reload the form. - flash_object_errors(@naming) if name_missing? + flash_naming_errors add_reasons(params.dig(:naming, :reasons)) respond_to_form_errors end @@ -99,6 +99,8 @@ def destroy end end + ######### + private def init_ivars @@ -257,16 +259,22 @@ def respond_to_successful_create end end - def name_missing? - if @name && @what.match(/\S/) - false - else - @naming.errors.add(:name, - :form_observations_there_is_a_problem_with_name.t) - true + def flash_naming_errors + if @what.blank? + flash_error(:form_naming_what_missing.t) + elsif name_missing? + flash_object_errors(@naming) end end + def name_missing? + return false if @name && @what.present? + + @naming.errors. + add(:name, :form_observations_there_is_a_problem_with_name.t) + true + end + def respond_to_form_errors redo_action = case action_name when "create" @@ -308,7 +316,7 @@ def validate_name success = resolve_name(params.dig(:naming, :name).to_s, params[:approved_name], params.dig(:chosen_name, :name_id).to_s) - flash_object_errors(@naming) if name_missing? + flash_naming_errors success end @@ -408,4 +416,3 @@ def destroy_if_we_can(naming) end end end -# rubocop:enable Metrics/ClassLength diff --git a/app/views/controllers/observations/_form.html.erb b/app/views/controllers/observations/_form.html.erb index 6d3a964bfc..9c6586f20e 100644 --- a/app/views/controllers/observations/_form.html.erb +++ b/app/views/controllers/observations/_form.html.erb @@ -44,7 +44,8 @@ image_upload_localization = { action: action, button_name: button_name, show_reasons: false, - unfocused: true + unfocused: true, + name_help: :form_naming_name_help_leave_blank.t } %> <%= render(partial: "observations/namings/fields", locals: naming_locals) %> diff --git a/app/views/controllers/observations/namings/_fields.erb b/app/views/controllers/observations/namings/_fields.erb index 28e4e395e1..7e57de9e0a 100644 --- a/app/views/controllers/observations/namings/_fields.erb +++ b/app/views/controllers/observations/namings/_fields.erb @@ -14,10 +14,10 @@ feedback_locals = { parent_deprecated: @parent_deprecated, names: @names } - confidences = options_for_select(Vote.confidence_menu, @vote&.value) select_opts = { include_blank: ["new", "create"].include?(action_name) } context ||= "blank" +name_help ||= :form_naming_name_help.t %> <%= @@ -40,7 +40,7 @@ context ||= "blank" end, tag.div(class: "col-xs-12 col-sm-6") do help_block_with_arrow("left", id: "naming_name_help") do - tag.p(:form_naming_name_help.t) + tag.p(name_help) end end ].safe_join diff --git a/config/locales/en.txt b/config/locales/en.txt index 86b035f785..faf34d357e 100644 --- a/config/locales/en.txt +++ b/config/locales/en.txt @@ -827,6 +827,7 @@ removed_from_project: Removed [object] from "[project]". select_file: Select file... no_file_selected: No file selected. + SEE_MESSAGE_BELOW: See message below. "YES": "Yes" "NO": "No" "yes": "yes" @@ -1592,8 +1593,10 @@ form_naming_valid_synonyms: Preferred synonyms are form_naming_deprecated: The name '[name]' is deprecated. form_naming_not_recognized: MO does not recognize the name '[name]'. + form_naming_what_missing: "[:WHAT] missing" form_naming_parent_deprecated: The [rank] [parent] is deprecated. - form_naming_name_help: The **scientific name** (without author) that identifies this Observation. **Leave this field blank if you don't know the scientific name.** + form_naming_name_help: The **scientific name** (without author) that identifies this Observation. + form_naming_name_help_leave_blank: The **scientific name** (without author) that identifies this Observation. **Leave this field blank if you don't know the scientific name.** form_naming_deprecated_help: Select a Prefered synonym, enter another Name, or click '[button]' to use '[name]'. form_naming_correct_help: Did you mean one of the following names? [:form_naming_deprecated_help] form_naming_not_recognized_help: "To proceed: Edit the name to be a correctly spelled scientific name\n(or -- if you are creating an Observation -- erase the name).\nThen click '[button]'." @@ -1640,13 +1643,13 @@ form_observations_collection_number_help: Enter the collector's full name and their record identifier. The identifier can be anything. It's whatever you use to keep track of your specimens, and it is typically written on the specimen label. This is most commonly a sequential number starting at 1 for your first specimen, and working up over your life time. Another common format is a year or date along with a collection number for that date, e.g., "17-034". But it can be anything you like, including letters and punctuation. form_observations_herbarium_record_help: If you've sent a specimen to a fungarium, you can enter that here, along with their accession number if you know it. Otherwise let it default to your personal fungarium and leave the accession number blank. - form_observations_there_is_a_problem_with_projects: This observation violates the constraints of one or more selected projects. "+See message below.+":#project_messages + form_observations_there_is_a_problem_with_projects: This observation violates the constraints of one or more selected projects. "+[:SEE_MESSAGE_BELOW]+":#project_messages form_observations_projects_out_of_range: The observation date ([date]) or location ([place_name]) is outside the range of these checked project(s) form_observations_projects_out_of_range_help: "Either:\n- Uncheck out-of-range projects;\n- Change the observation date or location if it is incorrect; or\n- (undesirably) Check [:form_observations_projects_ignore_project_constraints] to ignore the project constraints.\nThen click [button_name]." form_observations_projects_ignore_project_constraints: Ignore Project Constraints - form_observations_there_is_a_problem_with_location: There is a problem with the location. "+See message below.+":#location_messages - form_observations_there_is_a_problem_with_name: There is a problem with the name. "+See message below.+":#name_messages + form_observations_there_is_a_problem_with_location: There is a problem with the location. "+[:SEE_MESSAGE_BELOW]+":#location_messages + form_observations_there_is_a_problem_with_name: There is a problem with the name. "+[:SEE_MESSAGE_BELOW]+":#name_messages # observations/_form_species_list form_species_lists_title: Title diff --git a/test/integration/capybara/namings_integration_test.rb b/test/integration/capybara/namings_integration_test.rb index 111df8296c..f7d3838fd0 100644 --- a/test/integration/capybara/namings_integration_test.rb +++ b/test/integration/capybara/namings_integration_test.rb @@ -46,9 +46,12 @@ def test_proposing_names assert_true(form.has_unchecked_field?("naming_reasons_4_check")) form.first("input[type='submit']").click end + namer_session.assert_selector("body.namings__create") - # (I don't care so long as it says something.) - assert_flash_text(/\S/, session: namer_session) + assert_flash_text(:form_naming_what_missing.l, session: namer_session) + namer_session. + # see https://github.com/MushroomObserver/mushroom-observer/issues/1796 + assert_no_selector("#flash_notices", text: :SEE_MESSAGE_BELOW.l) namer_session.within("#obs_#{obs.id}_naming_form") do |form| form.fill_in("naming_name", with: text_name)