From 63477ee59d4c76c3aba56d4231de7f894d985428 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:38:05 +0000 Subject: [PATCH 1/3] feat: Add contribution links and conditional edit form This commit introduces a series of changes to encourage user contributions for missing crop data. On the crop show page, it adds links for logged-in users to: - Add a description if one is not present. - Add a YouTube video if one is not present. - Add more attributes in the predictions section if any are missing. On the crop edit page, the form now conditionally displays fields. For standard users, it only shows fields for attributes that are currently empty. For privileged users (wranglers), it displays all fields, allowing them to edit existing data. --- app/views/crops/_form.html.haml | 63 +++++++++++++++----------- app/views/crops/_info.haml | 3 ++ app/views/crops/_predictions.html.haml | 4 ++ app/views/crops/show.html.haml | 3 ++ 4 files changed, 46 insertions(+), 27 deletions(-) diff --git a/app/views/crops/_form.html.haml b/app/views/crops/_form.html.haml index 85b723d91..a6d9ce80c 100644 --- a/app/views/crops/_form.html.haml +++ b/app/views/crops/_form.html.haml @@ -42,36 +42,45 @@ %span.help-block Living more than two years %h2 Data - = f.text_area :description, label: 'Description' - - if @crop.parent - %span.help-block Parent: #{@crop.parent.description} - = f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0 - - if @crop.parent - %span.help-block Parent: #{@crop.parent.row_spacing} - = f.number_field :spread, label: 'Spread (cm)', min: 0 - - if @crop.parent - %span.help-block Parent: #{@crop.parent.spread} - = f.number_field :height, label: 'Height (cm)', min: 0 - - if @crop.parent - %span.help-block Parent: #{@crop.parent.height} - = f.text_field :sowing_method - - if @crop.parent - %span.help-block Parent: #{@crop.parent.sowing_method} - = f.text_field :sun_requirements - - if @crop.parent - %span.help-block Parent: #{@crop.parent.sun_requirements} - = f.number_field :growing_degree_days, min: 0 - - if @crop.parent - %span.help-block Parent: #{@crop.parent.growing_degree_days} + - if @crop.description.blank? || can?(:wrangle, @crop) + = f.text_area :description, label: 'Description' + - if @crop.parent + %span.help-block Parent: #{@crop.parent.description} + - if @crop.row_spacing.blank? || can?(:wrangle, @crop) + = f.number_field :row_spacing, label: 'Row Spacing (cm)', min: 0 + - if @crop.parent + %span.help-block Parent: #{@crop.parent.row_spacing} + - if @crop.spread.blank? || can?(:wrangle, @crop) + = f.number_field :spread, label: 'Spread (cm)', min: 0 + - if @crop.parent + %span.help-block Parent: #{@crop.parent.spread} + - if @crop.height.blank? || can?(:wrangle, @crop) + = f.number_field :height, label: 'Height (cm)', min: 0 + - if @crop.parent + %span.help-block Parent: #{@crop.parent.height} + - if @crop.sowing_method.blank? || can?(:wrangle, @crop) + = f.text_field :sowing_method + - if @crop.parent + %span.help-block Parent: #{@crop.parent.sowing_method} + - if @crop.sun_requirements.blank? || can?(:wrangle, @crop) + = f.text_field :sun_requirements + - if @crop.parent + %span.help-block Parent: #{@crop.parent.sun_requirements} + - if @crop.growing_degree_days.blank? || can?(:wrangle, @crop) + = f.number_field :growing_degree_days, min: 0 + - if @crop.parent + %span.help-block Parent: #{@crop.parent.growing_degree_days} - unless @crop.approved? = link_to 'Search wikipedia', "https://en.wikipedia.org/w/index.php?search=#{@crop.name}", target: '_blank' - = f.url_field :en_wikipedia_url, id: "en_wikipedia_url", label: 'Wikipedia URL' - %span.help-block - Link to the crop's page on the English language Wikipedia (required). - = f.url_field :en_youtube_url, label: 'YouTube URL' - %span.help-block - Link to a YouTube video about the crop in English. + - if @crop.en_wikipedia_url.blank? || can?(:wrangle, @crop) + = f.url_field :en_wikipedia_url, id: "en_wikipedia_url", label: 'Wikipedia URL' + %span.help-block + Link to the crop's page on the English language Wikipedia (required). + - if @crop.en_youtube_url.blank? || can?(:wrangle, @crop) + = f.url_field :en_youtube_url, label: 'YouTube URL' + %span.help-block + Link to a YouTube video about the crop in English. -# Only crop wranglers see the crop hierarchy (for now) - if can? :wrangle, @crop diff --git a/app/views/crops/_info.haml b/app/views/crops/_info.haml index 34745169b..990076f11 100644 --- a/app/views/crops/_info.haml +++ b/app/views/crops/_info.haml @@ -23,6 +23,9 @@ Nobody is growing this yet. You could be the first! - if crop_or_parent(@crop, :description).present? %p= simple_format crop_or_parent(@crop, :description) + - else + - if member_signed_in? + %p= link_to "Add a description.", edit_crop_path(@crop) .col-md-3 = image_tag crop_image_path(@crop), class: 'img-responsive shadow rounded crop-hero-photo', alt: "Image of #{@crop.name}" diff --git a/app/views/crops/_predictions.html.haml b/app/views/crops/_predictions.html.haml index 5d58ad2fb..2ad5902ae 100644 --- a/app/views/crops/_predictions.html.haml +++ b/app/views/crops/_predictions.html.haml @@ -54,3 +54,7 @@ - if crop.growing_degree_days.present? = render 'layouts/fact_card', title: 'Growing Degree Days', value: crop.growing_degree_days, description: nil + - if member_signed_in? && (!crop.height.present? || !crop.spread.present? || !crop.row_spacing.present? || !crop.growing_degree_days.present?) + .card.fact-card + .card-body.text-center + %p= link_to "Add more attributes.", edit_crop_path(@crop) diff --git a/app/views/crops/show.html.haml b/app/views/crops/show.html.haml index d8aa68d71..4b20ea7ef 100644 --- a/app/views/crops/show.html.haml +++ b/app/views/crops/show.html.haml @@ -37,6 +37,9 @@ %h2 Video .embed-responsive.embed-responsive-16by9 %iframe.embed-responsive-item{ src: "https://www.youtube.com/embed/#{youtube_video_id(crop_or_parent(@crop, :en_youtube_url))}", allowfullscreen: true } + - else + - if member_signed_in? + %p= link_to "Submit a video.", edit_crop_path(@crop) %section.photos = cute_icon 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 2/3] 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 From e8dbcb0916c0974eded6593779ae68f7231c7800 Mon Sep 17 00:00:00 2001 From: Daniel O'Connor Date: Sun, 30 Nov 2025 13:24:42 +1030 Subject: [PATCH 3/3] Delete db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb --- .../20251129185029_add_wikidata_id_to_scientific_names.rb | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb diff --git a/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb b/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb deleted file mode 100644 index aa6651124..000000000 --- a/db/migrate/20251129185029_add_wikidata_id_to_scientific_names.rb +++ /dev/null @@ -1,7 +0,0 @@ -# frozen_string_literal: true - -class AddWikidataIdToScientificNames < ActiveRecord::Migration[6.1] - def change - add_column :scientific_names, :wikidata_id, :string - end -end