From 5db6a86607b074a7c6f62cba19576eaf403de70d Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Sat, 20 Sep 2025 08:54:12 +0000 Subject: [PATCH] Add ability to copy/duplicate an activity --- app/controllers/activities_controller.rb | 2 ++ app/helpers/buttons_helper.rb | 13 +++++++++++++ app/helpers/icons_helper.rb | 4 ++++ app/views/activities/_actions.haml | 1 + config/locales/en.yml | 1 + 5 files changed, 21 insertions(+) diff --git a/app/controllers/activities_controller.rb b/app/controllers/activities_controller.rb index 3cb447def..3d72ed439 100644 --- a/app/controllers/activities_controller.rb +++ b/app/controllers/activities_controller.rb @@ -33,6 +33,8 @@ class ActivitiesController < DataController due_date: Date.today ) @activity.name = params[:name] if params[:name] + @activity.description = params[:description] if params[:description] + @activity.category = params[:category] if params[:category] @activity.due_date = params[:due_date] if params[:due_date] if params[:garden_id] @activity.garden = Garden.find_by( diff --git a/app/helpers/buttons_helper.rb b/app/helpers/buttons_helper.rb index ac929f711..2d214dea2 100644 --- a/app/helpers/buttons_helper.rb +++ b/app/helpers/buttons_helper.rb @@ -88,6 +88,19 @@ module ButtonsHelper edit_button(edit_activity_path(activity), classes:) end + def activity_copy_button(activity, classes: 'btn') + link_to new_activity_path( + name: activity.name, + description: activity.description, + category: activity.category, + garden_id: activity.garden_id, + planting_id: activity.planting_id, + due_date: activity.due_date + ), class: classes do + copy_icon + ' ' + t('buttons.copy') + end + end + def activity_finish_button(activity, classes: 'btn btn-default btn-secondary') return unless can?(:edit, activity) || activity.finished diff --git a/app/helpers/icons_helper.rb b/app/helpers/icons_helper.rb index 71721ef04..80c118d00 100644 --- a/app/helpers/icons_helper.rb +++ b/app/helpers/icons_helper.rb @@ -59,6 +59,10 @@ module IconsHelper image_icon 'delete' end + def copy_icon + icon('far', 'copy') + end + def add_photo_icon image_icon 'add-photo' end diff --git a/app/views/activities/_actions.haml b/app/views/activities/_actions.haml index 1631b7042..c87a01625 100644 --- a/app/views/activities/_actions.haml +++ b/app/views/activities/_actions.haml @@ -3,6 +3,7 @@ %a#activity-actions-button.btn.btn-info.dropdown-toggle{"aria-expanded" => "false", "aria-haspopup" => "true", "data-bs-toggle" => "dropdown", type: "button", href: '#'} Actions .dropdown-menu.dropdown-menu-xs{"aria-labelledby" => "planting-actions-button"} = activity_edit_button(activity, classes: 'dropdown-item') + = activity_copy_button(activity, classes: 'dropdown-item') - if activity.active = activity_finish_button(activity, classes: 'dropdown-item') .dropdown-divider diff --git a/config/locales/en.yml b/config/locales/en.yml index d0c1adc4d..56680c272 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -72,6 +72,7 @@ en: add: Add add_photo: Add photo add_seed_to_stash: Add %{crop_name} seeds to stash + copy: Copy delete: Delete edit: Edit harvest: Harvest