Skip to content

Commit

Permalink
Tunes date checking for taxon determinations. Taxon determinations vi…
Browse files Browse the repository at this point in the history
…ews. Validation for taxon determinations.
  • Loading branch information
mjy committed Nov 10, 2014
1 parent b16593b commit c47d560
Show file tree
Hide file tree
Showing 18 changed files with 119 additions and 127 deletions.
22 changes: 22 additions & 0 deletions app/assets/javascripts/forms.js.coffee
Original file line number Diff line number Diff line change
@@ -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

11 changes: 11 additions & 0 deletions app/controllers/asserted_distributions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion app/controllers/taxon_determinations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions app/helpers/taxon_determinations_helper.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/models/otu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 13 additions & 6 deletions app/models/taxon_determination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 1 addition & 4 deletions app/views/asserted_distributions/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<div class="field">
<%= f.label :otu_id %>
<br>
<br>
<%= render :partial => 'workbench/elements/forms/ajax_select',
:locals => {:controller => 'otus',
:object => 'asserted_distribution',
Expand All @@ -29,7 +28,6 @@
<div class="field">
<%= f.label :geographic_area %>
<br>
<br>
<%= render :partial => 'workbench/elements/forms/ajax_select',
:locals => {:controller => 'geographic_areas',
:object => 'asserted_distribution',
Expand All @@ -41,7 +39,6 @@
<div class="field">
<%= f.label :source_id %>
<br>
<br>
<%= render :partial => 'workbench/elements/forms/ajax_select',
:locals => {:controller => 'sources',
:object => 'asserted_distribution',
Expand All @@ -51,7 +48,7 @@
:size => 20} %>
</div>
</div>
<div class="optional"><
<div class="optional">
<div class="field">
<%= f.label :is_absent %>
<br>
Expand Down
4 changes: 2 additions & 2 deletions app/views/asserted_distributions/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -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: '',
Expand Down
3 changes: 0 additions & 3 deletions app/views/asserted_distributions/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
<h1>Editing asserted_distribution</h1>

<%= render 'form' %>
<%= link_to 'Show', @asserted_distribution %> |
<%= link_to 'Back', asserted_distributions_path %>
2 changes: 1 addition & 1 deletion app/views/citations/_quick_search_form.html.erb
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
2 changes: 1 addition & 1 deletion app/views/shared/data/_index.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<section>
<div class="flexbox">
<div class="item item1 one_tenth_width">
<div class="item item1 one_fifth_width">
<h2><%= model_name_title -%></h2>
<span class="subtle"><%= favorite_page_link -%></span>
</div>
Expand Down
31 changes: 31 additions & 0 deletions app/views/taxon_determinations/_attributes.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<div class="attributes">
<p>
<strong>Otu:</strong>
<%= otu_link(@taxon_determination.otu) %>
</p>

<p>
<strong>Biological collection object:</strong>
<%= collection_object_link(@taxon_determination.biological_collection_object.metamorphosize) %>
</p>

<p>
<strong>Year made:</strong>
<%= @taxon_determination.year_made %>
</p>

<p>
<strong>Month made:</strong>
<%= @taxon_determination.month_made %>
</p>

<p>
<strong>Day made:</strong>
<%= @taxon_determination.day_made %>
</p>

<p>
<strong>Position:</strong>
<%= @taxon_determination.position %>
</p>
</div>
27 changes: 17 additions & 10 deletions app/views/taxon_determinations/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,37 @@

<div class="field">
<%= f.label :biological_collection_object_id %><br>
<%= 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: ''} %>
</div>

<div class="field">
<%= f.label :otu_id %><br>
<%= f.select :otu_id, options_from_collection_for_select(Otu.all, :id, :name) %>
</div>

<div class="field">
<%= f.label :position %><br>
<%= 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: ''} %>
</div>

<div class="field">
<%= f.label :year_made %><br>
<%= f.text_field :year_made %>
<%= f.text_field :year_made, size: 4 %>
</div>
<div class="field">
<%= f.label :month_made %><br>
<%= f.text_field :month_made %>
<%= f.text_field :month_made, size: 2 %>
</div>
<div class="field">
<%= f.label :day_made %><br>
<%= f.text_field :day_made %>
<%= f.text_field :day_made, size: 2 %>
</div>
<div class="actions">
<%= f.submit %>
Expand Down
44 changes: 1 addition & 43 deletions app/views/taxon_determinations/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,43 +1 @@
<h1>Taxon Determinations</h1>

<table>
<thead>
<tr>
<th>Biological collection object</th>
<th>Otu</th>
<th>Position</th>
<th>Year made</th>
<th>Month made</th>
<th>Day made</th>
<th>Created by</th>
<th>Updated by</th>
<th>Project</th>
<th></th>
<th></th>
<th></th>
</tr>
</thead>

<tbody>
<% @taxon_determinations.each do |taxon_determination| %>
<tr>
<td><%= taxon_determination.biological_collection_object_id %></td>
<td><%= taxon_determination.otu_id %></td>
<td><%= taxon_determination.position %></td>
<td><%= taxon_determination.year_made %></td>
<td><%= taxon_determination.month_made %></td>
<td><%= taxon_determination.day_made %></td>
<td><%= taxon_determination.created_by_id %></td>
<td><%= taxon_determination.updated_by_id %></td>
<td><%= taxon_determination.project_id %></td>
<td><%= link_to 'Show', taxon_determination %></td>
<td><%= link_to 'Edit', edit_taxon_determination_path(taxon_determination) %></td>
<td><%= link_to 'Destroy', taxon_determination, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</tbody>
</table>

<br>

<%= link_to 'New Taxon determination', new_taxon_determination_path %>
<%= render '/shared/data/index' %>
4 changes: 1 addition & 3 deletions app/views/taxon_determinations/list.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
<tr>
<th>Biological collection object</th>
<th>Otu</th>
<th>Position</th>
<th>Year made</th>
<th>Month made</th>
<th>Day made</th>
Expand All @@ -22,9 +21,8 @@
<tbody>
<% @taxon_determinations.each do |taxon_determination| %>
<tr>
<td><%= taxon_determination.biological_collection_object_id %></td>
<td><%= object_tag(taxon_determination.biological_collection_object.metamorphosize) %></td>
<td><%= object_tag(taxon_determination.otu) %></td>
<td><%= taxon_determination.position %></td>
<td><%= taxon_determination.year_made %></td>
<td><%= taxon_determination.month_made %></td>
<td><%= taxon_determination.day_made %></td>
Expand Down
50 changes: 1 addition & 49 deletions app/views/taxon_determinations/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,49 +1 @@
<p id="notice"><%= notice %></p>

<p>
<strong>Biological collection object:</strong>
<%= @taxon_determination.biological_collection_object_id %>
</p>

<p>
<strong>Otu:</strong>
<%= @taxon_determination.otu_id %>
</p>

<p>
<strong>Position:</strong>
<%= @taxon_determination.position %>
</p>

<p>
<strong>Year made:</strong>
<%= @taxon_determination.year_made %>
</p>

<p>
<strong>Month made:</strong>
<%= @taxon_determination.month_made %>
</p>

<p>
<strong>Day made:</strong>
<%= @taxon_determination.day_made %>
</p>

<p>
<strong>Created by:</strong>
<%= @taxon_determination.created_by_id %>
</p>

<p>
<strong>Updated by:</strong>
<%= @taxon_determination.updated_by_id %>
</p>

<p>
<strong>Project:</strong>
<%= @taxon_determination.project_id %>
</p>

<%= link_to 'Edit', edit_taxon_determination_path(@taxon_determination) %> |
<%= link_to 'Back', taxon_determinations_path %>
<%= render(partial: '/shared/data/show', locals: {object: @taxon_determination}) -%>
4 changes: 2 additions & 2 deletions spec/controllers/taxon_determinations_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit c47d560

Please sign in to comment.