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 @@
<%= f.label :otu_id %>
-
<%= render :partial => 'workbench/elements/forms/ajax_select', :locals => {:controller => 'otus', :object => 'asserted_distribution', @@ -29,7 +28,6 @@
<%= f.label :geographic_area %>
-
<%= render :partial => 'workbench/elements/forms/ajax_select', :locals => {:controller => 'geographic_areas', :object => 'asserted_distribution', @@ -41,7 +39,6 @@
<%= f.label :source_id %>
-
<%= render :partial => 'workbench/elements/forms/ajax_select', :locals => {:controller => 'sources', :object => 'asserted_distribution', @@ -51,7 +48,7 @@ :size => 20} %>
-
< +
<%= f.label :is_absent %>
diff --git a/app/views/asserted_distributions/_quick_search_form.html.erb b/app/views/asserted_distributions/_quick_search_form.html.erb index 90023bee45..a29356ad56 100644 --- a/app/views/asserted_distributions/_quick_search_form.html.erb +++ b/app/views/asserted_distributions/_quick_search_form.html.erb @@ -1,7 +1,7 @@ -<%= form_tag(search_collecting_events_path) do %> +<%= form_tag(search_asserted_distributions_path, {method: :get}) do %> <%= render partial: 'workbench/elements/forms/ajax_select', locals: {controller: 'asserted_distributions', - object: 'asserted_distribution', + object: nil, method: 'id', tag_id: 'asserted_distribution_id_for_quick_search_form', size: '', diff --git a/app/views/asserted_distributions/edit.html.erb b/app/views/asserted_distributions/edit.html.erb index 9d273a41aa..ff5bd82e8f 100644 --- a/app/views/asserted_distributions/edit.html.erb +++ b/app/views/asserted_distributions/edit.html.erb @@ -1,6 +1,3 @@

Editing asserted_distribution

<%= render 'form' %> - -<%= link_to 'Show', @asserted_distribution %> | -<%= link_to 'Back', asserted_distributions_path %> diff --git a/app/views/citations/_quick_search_form.html.erb b/app/views/citations/_quick_search_form.html.erb index 9adc1bcd18..84d78dcdbe 100644 --- a/app/views/citations/_quick_search_form.html.erb +++ b/app/views/citations/_quick_search_form.html.erb @@ -1,4 +1,4 @@ -<%= form_tag(search_citations_path) do %> +<%= form_tag(search_citations_path, {method: :get}) do %> <%= render partial: 'workbench/elements/forms/ajax_select', locals: {controller: 'citations', object: nil, diff --git a/app/views/shared/data/_index.html.erb b/app/views/shared/data/_index.html.erb index a7c80d9d8e..59d976f6dc 100644 --- a/app/views/shared/data/_index.html.erb +++ b/app/views/shared/data/_index.html.erb @@ -1,6 +1,6 @@
-
+

<%= model_name_title -%>

<%= favorite_page_link -%>
diff --git a/app/views/taxon_determinations/_attributes.html.erb b/app/views/taxon_determinations/_attributes.html.erb new file mode 100644 index 0000000000..5e53753b25 --- /dev/null +++ b/app/views/taxon_determinations/_attributes.html.erb @@ -0,0 +1,31 @@ +
+

+ 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 %> +

+
diff --git a/app/views/taxon_determinations/_form.html.erb b/app/views/taxon_determinations/_form.html.erb index 903d24f7cb..6f60478032 100644 --- a/app/views/taxon_determinations/_form.html.erb +++ b/app/views/taxon_determinations/_form.html.erb @@ -13,30 +13,37 @@
<%= f.label :biological_collection_object_id %>
- <%= f.select :biological_collection_object_id, options_from_collection_for_select(CollectionObject.all, :id, :id) %> + <%= render partial: 'workbench/elements/forms/ajax_select', + locals: {controller: 'collection_objects', + object: 'taxon_determination', + method: 'biological_collection_object_id', + tag_id: 'biological_collection_object_id_for_taxon_determination', + size: '', + display: ''} %>
<%= f.label :otu_id %>
- <%= f.select :otu_id, options_from_collection_for_select(Otu.all, :id, :name) %> -
- -
- <%= f.label :position %>
- <%= f.number_field :position %> + <%= render partial: 'workbench/elements/forms/ajax_select', + locals: {controller: 'otus', + object: 'taxon_determination', + method: 'otu_id', + tag_id: 'otu_id_for_taxon_determination', + size: '', + display: ''} %>
<%= f.label :year_made %>
- <%= f.text_field :year_made %> + <%= f.text_field :year_made, size: 4 %>
<%= f.label :month_made %>
- <%= f.text_field :month_made %> + <%= f.text_field :month_made, size: 2 %>
<%= f.label :day_made %>
- <%= f.text_field :day_made %> + <%= f.text_field :day_made, size: 2 %>
<%= f.submit %> diff --git a/app/views/taxon_determinations/index.html.erb b/app/views/taxon_determinations/index.html.erb index 1f321757b5..cca441bc6e 100644 --- a/app/views/taxon_determinations/index.html.erb +++ b/app/views/taxon_determinations/index.html.erb @@ -1,43 +1 @@ -

Taxon Determinations

- - - - - - - - - - - - - - - - - - - - - <% @taxon_determinations.each do |taxon_determination| %> - - - - - - - - - - - - - - - <% end %> - -
Biological collection objectOtuPositionYear madeMonth madeDay madeCreated byUpdated byProject
<%= 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?' } %>
- -
- -<%= link_to 'New Taxon determination', new_taxon_determination_path %> +<%= render '/shared/data/index' %> diff --git a/app/views/taxon_determinations/list.html.erb b/app/views/taxon_determinations/list.html.erb index de2dc67de8..f20fc0fee7 100644 --- a/app/views/taxon_determinations/list.html.erb +++ b/app/views/taxon_determinations/list.html.erb @@ -7,7 +7,6 @@ Biological collection object Otu - Position Year made Month made Day made @@ -22,9 +21,8 @@ <% @taxon_determinations.each do |taxon_determination| %> - <%= taxon_determination.biological_collection_object_id %> + <%= object_tag(taxon_determination.biological_collection_object.metamorphosize) %> <%= object_tag(taxon_determination.otu) %> - <%= taxon_determination.position %> <%= taxon_determination.year_made %> <%= taxon_determination.month_made %> <%= taxon_determination.day_made %> diff --git a/app/views/taxon_determinations/show.html.erb b/app/views/taxon_determinations/show.html.erb index dc3fde443f..5fd5e23380 100644 --- a/app/views/taxon_determinations/show.html.erb +++ b/app/views/taxon_determinations/show.html.erb @@ -1,49 +1 @@ -

<%= 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