diff --git a/Gemfile b/Gemfile index d4eea771b0..08de7290be 100644 --- a/Gemfile +++ b/Gemfile @@ -106,6 +106,8 @@ gem 'sidekiq-scheduler' gem "cable_ready", "5.0.1" gem "stimulus_reflex", "3.5.0.rc3" +gem 'turbo-rails' + gem 'combine_pdf' gem 'wicked_pdf' gem 'wkhtmltopdf-binary' diff --git a/Gemfile.lock b/Gemfile.lock index f4953104fb..7112b9dbfd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -770,6 +770,10 @@ GEM timecop (0.9.8) timeout (0.4.1) ttfunk (1.7.0) + turbo-rails (2.0.5) + actionpack (>= 6.0.0) + activejob (>= 6.0.0) + railties (>= 6.0.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) unicode-display_width (2.5.0) @@ -959,6 +963,7 @@ DEPENDENCIES stringex (~> 2.8.5) stripe timecop + turbo-rails valid_email2 validates_lengths_from_database vcr diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index f8cdc339c2..fa6470d267 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -33,6 +33,14 @@ module Admin "/admin/products?#{params.to_query}" # todo: fix routing so this can be automaticly generated end + def clone + @product = Spree::Product.find(params[:id]) + @cloned_product = @product.duplicate + raise "Clone failed" unless @cloned_product.save + + respond_to(&:turbo_stream) + end + private def init_filters_params diff --git a/app/views/admin/products_v3/_product_row.html.haml b/app/views/admin/products_v3/_product_row.html.haml index f82ef26933..60bd64ab59 100644 --- a/app/views/admin/products_v3/_product_row.html.haml +++ b/app/views/admin/products_v3/_product_row.html.haml @@ -42,7 +42,7 @@ %td.align-right = render(VerticalEllipsisMenu::Component.new) do = link_to t('admin.products_page.actions.edit'), edit_admin_product_path(product), 'data-turbo': false - = link_to t('admin.products_page.actions.clone'), clone_admin_product_path(product), 'data-turbo': false + = link_to t('admin.products_page.actions.clone'), admin_clone_product_path(product), method: :post, 'data-turbo-stream': true %a{ "data-controller": "modal-link", "data-action": "click->modal-link#setModalDataSetOnConfirm click->modal-link#open", "data-modal-link-target-value": "product-delete-modal", "class": "delete", "data-modal-link-modal-dataset-value": {'data-current-id': product.id}.to_json } diff --git a/app/views/admin/products_v3/clone.turbo_stream.haml b/app/views/admin/products_v3/clone.turbo_stream.haml new file mode 100644 index 0000000000..252eb8fd72 --- /dev/null +++ b/app/views/admin/products_v3/clone.turbo_stream.haml @@ -0,0 +1,2 @@ += turbo_stream.replace "products-content" do + %h1= "This is a test." \ No newline at end of file diff --git a/config/routes/admin.rb b/config/routes/admin.rb index 1a7ca8c3cc..8239fcf695 100644 --- a/config/routes/admin.rb +++ b/config/routes/admin.rb @@ -73,6 +73,7 @@ Openfoodnetwork::Application.routes.draw do # This might be easier to arrange once we rename the controller to plain old "products" post '/products/bulk_update', to: 'products_v3#bulk_update' get '/products', to: 'products_v3#index' + post 'products/:id/clone', to: 'products_v3#clone', as: 'clone_product' end resources :variant_overrides do