diff --git a/app/assets/javascripts/forms.js.coffee b/app/assets/javascripts/forms.js.coffee new file mode 100644 index 0000000000..4fcc11b1d5 --- /dev/null +++ b/app/assets/javascripts/forms.js.coffee @@ -0,0 +1,22 @@ +# forms.js.coffee +# A temporary place to include form-related javascripts + +# A page can not have more than one form with required data +bind_required_fields_and_submit = () -> + $("form input.required_for_submit").change -> + empty = false + $("form input.required_for_submit").each -> + empty = true if $(this).val() is "" + return + + if empty + $("#submit_with_required").attr "disabled", "disabled" + else + $("#submit_with_required").removeAttr "disabled" + return + return + +$(document).on 'ready page:load', -> + bind_required_fields_and_submit(); +return + diff --git a/app/controllers/asserted_distributions_controller.rb b/app/controllers/asserted_distributions_controller.rb index e4b5803e4c..24f48a4183 100644 --- a/app/controllers/asserted_distributions_controller.rb +++ b/app/controllers/asserted_distributions_controller.rb @@ -83,6 +83,17 @@ def autocomplete render :json => data end + + def search + if params[:id] + redirect_to asserted_distribution_path(params[:id]) + else + redirect_to asserted_distributions_path, notice: 'You must select an item from the list with a click or tab press before clicking show.' + end + end + + + private # Use callbacks to share common setup or constraints between actions. def set_asserted_distribution diff --git a/app/controllers/taxon_determinations_controller.rb b/app/controllers/taxon_determinations_controller.rb index 17628495db..9e3e7ef76f 100644 --- a/app/controllers/taxon_determinations_controller.rb +++ b/app/controllers/taxon_determinations_controller.rb @@ -6,9 +6,15 @@ class TaxonDeterminationsController < ApplicationController # GET /taxon_determinations # GET /taxon_determinations.json def index - @taxon_determinations = TaxonDetermination.all + @recent_objects = TaxonDetermination.recent_from_project_id($project_id).order(updated_at: :desc).limit(10) end + def list + @taxon_determinations = TaxonDetermination.with_project_id($project_id).order(:id).page(params[:page]) #.per(10) #.per(3) + end + + + # GET /taxon_determinations/1 # GET /taxon_determinations/1.json def show diff --git a/app/helpers/taxon_determinations_helper.rb b/app/helpers/taxon_determinations_helper.rb index 4907df9585..31320e392e 100644 --- a/app/helpers/taxon_determinations_helper.rb +++ b/app/helpers/taxon_determinations_helper.rb @@ -1,2 +1,8 @@ module TaxonDeterminationsHelper + + def taxon_determination_tag(taxon_determination) + return nil if taxon_determination.nil? + "foo" + #otu_tag(taxon_determination.otu) + " for " + object_tag(taxon_determination.biological_collection_object.metamorphosize) + end end diff --git a/app/models/collection_object/biological_collection_object.rb b/app/models/collection_object/biological_collection_object.rb index 0b0e2cf635..45f9a5e31a 100644 --- a/app/models/collection_object/biological_collection_object.rb +++ b/app/models/collection_object/biological_collection_object.rb @@ -1,7 +1,7 @@ class CollectionObject::BiologicalCollectionObject < CollectionObject has_many :biocuration_classes, through: :biocuration_classifications, inverse_of: :biological_collection_objects has_many :biocuration_classifications, inverse_of: :biological_collection_object - has_many :otus, through: :taxon_determinations + has_many :otus, through: :taxon_determinations, inverse_of: :taxon_determinations has_many :taxon_determinations, inverse_of: :biological_collection_object accepts_nested_attributes_for :biocuration_classes, :biocuration_classifications, :taxon_determinations, :otus diff --git a/app/models/otu.rb b/app/models/otu.rb index 8421a49592..6d559e0704 100644 --- a/app/models/otu.rb +++ b/app/models/otu.rb @@ -23,7 +23,7 @@ class Otu < ActiveRecord::Base has_many :otu_contents, inverse_of: :otu, dependent: :destroy has_many :taxon_determinations, inverse_of: :otu, dependent: :destroy - has_many :collection_objects, through: :taxon_determinations, source: :biological_collection_object + has_many :collection_objects, through: :taxon_determinations, source: :biological_collection_object, inverse_of: :otus has_many :collection_profiles # @proceps dependent: what? has_many :topics, through: :otu_contents, source: :topic diff --git a/app/models/taxon_determination.rb b/app/models/taxon_determination.rb index 3bc3bbc5a5..8c0e849359 100644 --- a/app/models/taxon_determination.rb +++ b/app/models/taxon_determination.rb @@ -37,27 +37,34 @@ class TaxonDetermination < ActiveRecord::Base # TODO: factor these out (see also TaxonDetermination, Source::Bibtex) validates_numericality_of :year_made, - only_integer: true, greater_than: 0, + only_integer: true, + greater_than: 0, less_than_or_equal_to: Time.now.year, allow_nil: true, - message: 'year made must be an integer greater than 0' + message: ' must be a 4 digit integer greater than 0' validates_inclusion_of :month_made, in: 1..12, allow_nil: true, - message: ' month made' + message: ' is not an integer from 1-12' validates_numericality_of :day_made, + unless: 'year_made.nil? || month_made.nil? || ![*(1..12)].include?(month_made)', allow_nil: true, only_integer: true, greater_than: 0, + less_than: 32, less_than_or_equal_to: Proc.new { |a| Time.utc(a.year_made, a.month_made).end_of_month.day }, - :unless => 'year_made.nil? || month_made.nil?', - message: '%{value} is not a valid day_made for the month provided' + message: '%{value} is not valid for the month provided' + + validates :otu, presence: true + validates :biological_collection_object, presence: true + + before_save :set_made_fields_if_not_provided def sort_date Utilities::Dates.nomenclature_date(day_made, month_made, year_made) end - before_save :set_made_fields_if_not_provided + protected diff --git a/app/views/asserted_distributions/_form.html.erb b/app/views/asserted_distributions/_form.html.erb index 4b52f77f3a..41b93441b5 100644 --- a/app/views/asserted_distributions/_form.html.erb +++ b/app/views/asserted_distributions/_form.html.erb @@ -16,7 +16,6 @@
+ Otu: + <%= otu_link(@taxon_determination.otu) %> +
+ ++ Biological collection object: + <%= collection_object_link(@taxon_determination.biological_collection_object.metamorphosize) %> +
+ ++ Year made: + <%= @taxon_determination.year_made %> +
+ ++ Month made: + <%= @taxon_determination.month_made %> +
+ ++ Day made: + <%= @taxon_determination.day_made %> +
+ ++ Position: + <%= @taxon_determination.position %> +
+Biological collection object | -Otu | -Position | -Year made | -Month made | -Day made | -Created by | -Updated by | -Project | -- | - | - |
---|---|---|---|---|---|---|---|---|---|---|---|
<%= taxon_determination.biological_collection_object_id %> | -<%= taxon_determination.otu_id %> | -<%= taxon_determination.position %> | -<%= taxon_determination.year_made %> | -<%= taxon_determination.month_made %> | -<%= taxon_determination.day_made %> | -<%= taxon_determination.created_by_id %> | -<%= taxon_determination.updated_by_id %> | -<%= taxon_determination.project_id %> | -<%= link_to 'Show', taxon_determination %> | -<%= link_to 'Edit', edit_taxon_determination_path(taxon_determination) %> | -<%= link_to 'Destroy', taxon_determination, method: :delete, data: { confirm: 'Are you sure?' } %> | -
<%= notice %>
- -- Biological collection object: - <%= @taxon_determination.biological_collection_object_id %> -
- -- Otu: - <%= @taxon_determination.otu_id %> -
- -- Position: - <%= @taxon_determination.position %> -
- -- Year made: - <%= @taxon_determination.year_made %> -
- -- Month made: - <%= @taxon_determination.month_made %> -
- -- Day made: - <%= @taxon_determination.day_made %> -
- -- Created by: - <%= @taxon_determination.created_by_id %> -
- -- Updated by: - <%= @taxon_determination.updated_by_id %> -
- -- Project: - <%= @taxon_determination.project_id %> -
- -<%= link_to 'Edit', edit_taxon_determination_path(@taxon_determination) %> | -<%= link_to 'Back', taxon_determinations_path %> +<%= render(partial: '/shared/data/show', locals: {object: @taxon_determination}) -%> diff --git a/spec/controllers/taxon_determinations_controller_spec.rb b/spec/controllers/taxon_determinations_controller_spec.rb index 16c6f76864..011b9243b7 100644 --- a/spec/controllers/taxon_determinations_controller_spec.rb +++ b/spec/controllers/taxon_determinations_controller_spec.rb @@ -35,10 +35,10 @@ let(:valid_session) { {} } describe "GET index" do - it "assigns all taxon_determinations as @taxon_determinations" do + it "assigns a projects recent taxon_determinations as @recent_objects" do taxon_determination = TaxonDetermination.create! valid_attributes get :index, {}, valid_session - expect(assigns(:taxon_determinations)).to eq([taxon_determination]) + expect(assigns(:recent_objects)).to eq([taxon_determination]) end end