Skip to content

Commit

Permalink
Show edit form for new images
Browse files Browse the repository at this point in the history
  • Loading branch information
dacook committed May 22, 2024
1 parent 3fcc9ac commit 536b560
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 5 deletions.
2 changes: 2 additions & 0 deletions app/controllers/admin/products_v3_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Admin
class ProductsV3Controller < Spree::Admin::BaseController
helper ProductsHelper

before_action :init_filters_params
before_action :init_pagination_params

Expand Down
5 changes: 4 additions & 1 deletion app/controllers/spree/admin/images_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ def index
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
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/admin/products_helper.rb
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions app/views/admin/products_v3/_product_row.html.haml
Original file line number Diff line number Diff line change
@@ -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')
Expand Down

0 comments on commit 536b560

Please sign in to comment.