Skip to content

Commit

Permalink
Renamed Herbarium model to Collection
Browse files Browse the repository at this point in the history
  • Loading branch information
SarahW91 committed Aug 5, 2022
1 parent e02c2a1 commit 0ba0caf
Show file tree
Hide file tree
Showing 37 changed files with 143 additions and 134 deletions.
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,7 @@ GEM
webrick (~> 1.7.0)

PLATFORMS
ruby
x86_64-linux

DEPENDENCIES
Expand Down
6 changes: 3 additions & 3 deletions app/assets/javascripts/datatable_initialisation.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ jQuery(function() {
"order": [ 2, 'desc' ]
} );

//HERBARIA
$('#herbaria').DataTable( {
//COLLECTIONS
$('#collections').DataTable( {
bProcessing: true,
bServerSide: true,
sAjaxSource: $('#herbaria').data('source'),
sAjaxSource: $('#collections').data('source'),
"columnDefs": [
{ "orderable": false, "targets": 3 }
],
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/selects_with_select2.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ jQuery(function() {

// INDIVIDUALS
$('#individual_taxon_id').select2((select2AutocompleteOptions("/taxa/filter", "a taxon")));
$('#individual_herbarium_id').select2(select2SingleSelectOptions('an herbarium'));
$('#individual_collection_id').select2(select2SingleSelectOptions('a collection'));
$('#individual_tissue_id').select2(select2SingleSelectOptions('a tissue type'));
$('#individual_project_ids').select2(select2MultiselectOptions);

// INDIVIDUAL SEARCHES
$('#individual_search_specimen_id').select2((select2AutocompleteOptions("/individuals/filter?name_only=1", "a specimen")));
$('#individual_search_herbarium').select2(select2SingleSelectOptions('an herbarium'));
$('#individual_search_collection').select2(select2SingleSelectOptions('a collection'));
$('#individual_search_taxon').select2((select2AutocompleteOptions("/taxa/filter?name_only=1", "a taxon")));

// ISOLATES
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,80 +20,80 @@
# along with BarKeeper. If not, see <http://www.gnu.org/licenses/>.
#

class HerbariaController < ApplicationController
class CollectionsController < ApplicationController
load_and_authorize_resource

before_action :set_herbarium, only: [:show, :edit, :update, :destroy]
before_action :set_collection, only: [:show, :edit, :update, :destroy]

# GET /herbaria
# GET /herbaria.json
# GET /collections
# GET /collections.json
def index
respond_to do |format|
format.html
format.json { render json: HerbariumDatatable.new(view_context) }
format.json { render json: CollectionDatatable.new(view_context) }
end
end

# GET /herbaria/1
# GET /herbaria/1.json
# GET /collections/1
# GET /collections/1.json
def show;end

# GET /herbaria/new
# GET /collections/new
def new
@herbarium = Herbarium.new
@collection = Collection.new
end

# GET /herbaria/1/edit
# GET /collections/1/edit
def edit;end

# POST /herbaria
# POST /herbaria.json
# POST /collections
# POST /collections.json
def create
@herbarium = Herbarium.new(herbarium_params)
@collection = Collection.new(collection_params)

respond_to do |format|
if @herbarium.save
format.html { redirect_to @herbarium, notice: 'Herbarium was successfully created.' }
format.json { render :show, status: :created, location: @herbarium }
if @collection.save
format.html { redirect_to @collection, notice: 'Collection was successfully created.' }
format.json { render :show, status: :created, location: @collection }
else
format.html { render :new }
format.json { render json: @herbarium.errors, status: :unprocessable_entity }
format.json { render json: @collection.errors, status: :unprocessable_entity }
end
end
end

# PATCH/PUT /herbaria/1
# PATCH/PUT /herbaria/1.json
# PATCH/PUT /collections/1
# PATCH/PUT /collections/1.json
def update
respond_to do |format|
if @herbarium.update(herbarium_params)
format.html { redirect_to @herbarium, notice: 'Herbarium was successfully updated.' }
format.json { render :show, status: :ok, location: @herbarium }
if @collection.update(collection_params)
format.html { redirect_to @collection, notice: 'Collection was successfully updated.' }
format.json { render :show, status: :ok, location: @collection }
else
format.html { render :edit }
format.json { render json: @herbarium.errors, status: :unprocessable_entity }
format.json { render json: @collection.errors, status: :unprocessable_entity }
end
end
end

# DELETE /herbaria/1
# DELETE /herbaria/1.json
# DELETE /collections/1
# DELETE /collections/1.json
def destroy
@herbarium.destroy
@collection.destroy
respond_to do |format|
format.html { redirect_to herbaria_url, notice: 'Herbarium was successfully destroyed.' }
format.html { redirect_to collections_url, notice: 'Collection was successfully destroyed.' }
format.json { head :no_content }
end
end

private
# Use callbacks to share common setup or constraints between actions.
def set_herbarium
@herbarium = Herbarium.find(params[:id])
def set_collection
@collection = Collection.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def herbarium_params
params.require(:herbarium).permit(:name, :acronym)
def collection_params
params.require(:collection).permit(:name, :acronym)
end
end
2 changes: 1 addition & 1 deletion app/controllers/individual_searches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,6 @@ def set_individual_search
# Never trust parameters from the scary internet, only allow the white list through.
def individual_search_params
params.require(:individual_search).permit(:title, :DNA_bank_id, :has_issue, :has_problematic_location,
:has_taxon, :taxon, :specimen_id, :herbarium)
:has_taxon, :taxon, :specimen_id, :collection)
end
end
2 changes: 1 addition & 1 deletion app/controllers/individuals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ def set_individual
# Never trust parameters from the scary internet, only allow the white list through.
def individual_params
params.require(:individual).permit(:specimen_id, :DNA_bank_id, :collector, :specimen_id, :herbarium_code,
:herbarium_id, :country, :state_province, :locality, :latitude, :longitude,
:collection_id, :country, :state_province, :locality, :latitude, :longitude,
:latitude_original, :longitude_original, :elevation, :exposition, :habitat,
:substrate, :life_form, :collectors_field_number, :collected, :determination,
:revision, :confirmation, :comments, :taxon_id, :taxon_name, :tissue_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# frozen_string_literal: true

class HerbariumDatatable
class CollectionDatatable
include Rails.application.routes.url_helpers
delegate :url_helpers, to: 'Rails.application.routes'

Expand All @@ -35,43 +35,43 @@ def initialize(view)
def as_json(_options = {})
{
sEcho: params[:sEcho].to_i,
iTotalRecords: Herbarium.count,
iTotalDisplayRecords: herbaria.total_entries,
iTotalRecords: Collection.count,
iTotalDisplayRecords: collections.total_entries,
aaData: data
}
end

private

def data
herbaria.map do |herbarium|
collections.map do |collection|
name = ''

name = link_to herbarium.name, edit_herbarium_path(herbarium) if herbarium.name
name = link_to collection.name, edit_collection_path(collection) if collection.name

[
name,
herbarium.acronym,
herbarium.updated_at.in_time_zone('CET').strftime('%Y-%m-%d %H:%M:%S'),
link_to('Delete', herbarium, method: :delete, data: { confirm: 'Are you sure?' })
collection.acronym,
collection.updated_at.in_time_zone('CET').strftime('%Y-%m-%d %H:%M:%S'),
link_to('Delete', collection, method: :delete, data: { confirm: 'Are you sure?' })
]
end
end

def herbaria
@herbaria ||= fetch_herbaria
def collections
@collections ||= fetch_collections
end

def fetch_herbaria
herbaria = Herbarium.all.order("#{sort_column} #{sort_direction}")
def fetch_collections
collections = Collection.all.order("#{sort_column} #{sort_direction}")

herbaria = herbaria.page(page).per_page(per_page)
collections = collections.page(page).per_page(per_page)

if params[:sSearch].present?
herbaria = herbaria.where('herbaria.name ILIKE :search OR herbaria.acronym ILIKE :search', search: "%#{params[:sSearch]}%")
collections = collections.where('collections.name ILIKE :search OR collections.acronym ILIKE :search', search: "%#{params[:sSearch]}%")
end

herbaria
collections
end

def page
Expand All @@ -83,7 +83,7 @@ def per_page
end

def sort_column
columns = %w[herbaria.name herbaria.acronym herbaria.updated_at]
columns = %w[collections.name collections.acronym collections.updated_at]
columns[params[:iSortCol_0].to_i]
end

Expand Down
12 changes: 6 additions & 6 deletions app/datatables/individual_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ def data
taxon = ''

taxon = link_to individual.taxon.scientific_name, edit_taxon_path(individual.taxon) if individual.taxon
herbarium = link_to individual.herbarium.acronym, edit_herbarium_path(individual.herbarium) if individual.herbarium
collection = link_to individual.collection.acronym, edit_collection_path(individual.collection) if individual.collection

[
link_to(individual.specimen_id, edit_individual_path(individual)),
taxon,
herbarium,
collection,
individual.collector,
individual.collectors_field_number,
individual.updated_at.in_time_zone('CET').strftime('%Y-%m-%d %H:%M:%S'),
Expand All @@ -72,17 +72,17 @@ def individuals

def fetch_individuals
if @taxon_id
individuals = Individual.includes(:taxon, :herbarium).where(taxon_id: @taxon_id).in_project(@current_default_project).order("#{sort_column} #{sort_direction}")
individuals = Individual.includes(:taxon, :collection).where(taxon_id: @taxon_id).in_project(@current_default_project).order("#{sort_column} #{sort_direction}")
else
individuals = Individual.includes(:taxon, :herbarium).in_project(@current_default_project).order("#{sort_column} #{sort_direction}")
individuals = Individual.includes(:taxon, :collection).in_project(@current_default_project).order("#{sort_column} #{sort_direction}")
end

individuals = individuals.page(page).per_page(per_page)

if params[:sSearch].present?
individuals = individuals.where('individuals.specimen_id ILIKE :search
OR taxa.scientific_name ILIKE :search
OR herbaria.acronym ILIKE :search
OR collections.acronym ILIKE :search
OR individuals.collector ILIKE :search
OR individuals.collectors_field_number ILIKE :search', search: "%#{params[:sSearch]}%")
.references(:taxon)
Expand All @@ -100,7 +100,7 @@ def per_page
end

def sort_column
columns = %w[individuals.specimen_id taxa.scientific_name herbaria.acronym individuals.collector individuals.collectors_field_number individuals.updated_at]
columns = %w[individuals.specimen_id taxa.scientific_name collections.acronym individuals.collector individuals.collectors_field_number individuals.updated_at]
columns[params[:iSortCol_0].to_i]
end

Expand Down
10 changes: 5 additions & 5 deletions app/datatables/individual_search_result_datatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,12 +54,12 @@ def data
taxon_id = individual.taxon.id
end

herbarium = link_to individual.herbarium.acronym, edit_herbarium_path(individual.herbarium) if individual.herbarium
collection = link_to individual.collection.acronym, edit_collection_path(individual.collection) if individual.collection

[
link_to(individual.specimen_id, edit_individual_path(individual)),
link_to(taxon_name, edit_taxon_path(taxon_id)),
herbarium,
collection,
individual.latitude_original,
individual.longitude_original,
individual.updated_at.in_time_zone('CET').strftime('%Y-%m-%d %H:%M:%S'),
Expand All @@ -69,14 +69,14 @@ def data
end

def individuals_data
@search_result ||= IndividualSearch.find_by_id(@search_id).individuals.includes(:taxon, :herbarium).reorder("#{sort_column} #{sort_direction}")
@search_result ||= IndividualSearch.find_by_id(@search_id).individuals.includes(:taxon, :collection).reorder("#{sort_column} #{sort_direction}")

@search_result = @search_result.page(page).per_page(per_page)

if params[:sSearch].present?
@search_result = @search_result.where('individuals.specimen_id ILIKE :search
OR taxa.scientific_name ILIKE :search
OR herbaria.acronym ILIKE :search', search: "%#{params[:sSearch]}%")
OR collections.acronym ILIKE :search', search: "%#{params[:sSearch]}%")
.references(:taxon)
end

Expand All @@ -92,7 +92,7 @@ def per_page
end

def sort_column
columns = %w[individuals.specimen_id taxa.scientific_name herbaria.acronym individuals.latitude_original individuals.longitude_original individuals.updated_at]
columns = %w[individuals.specimen_id taxa.scientific_name collections.acronym individuals.latitude_original individuals.longitude_original individuals.updated_at]
columns[params[:iSortCol_0].to_i]
end

Expand Down
2 changes: 1 addition & 1 deletion app/models/ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def initialize(user)

can %i[edit index filter taxonomy_tree associated_specimen find_ancestry show_individuals show_children], Taxon
can %i[edit index filter locality], Individual
can %i[edit index], Herbarium
can %i[edit index], Collection

can %i[edit index filter change_via_script as_fasq], Contig
can %i[edit index filter show_clusters], Isolate
Expand Down
2 changes: 1 addition & 1 deletion app/models/herbarium.rb → app/models/collection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
# along with BarKeeper. If not, see <http://www.gnu.org/licenses/>.
#

class Herbarium < ApplicationRecord
class Collection < ApplicationRecord
include PgSearch::Model

validates_presence_of :acronym
Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/import.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def query_dna_bank(id, data_source = 'dna_bank')
results[:genus] = unit.at_xpath('//abcd21:GenusOrMonomial')&.content&.strip
results[:species_epithet] = unit.at_xpath('//abcd21:FirstEpithet')&.content&.strip
results[:infraspecific] = unit.at_xpath('//abcd21:InfraspecificEpithet')&.content&.strip
results[:herbarium] = unit.at_xpath('//abcd21:SourceInstitutionCode')&.content&.strip
results[:collection] = unit.at_xpath('//abcd21:SourceInstitutionCode')&.content&.strip
results[:collector] = unit.at_xpath('//abcd21:GatheringAgent')&.content&.strip
results[:locality] = unit.at_xpath('//abcd21:LocalityText')&.content&.strip
results[:longitude] = unit.at_xpath('//abcd21:LongitudeDecimal')&.content&.strip
Expand Down
10 changes: 5 additions & 5 deletions app/models/individual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Individual < ApplicationRecord

has_many :isolates
belongs_to :taxon
belongs_to :herbarium
belongs_to :collection
belongs_to :tissue

has_many_attached :voucher_images
Expand All @@ -53,7 +53,7 @@ class Individual < ApplicationRecord
scope :bad_location, -> { bad_latitude.or(Individual.bad_longitude) }

def self.to_csv(project_id)
header = %w{ Database_ID specimen_id taxon_name determination herbarium collectors_field_number collector collection_date
header = %w{ Database_ID specimen_id taxon_name determination collection collectors_field_number collector collection_date
state_province country latitude longitude elevation exposition locality habitat comments }

attributes = %w{ id specimen_id taxon_name determination herbarium_code collectors_field_number collector collected
Expand Down Expand Up @@ -111,9 +111,9 @@ def read_abcd_results(abcd_results)
self.latitude_original = abcd_results[:latitude] if abcd_results[:latitude]
self.longitude_original = abcd_results[:longitude] if abcd_results[:longitude]

if abcd_results[:herbarium]
herbarium = Herbarium.find_or_create_by(acronym: abcd_results[:herbarium])
self.herbarium = herbarium
if abcd_results[:collection]
collection = Collection.find_or_create_by(acronym: abcd_results[:collection])
self.collection = collection
end

if abcd_results[:higher_taxon_name] && abcd_results[:higher_taxon_rank]
Expand Down
Loading

0 comments on commit 0ba0caf

Please sign in to comment.