Skip to content

Commit 5986b43

Browse files
committed
Add country to C14Lab
1 parent d2af392 commit 5986b43

File tree

6 files changed

+54
-25
lines changed

6 files changed

+54
-25
lines changed

app/helpers/application_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,10 @@ def na_value
5757
'<abbr title="Unknown or missing value" class="initialism text-muted">NA</abbr>'.html_safe
5858
end
5959

60+
def na_or(value)
61+
value.blank? ? na_value : value
62+
end
63+
6064
def tick_or_cross(bool)
6165
bool ? bs_icon("check") : bs_icon("x")
6266
end

app/models/c14_lab.rb

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#
33
# Table name: c14_labs
44
#
5-
# id :bigint not null, primary key
6-
# active :boolean
7-
# name :string
8-
# created_at :datetime not null
9-
# updated_at :datetime not null
5+
# id :bigint not null, primary key
6+
# active :boolean
7+
# country_code :string
8+
# name :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
1011
#
1112
# Indexes
1213
#
@@ -25,19 +26,31 @@ class C14Lab < ApplicationRecord
2526

2627
acts_as_copy_target # enable CSV exports
2728

29+
scope :with_c14s_count, -> { select <<~SQL
30+
"c14_labs".*,
31+
(
32+
SELECT COUNT(c14s.id)
33+
FROM c14s
34+
WHERE c14_lab_id = "c14_labs".id
35+
) AS c14s_count
36+
SQL
37+
}
38+
2839
def self.label
2940
"radiocarbon lab"
3041
end
3142

32-
def country
33-
"an unknown land" # TODO
34-
end
35-
3643
def lab_code
3744
# TODO: There can only be one...
3845
c14_lab_codes.select(canonical: true).first.lab_code
3946
end
4047

48+
def country
49+
return nil if country_code.blank?
50+
ISO3166::Country[country_code] ||
51+
ISO3166::Country.find_country_by_any_name(country_code)
52+
end
53+
4154
def c14s_count
4255
c14s.count
4356
end

app/views/c14_labs/show.html.erb

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<% content_for :title, @c14_lab.name %>
22
<% content_for :meta_description do %>
3-
<%= @c14_lab.name %> <%= @c14_lab.active ? "is" : "was" %> a radiocarbon laboratory in <%= @c14_lab.country %>.
3+
<%= @c14_lab.name %> <%= @c14_lab.active ? "is" : "was" %> a radiocarbon laboratory<% unless @c14_lab.country.blank? %> in <%= @c14_lab.country %><% end %>.
44
Its standard abbreviation <%= @c14_lab.active ? "is" : "was" %> '<%= @c14_lab.lab_code %>'<% if @c14_lab.c14_lab_codes.count > 1 %>; variants include <%= @c14_lab.c14_lab_codes.where(canonical: false).pluck(:lab_code).to_sentence %><% end %>.
55
<% unless @c14_lab.active %>It is no longer operating.<% end %>
66
XRONOS includes information on <%= @c14_lab.c14s_count %> <%= "radiocarbon date".pluralize(@c14_lab.c14s_count) %> produced by <%= @c14_lab.name %>.
@@ -28,7 +28,8 @@
2828

2929
<div class="h5">
3030
<%= xr_icon C14, {}, { style: "width: auto; height: 1.25rem;" } %>
31-
Radiocarbon laboratory in <%= @c14_lab.country %>
31+
Radiocarbon laboratory
32+
<% unless @c14_lab.country.blank? %>in <%= @c14_lab.country %><% end %>
3233
</div>
3334

3435
<div class="my-3">
@@ -41,11 +42,11 @@
4142
<h2><%= bs_icon "clipboard" %> Laboratory metadata</h2>
4243
<dl>
4344

44-
<dt>Active</dt>
45+
<dt>Status</dt>
4546
<dd class="font-monospace"><%= @c14_lab.active ? "Active" : "Inactive" %></dd>
4647

4748
<dt>Country</dt>
48-
<dd class="font-monospace"><%= @c14_lab.country %></dd>
49+
<dd class="font-monospace"><%= na_or @c14_lab.country %></dd>
4950

5051
<dt>Canonical laboratory code</dt>
5152
<dd class="font-monospace"><%= @c14_lab.lab_code %></dd>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCountryToC14Lab < ActiveRecord::Migration[7.2]
2+
def change
3+
add_column :c14_labs, :country_code, :string
4+
end
5+
end

db/schema.rb

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#
1111
# It's strongly recommended that you check this file into your version control system.
1212

13-
ActiveRecord::Schema[7.2].define(version: 2025_04_07_124024) do
13+
ActiveRecord::Schema[7.2].define(version: 2025_04_07_150504) do
1414
# These are extensions that must be enabled in order to support this database
1515
enable_extension "pg_trgm"
1616
enable_extension "plpgsql"
@@ -75,6 +75,7 @@
7575
t.boolean "active"
7676
t.datetime "created_at", precision: nil, null: false
7777
t.datetime "updated_at", precision: nil, null: false
78+
t.string "country_code"
7879
t.index ["active"], name: "index_c14_labs_on_active"
7980
t.index ["name"], name: "index_c14_labs_on_name"
8081
end
@@ -212,8 +213,9 @@
212213
end
213214

214215
create_table "periods_site_phases", id: false, force: :cascade do |t|
215-
t.bigint "site_phase_id"
216-
t.bigint "period_id"
216+
t.bigint "site_phase_id", null: false
217+
t.bigint "period_id", null: false
218+
t.index ["site_phase_id", "period_id"], name: "index_spp"
217219
end
218220

219221
create_table "pg_search_documents", force: :cascade do |t|
@@ -225,11 +227,13 @@
225227
t.index ["searchable_type", "searchable_id"], name: "index_pg_search_documents_on_searchable"
226228
end
227229

228-
create_table "physical_locations", id: false, force: :cascade do |t|
230+
create_table "physical_locations", force: :cascade do |t|
229231
t.bigint "site_id"
230232
t.bigint "country_id"
231-
t.text "created_at"
232-
t.text "updated_at"
233+
t.datetime "created_at", precision: nil, null: false
234+
t.datetime "updated_at", precision: nil, null: false
235+
t.index ["country_id"], name: "index_physical_locations_on_country_id"
236+
t.index ["site_id"], name: "index_physical_locations_on_site_id"
233237
end
234238

235239
create_table "references", force: :cascade do |t|
@@ -348,7 +352,8 @@
348352
end
349353

350354
create_table "versions", force: :cascade do |t|
351-
t.string "item_type", null: false
355+
t.string "item_type"
356+
t.string "{:null=>false}"
352357
t.bigint "item_id", null: false
353358
t.string "event", null: false
354359
t.string "whodunnit"

test/factories/c14_labs.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22
#
33
# Table name: c14_labs
44
#
5-
# id :bigint not null, primary key
6-
# active :boolean
7-
# name :string
8-
# created_at :datetime not null
9-
# updated_at :datetime not null
5+
# id :bigint not null, primary key
6+
# active :boolean
7+
# country_code :string
8+
# name :string
9+
# created_at :datetime not null
10+
# updated_at :datetime not null
1011
#
1112
# Indexes
1213
#

0 commit comments

Comments
 (0)