mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Create Product component
Update product_component.html.haml
This commit is contained in:
11
app/components/product_component.rb
Normal file
11
app/components/product_component.rb
Normal file
@@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class ProductComponent < ViewComponentReflex::Component
|
||||
def initialize(product:, columns:)
|
||||
@columns = columns
|
||||
@image = product.images[0] if product.images.any?
|
||||
@name = product.name
|
||||
@unit = "#{product.unit_value} #{product.variant_unit}"
|
||||
@price = product.price
|
||||
end
|
||||
end
|
||||
12
app/components/product_component/product_component.html.haml
Normal file
12
app/components/product_component/product_component.html.haml
Normal file
@@ -0,0 +1,12 @@
|
||||
%tr
|
||||
%td.products_column.title
|
||||
- if @image
|
||||
.image
|
||||
= image_tag @image.url(:mini)
|
||||
= @name
|
||||
- if @columns.include?(:unit)
|
||||
%td.products_column.unit
|
||||
= @unit
|
||||
- if @columns.include?(:price)
|
||||
%td.products_column.price
|
||||
= @price
|
||||
@@ -1,14 +0,0 @@
|
||||
%div.product
|
||||
= if product.images[0]
|
||||
%div.image
|
||||
%img{src: product.images[0].attachment.url(:mini, false) }
|
||||
%div.title
|
||||
= product.name
|
||||
%div.unit
|
||||
= product.unit_value
|
||||
= product.variant_unit
|
||||
%div.price
|
||||
= product.price
|
||||
|
||||
%pre
|
||||
= product.to_json
|
||||
@@ -10,4 +10,5 @@
|
||||
Filter results
|
||||
|
||||
#new_products
|
||||
= render partial: "product", collection: @products
|
||||
%table.products_table
|
||||
= render(ProductComponent.with_collection(@products, columns: [:price, :unit]))
|
||||
|
||||
Reference in New Issue
Block a user