mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-26 01:33:22 +00:00
Clean up tag rule form component template
Consolidate everything in one template and move visibility options to the component.
This commit is contained in:
@@ -24,29 +24,36 @@ class TagRuleFormComponent < ViewComponent::Base
|
||||
text_top: t('components.tag_rule_form.tag_rules.shipping_method_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.shipping_method_tagged_bottom'),
|
||||
taggable: "shipping_method",
|
||||
visibility_field: "shipping_methods",
|
||||
visibility_field: "preferred_matched_shipping_methods_visibility",
|
||||
}
|
||||
when "TagRule::FilterPaymentMethods"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.payment_method_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.payment_method_tagged_bottom'),
|
||||
taggable: "payment_method",
|
||||
visibility_field: "payment_methods",
|
||||
visibility_field: "preferred_matched_payment_methods_visibility",
|
||||
}
|
||||
when "TagRule::FilterOrderCycles"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.order_cycle_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.order_cycle_tagged_bottom'),
|
||||
taggable: "exchange",
|
||||
visibility_field: "order_cycles",
|
||||
visibility_field: "preferred_matched_order_cycles_visibility",
|
||||
}
|
||||
when "TagRule::FilterProducts"
|
||||
{
|
||||
text_top: t('components.tag_rule_form.tag_rules.inventory_tagged_top'),
|
||||
text_bottom: t('components.tag_rule_form.tag_rules.inventory_tagged_bottom'),
|
||||
taggable: "variant",
|
||||
visibility_field: "variants",
|
||||
visibility_field: "preferred_matched_variants_visibility",
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def visibility_options
|
||||
[
|
||||
[t('components.tag_rule_form.tag_rules.visible'), "visible"],
|
||||
[t('components.tag_rule_form.tag_rules.not_visible'), "hidden"]
|
||||
]
|
||||
end
|
||||
end
|
||||
|
||||
@@ -26,5 +26,10 @@
|
||||
= rule_data[:text_bottom]
|
||||
%td
|
||||
%div
|
||||
= render partial: "admin/tag_rules/filter_input" , locals: { rule: rule, index: index, field_name: rule_data[:visibility_field] }
|
||||
|
||||
%div
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][#{rule_data[:visibility_field]}]", "hidden"
|
||||
%span.text-normal
|
||||
= t(:not_visible)
|
||||
- else
|
||||
= select_tag "enterprise[tag_rules_attributes][#{index}][#{rule_data[:visibility_field]}]", options_for_select(visibility_options, rule.public_send(rule_data[:visibility_field].to_sym) ), { "data-controller": "tom-select", class: "primary no-search" }
|
||||
|
||||
@@ -50,10 +50,6 @@ module Admin
|
||||
@object.build_custom_tab if @object.custom_tab.nil?
|
||||
|
||||
load_tag_rule_types
|
||||
# TODO translation
|
||||
@visibility_options = [
|
||||
[t('js.tag_rules.visible'), "visible"], [t('js.tag_rules.not_visible'), "hidden"]
|
||||
]
|
||||
|
||||
return unless params[:stimulus]
|
||||
|
||||
|
||||
@@ -9,9 +9,7 @@ module Admin
|
||||
@div_id = params[:div_id]
|
||||
is_default = params[:is_default]
|
||||
@customer_tags = params[:customer_tags]
|
||||
# TODO translation
|
||||
@visibility_options = [[t('js.tag_rules.visible'), "visible"],
|
||||
[t('js.tag_rules.not_visible'), "hidden"]]
|
||||
|
||||
status = :ok
|
||||
if permitted_tag_rule_type.include?(params[:rule_type])
|
||||
@default_rule = "TagRule::#{params[:rule_type]}".constantize.new(is_default:)
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
%div
|
||||
- visibility_field_name = "preferred_matched_#{field_name}_visibility"
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", "hidden"
|
||||
%span.text-normal
|
||||
= t(:not_visible)
|
||||
- else
|
||||
= select_tag "enterprise[tag_rules_attributes][#{index}][#{visibility_field_name}]", options_for_select(@visibility_options, rule.public_send(visibility_field_name.to_sym) ), { "data-controller": "tom-select", class: "primary no-search" }
|
||||
@@ -3796,9 +3796,6 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
some_trouble: "I had some trouble saving: %{errors}"
|
||||
changing_on_hand_stock: Changing on hand stock levels...
|
||||
stock_reset: Stocks reset to defaults.
|
||||
tag_rules:
|
||||
visible: VISIBLE
|
||||
not_visible: NOT VISIBLE
|
||||
services:
|
||||
unsaved_changes_message: Unsaved changes currently exist, save now or ignore?
|
||||
save: SAVE
|
||||
@@ -5073,6 +5070,8 @@ See the %{link} to find out more about %{sitename}'s features and to start using
|
||||
order_cycle_tagged_bottom: "are:"
|
||||
inventory_tagged_top: "Inventory variants tagged"
|
||||
inventory_tagged_bottom: "are:"
|
||||
visible: VISIBLE
|
||||
not_visible: NOT VISIBLE
|
||||
tag_rule_group_form:
|
||||
for_customers_tagged: 'For customers tagged:'
|
||||
add_new_rule: '+ Add A New Rule'
|
||||
|
||||
Reference in New Issue
Block a user