mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-18 13:38:24 -04:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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'
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user