From 536b5608ab5aa51363b6ef0c5fe12cefcb8e2ccf Mon Sep 17 00:00:00 2001 From: David Cook Date: Wed, 22 May 2024 16:54:41 +1000 Subject: [PATCH] Show edit form for new images --- app/controllers/admin/products_v3_controller.rb | 2 ++ app/controllers/spree/admin/images_controller.rb | 5 ++++- app/helpers/admin/products_helper.rb | 13 +++++++++++++ app/views/admin/products_v3/_product_row.html.haml | 7 +++---- 4 files changed, 22 insertions(+), 5 deletions(-) create mode 100644 app/helpers/admin/products_helper.rb diff --git a/app/controllers/admin/products_v3_controller.rb b/app/controllers/admin/products_v3_controller.rb index f8cdc339c2..77098ee7bb 100644 --- a/app/controllers/admin/products_v3_controller.rb +++ b/app/controllers/admin/products_v3_controller.rb @@ -2,6 +2,8 @@ module Admin class ProductsV3Controller < Spree::Admin::BaseController + helper ProductsHelper + before_action :init_filters_params before_action :init_pagination_params diff --git a/app/controllers/spree/admin/images_controller.rb b/app/controllers/spree/admin/images_controller.rb index 0e0890a229..28ef28bbcb 100644 --- a/app/controllers/spree/admin/images_controller.rb +++ b/app/controllers/spree/admin/images_controller.rb @@ -17,7 +17,10 @@ module Spree def new @url_filters = ::ProductFilters.new.extract(request.query_parameters) - render layout: !request.xhr? + respond_with do |format| + format.turbo_stream { render :edit } + format.all { render layout: !request.xhr? } + end end def edit diff --git a/app/helpers/admin/products_helper.rb b/app/helpers/admin/products_helper.rb new file mode 100644 index 0000000000..e29b378342 --- /dev/null +++ b/app/helpers/admin/products_helper.rb @@ -0,0 +1,13 @@ +# frozen_string_literal: true + +module Admin + module ProductsHelper + def product_image_form_path(product) + if product.image.present? + edit_admin_product_image_path(product.id, product.image.id) + else + new_admin_product_image_path(product.id) + end + end + end +end diff --git a/app/views/admin/products_v3/_product_row.html.haml b/app/views/admin/products_v3/_product_row.html.haml index 5cd0cc8db1..706a3ec7ed 100644 --- a/app/views/admin/products_v3/_product_row.html.haml +++ b/app/views/admin/products_v3/_product_row.html.haml @@ -1,8 +1,7 @@ %td.with-image{ id: "image-#{product.id}" } - - if product.image.present? # todo: handle blank img - %a.image-field{ href: edit_admin_product_image_path(product.id, product.image.id), 'data-turbo-stream': true } - = image_tag product.image&.url(:mini) || Spree::Image.default_image_url(:mini), width: 40, height: 40 - .button.secondary.mini= t('admin.products_page.image.edit') + %a.image-field{ href: product_image_form_path(product), 'data-turbo-stream': true } + = image_tag product.image&.url(:mini) || Spree::Image.default_image_url(:mini), width: 40, height: 40 + .button.secondary.mini= t('admin.products_page.image.edit') %td.field.align-left.header.naked_inputs = f.hidden_field :id = f.text_field :name, 'aria-label': t('admin.products_page.columns.name')