mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Add producer and category to a product in the table
+ refactor and automatize optional column rendered
This commit is contained in:
@@ -2,10 +2,28 @@
|
||||
|
||||
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
|
||||
super
|
||||
@product = product
|
||||
@image = @product.images[0] if product.images.any?
|
||||
@name = @product.name
|
||||
@columns = columns.map { |c|
|
||||
{
|
||||
id: c,
|
||||
value: column_value(c)
|
||||
}
|
||||
}
|
||||
end
|
||||
|
||||
def column_value(column)
|
||||
case column
|
||||
when 'price'
|
||||
@product.price
|
||||
when 'unit'
|
||||
"#{@product.unit_value} #{@product.variant_unit}"
|
||||
when 'producer'
|
||||
@product.supplier.name
|
||||
when 'category'
|
||||
@product.taxons.map(&:name).join(', ')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -4,9 +4,6 @@
|
||||
.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
|
||||
- @columns.each do |column|
|
||||
%td.products_column{class: column[:id]}
|
||||
= column[:value]
|
||||
|
||||
@@ -7,7 +7,11 @@ class ProductsTableComponent < ViewComponentReflex::Component
|
||||
super
|
||||
@user = user
|
||||
@columns = [{ label: I18n.t("admin.products_page.columns_selector.price"), value: "price" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.unit"), value: "unit" }]
|
||||
{ label: I18n.t("admin.products_page.columns_selector.unit"), value: "unit" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.producer"),
|
||||
value: "producer" },
|
||||
{ label: I18n.t("admin.products_page.columns_selector.category"),
|
||||
value: "category" }].sort { |a, b| a[:label] <=> b[:label] }
|
||||
@columns_selected = ["price", "unit"]
|
||||
@per_page = [{ label: "10", value: 10 }, { label: "25", value: 25 }, { label: "50", value: 50 },
|
||||
{ label: "100", value: 100 }]
|
||||
|
||||
@@ -462,6 +462,8 @@ en:
|
||||
columns_selector:
|
||||
unit: Unit
|
||||
price: Price
|
||||
producer: Producer
|
||||
category: Category
|
||||
adjustments:
|
||||
skipped_changing_canceled_order: "You can't change a cancelled order."
|
||||
# Common properties / models
|
||||
|
||||
Reference in New Issue
Block a user