feat: Add Wikidata ID to scientific names

This commit introduces the ability to store and display the Wikidata ID for scientific names.

Changes include:
- A database migration to add the `wikidata_id` column to the `scientific_names` table.
- An update to the `scientific_names_controller` to permit the `wikidata_id` parameter.
- An update to the scientific name form to include a field for the Wikidata ID.
- An update to the crop show page to display a link to the Wikidata page for a scientific name.
This commit is contained in:
google-labs-jules[bot]
2025-11-30 02:53:19 +00:00
parent b27e263fdf
commit d31a6ec221
4 changed files with 33 additions and 19 deletions

View File

@@ -74,7 +74,7 @@ class ScientificNamesController < ApplicationController
end
def scientific_name_params
params.require(:scientific_name).permit(:crop_id, :name, :gbif_key)
params.require(:scientific_name).permit(:crop_id, :name, :gbif_key, :wikidata_id)
end
def gbif_service

View File

@@ -4,25 +4,28 @@
%p None known.
- else
- crop.scientific_names.each do |sn|
- if can? :edit, sn
.dropdown.planting-actions
%a#planting-actions-scinames.dropdown-toggle.card-link{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", :type => "button", :href => '#'}= sn.name
.dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "planting-actions-button"}
= link_to edit_scientific_name_path(sn), class: 'dropdown-item' do
= edit_icon
= t('.edit')
.dropdown-divider
= link_to sn, method: :delete, data: { confirm: 'Are you sure?' }, class: 'dropdown-item text-danger' do
= delete_icon
= t('.delete')
- else
- if sn.gbif_key
= link_to sn.name, "https://www.gbif.org/species/#{sn.gbif_key}",
class: 'card-link',
target: "_blank",
rel: "noopener noreferrer"
.d-inline-block
- if can? :edit, sn
.dropdown.planting-actions.d-inline-block
%a#planting-actions-scinames.dropdown-toggle.card-link{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", :type => "button", :href => '#'}= sn.name
.dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "planting-actions-button"}
= link_to edit_scientific_name_path(sn), class: 'dropdown-item' do
= edit_icon
= t('.edit')
.dropdown-divider
= link_to sn, method: :delete, data: { confirm: 'Are you sure?' }, class: 'dropdown-item text-danger' do
= delete_icon
= t('.delete')
- else
.badge= sn.name
- if sn.gbif_key
= link_to sn.name, "https://www.gbif.org/species/#{sn.gbif_key}",
class: 'card-link',
target: "_blank",
rel: "noopener noreferrer"
- else
.badge= sn.name
- if sn.wikidata_id.present?
= link_to "WD", "https://www.wikidata.org/wiki/#{sn.wikidata_id}", class: 'badge badge-info ms-1', target: '_blank', rel: 'noopener noreferrer', title: 'Wikidata'
%p.text-right
- if can? :edit, crop

View File

@@ -24,6 +24,10 @@
= f.label :name, class: 'control-label col-md-2'
.col-md-8
= f.text_field :name, class: 'form-control'
.form-group
= f.label :wikidata_id, "Wikidata ID", class: 'control-label col-md-2'
.col-md-8
= f.text_field :wikidata_id, class: 'form-control'
.form-group
.form-actions.col-md-offset-2.col-md-8
= f.submit 'Save', class: 'btn btn-primary'

View File

@@ -0,0 +1,7 @@
# frozen_string_literal: true
class AddWikidataIdToScientificNames < ActiveRecord::Migration[6.1]
def change
add_column :scientific_names, :wikidata_id, :string
end
end