mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-10 03:30:22 +00:00
Adding FilterOrderCycles tag rules to UI
This commit is contained in:
@@ -32,6 +32,9 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, ente
|
||||
when "FilterProducts"
|
||||
newRule.peferred_variant_tags = []
|
||||
newRule.preferred_matched_variants_visibility = "visible"
|
||||
when "FilterOrderCycles"
|
||||
newRule.peferred_exchange_tags = []
|
||||
newRule.preferred_matched_order_cycles_visibility = "visible"
|
||||
tagGroup.rules.push(newRule)
|
||||
updateRuleCounts()
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ angular.module("admin.tagRules").directive 'newTagRuleDialog', ($compile, $templ
|
||||
{ id: "FilterProducts", name: 'Show or Hide variants in my shopfront' }
|
||||
{ id: "FilterShippingMethods", name: 'Show or Hide shipping methods at checkout' }
|
||||
{ id: "FilterPaymentMethods", name: 'Show or Hide payment methods at checkout' }
|
||||
{ id: "FilterOrderCycles", name: 'Show or Hide order cycles in my shopfront' }
|
||||
]
|
||||
|
||||
scope.ruleType = scope.ruleTypes[0].id
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
angular.module("admin.tagRules").directive "filterOrderCycles", ->
|
||||
restrict: "E"
|
||||
replace: true
|
||||
templateUrl: "admin/tag_rules/filter_order_cycles.html"
|
||||
@@ -0,0 +1,27 @@
|
||||
%div
|
||||
%input{ type: "hidden",
|
||||
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_id",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][id]",
|
||||
ng: { value: "rule.id" } }
|
||||
|
||||
%input{ type: "hidden",
|
||||
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_type",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][type]",
|
||||
value: "TagRule::FilterOrderCycles" }
|
||||
|
||||
%input{ type: "hidden",
|
||||
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_customer_tags",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_customer_tags]",
|
||||
ng: { value: "rule.preferred_customer_tags" } }
|
||||
|
||||
%input{ type: "hidden",
|
||||
id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_exchange_tags",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_exchange_tags]",
|
||||
ng: { value: "rule.preferred_customer_tags" } }
|
||||
|
||||
%span.text-normal {{ $index + 1 }}. Order Cycles with matching tags are
|
||||
%input.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_order_cycles_visibility",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_order_cycles_visibility]",
|
||||
ng: { model: "rule.preferred_matched_order_cycles_visibility"},
|
||||
data: 'visibilityOptions', "min-search" => 5 }
|
||||
-# %tags-with-translation{ object: "rule", "tags-attr" => "shipping_method_tags", "tag-list-attr" => "preferred_shipping_method_tags" }
|
||||
@@ -40,4 +40,12 @@ module Api::Admin::TagRule
|
||||
object.preferred_variant_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterOrderCyclesSerializer < BaseSerializer
|
||||
attributes :preferred_matched_order_cycles_visibility, :exchange_tags
|
||||
|
||||
def exchange_tags
|
||||
object.preferred_exchange_tags.split(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
%filter-shipping-methods{ ng: { if: "::rule.type == 'TagRule::FilterShippingMethods'" } }
|
||||
%filter-products{ ng: { if: "::rule.type == 'TagRule::FilterProducts'" } }
|
||||
%filter-payment-methods{ ng: { if: "::rule.type == 'TagRule::FilterPaymentMethods'" } }
|
||||
%filter-order_cycles{ ng: { if: "::rule.type == 'TagRule::FilterOrderCycles'" } }
|
||||
%td.actions
|
||||
%a{ ng: { click: "deleteTagRule(tagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" }
|
||||
.add_rule.text-center
|
||||
|
||||
@@ -40,6 +40,12 @@ feature 'Tag Rules', js: true do
|
||||
click_button "Add Rule"
|
||||
select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_2_preferred_matched_payment_methods_visibility"
|
||||
|
||||
# New FilterPaymentMethods Rule
|
||||
click_button '+ Add A New Rule'
|
||||
select2_select 'Show or Hide order cycles in my shopfront', from: 'rule_type_selector'
|
||||
click_button "Add Rule"
|
||||
select2_select "NOT VISIBLE", from: "enterprise_tag_rules_attributes_3_preferred_matched_order_cycles_visibility"
|
||||
|
||||
# New DiscountOrder Rule
|
||||
# click_button '+ Add A New Rule'
|
||||
# select2_select 'Apply a discount to orders', from: 'rule_type_selector'
|
||||
@@ -66,6 +72,11 @@ feature 'Tag Rules', js: true do
|
||||
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_payment_method_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_matched_payment_methods_visibility).to eq "visible"
|
||||
|
||||
tag_rule = TagRule::FilterOrderCycles.last
|
||||
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_exchange_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_matched_order_cycles_visibility).to eq "hidden"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -74,6 +85,7 @@ feature 'Tag Rules', js: true do
|
||||
let!(:fsm_tag_rule) { create(:filter_shipping_methods_tag_rule, enterprise: enterprise, preferred_matched_shipping_methods_visibility: "hidden", preferred_customer_tags: "member" ) }
|
||||
let!(:fp_tag_rule) { create(:filter_products_tag_rule, enterprise: enterprise, preferred_matched_variants_visibility: "visible", preferred_customer_tags: "member" ) }
|
||||
let!(:fpm_tag_rule) { create(:filter_payment_methods_tag_rule, enterprise: enterprise, preferred_matched_payment_methods_visibility: "hidden", preferred_customer_tags: "member" ) }
|
||||
let!(:foc_tag_rule) { create(:filter_order_cycles_tag_rule, enterprise: enterprise, preferred_matched_order_cycles_visibility: "visible", preferred_customer_tags: "member" ) }
|
||||
|
||||
before do
|
||||
login_to_admin_section
|
||||
@@ -104,6 +116,10 @@ feature 'Tag Rules', js: true do
|
||||
expect(page).to have_select2 "enterprise_tag_rules_attributes_3_preferred_matched_payment_methods_visibility", selected: 'NOT VISIBLE'
|
||||
select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_3_preferred_matched_payment_methods_visibility"
|
||||
|
||||
# FilterPaymentMethods rule
|
||||
expect(page).to have_select2 "enterprise_tag_rules_attributes_4_preferred_matched_order_cycles_visibility", selected: 'VISIBLE'
|
||||
select2_select 'NOT VISIBLE', from: "enterprise_tag_rules_attributes_4_preferred_matched_order_cycles_visibility"
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
# DiscountOrder rule
|
||||
@@ -124,6 +140,11 @@ feature 'Tag Rules', js: true do
|
||||
expect(fpm_tag_rule.preferred_customer_tags).to eq "member,volunteer"
|
||||
expect(fpm_tag_rule.preferred_payment_method_tags).to eq "member,volunteer"
|
||||
expect(fpm_tag_rule.preferred_matched_payment_methods_visibility).to eq "visible"
|
||||
|
||||
# FilterPaymentMethods rule
|
||||
expect(foc_tag_rule.preferred_customer_tags).to eq "member,volunteer"
|
||||
expect(foc_tag_rule.preferred_exchange_tags).to eq "member,volunteer"
|
||||
expect(foc_tag_rule.preferred_matched_order_cycles_visibility).to eq "hidden"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user