From 06360eba0c7660ebffcc1dfd193d4e63a0a88f42 Mon Sep 17 00:00:00 2001 From: Joe Roe Date: Thu, 23 Mar 2023 14:02:50 +0100 Subject: [PATCH] Add issues MISSING_MATERIAL and MISSING_CRS --- app/helpers/issues_helper.rb | 6 +++++- app/models/sample.rb | 23 +++++++++++++++++++---- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/app/helpers/issues_helper.rb b/app/helpers/issues_helper.rb index 31657a40..e4366468 100644 --- a/app/helpers/issues_helper.rb +++ b/app/helpers/issues_helper.rb @@ -30,8 +30,12 @@ def issue_description(issue) when :missing_bibtex "No bibliographical information recorded" # Samples + when :missing_material + "Sample material is not recorded" when :missing_taxon - "Taxonomic classification of the sample material is unknown" + "Taxonomic classification of the sample material is not recoreded" + when :missing_crs + "Coordinate reference system (CRS) of sample coordinates is not recorded" # Taxons when :unknown_taxon "Taxon not matched to the GBIF Backbone Taxonomy" diff --git a/app/models/sample.rb b/app/models/sample.rb index 6e8a33cc..3dd98556 100644 --- a/app/models/sample.rb +++ b/app/models/sample.rb @@ -47,14 +47,29 @@ class Sample < ApplicationRecord acts_as_copy_target # enable CSV exports include HasIssues - @issues = [ :missing_taxon ] - + @issues = [ :missing_material, :missing_taxon, :missing_crs ] + + def self.label + "sample" + end + + # Issues + scope :missing_material, -> { where(material_id: nil) } + def missing_material? + material.blank? + end + scope :missing_taxon, -> { where(taxon_id: nil) } def missing_taxon? taxon.blank? end - def self.label - "sample" + scope :missing_crs, -> { where('position_crs IS NULL AND (position_x IS NOT NULL OR position_y IS NOT NULL OR position_z IS NOT NULL)') } + def missing_crs? + if position_x.blank? and position_y.blank? and position_z.blank? + false + else + position_crs.blank? + end end end