From d31a6ec221ee7c0c9fc0eb9e53fd02da620b2838 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sun, 30 Nov 2025 02:53:19 +0000 Subject: [PATCH] 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. --- .../scientific_names_controller.rb | 2 +- app/views/crops/_scientific_names.html.haml | 39 ++++++++++--------- app/views/scientific_names/_form.html.haml | 4 ++ ...029_add_wikidata_id_to_scientific_names.rb | 7 ++++ 4 files changed, 33 insertions(+), 19 deletions(-) create mode 100644 db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb diff --git a/app/controllers/scientific_names_controller.rb b/app/controllers/scientific_names_controller.rb index 972e06f90..d815de94a 100644 --- a/app/controllers/scientific_names_controller.rb +++ b/app/controllers/scientific_names_controller.rb @@ -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 diff --git a/app/views/crops/_scientific_names.html.haml b/app/views/crops/_scientific_names.html.haml index a55dc967f..65ac87e38 100644 --- a/app/views/crops/_scientific_names.html.haml +++ b/app/views/crops/_scientific_names.html.haml @@ -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 diff --git a/app/views/scientific_names/_form.html.haml b/app/views/scientific_names/_form.html.haml index f10849497..a62de8f34 100644 --- a/app/views/scientific_names/_form.html.haml +++ b/app/views/scientific_names/_form.html.haml @@ -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' diff --git a/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb b/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb new file mode 100644 index 000000000..aa6651124 --- /dev/null +++ b/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb @@ -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