mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-11 23:17:48 +00:00
Refactor tag rule filter input
Consolidated four partials into one
This commit is contained in:
@@ -26,5 +26,5 @@
|
||||
= rule_data[:text_bottom]
|
||||
%td
|
||||
%div
|
||||
= render partial: rule_data[:input_template], locals: { rule: rule, index: index }
|
||||
= render partial: "admin/tag_rules/filter_input" , locals: { rule: rule, index: index, field_name: rule_data[:visibility_field] }
|
||||
|
||||
|
||||
@@ -83,28 +83,28 @@ module Admin
|
||||
text_top: t('js.admin.tag_rules.shipping_method_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.shipping_method_tagged_bottom'),
|
||||
taggable: "shipping_method",
|
||||
input_template: "admin/tag_rules/filter_shipping_methods_input",
|
||||
visibility_field: "shipping_methods",
|
||||
}
|
||||
when "TagRule::FilterPaymentMethods"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.payment_method_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.payment_method_tagged_bottom'),
|
||||
taggable: "payment_method",
|
||||
input_template: "admin/tag_rules/filter_payment_methods_input",
|
||||
visibility_field: "payment_methods",
|
||||
}
|
||||
when "TagRule::FilterOrderCycles"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.order_cycle_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.order_cycle_tagged_bottom'),
|
||||
taggable: "exchange",
|
||||
input_template: "admin/tag_rules/filter_order_cycles_input",
|
||||
visibility_field: "order_cycles",
|
||||
}
|
||||
when "TagRule::FilterProducts"
|
||||
{
|
||||
text_top: t('js.admin.tag_rules.inventory_tagged_top'),
|
||||
text_bottom: t('js.admin.tag_rules.inventory_tagged_bottom'),
|
||||
taggable: "variant",
|
||||
input_template: "admin/tag_rules/filter_products_input",
|
||||
visibility_field: "variants",
|
||||
}
|
||||
end
|
||||
|
||||
|
||||
8
app/views/admin/tag_rules/_filter_input.html.haml
Normal file
8
app/views/admin/tag_rules/_filter_input.html.haml
Normal file
@@ -0,0 +1,8 @@
|
||||
%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" }
|
||||
@@ -1,9 +0,0 @@
|
||||
%div
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_order_cycles_visibility]", "hidden"
|
||||
%span.text-normal
|
||||
=t(:not_visible)
|
||||
- else
|
||||
- #TODO
|
||||
%input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_order_cycles_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_order_cycles_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_order_cycles_visibility", "ng-if": "!rule.is_default" }
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
%div
|
||||
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_payment_methods_visibility]", "hidden"
|
||||
%span.text-normal
|
||||
= t(:not_visible)
|
||||
- else
|
||||
- #TODO
|
||||
%input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_payment_methods_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_payment_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_payment_methods_visibility", "ng-if": "!rule.is_default" }
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
%div
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_variants_visibility]", "hidden"
|
||||
%span.text-normal
|
||||
= t(:not_visible)
|
||||
- else
|
||||
- #TODO
|
||||
%input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_variants_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_variants_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_variants_visibility", "ng-if": "!rule.is_default" }
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
%div
|
||||
- if rule.is_default
|
||||
= hidden_field_tag "enterprise[tag_rules_attributes][#{index}][preferred_matched_shipping_methods_visibility]", "hidden"
|
||||
%span.text-normal
|
||||
= t(:not_visible)
|
||||
- else
|
||||
- #TODO
|
||||
%input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_#{index}_preferred_matched_shipping_methods_visibility", name: "enterprise[tag_rules_attributes][#{index}][preferred_matched_shipping_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_shipping_methods_visibility", "ng-if": "!rule.is_default" }
|
||||
|
||||
Reference in New Issue
Block a user