mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Adding FilterProducts rules to tag rule UI
This commit is contained in:
@@ -26,6 +26,9 @@ angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, ente
|
||||
when "FilterShippingMethods"
|
||||
newRule.peferred_shipping_method_tags = []
|
||||
newRule.preferred_matched_shipping_methods_visibility = "visible"
|
||||
when "FilterProducts"
|
||||
newRule.peferred_variant_tags = []
|
||||
newRule.preferred_matched_variants_visibility = "visible"
|
||||
tagGroup.rules.push(newRule)
|
||||
updateRuleCounts()
|
||||
|
||||
|
||||
@@ -7,10 +7,11 @@ angular.module("admin.tagRules").directive 'newTagRuleDialog', ($compile, $templ
|
||||
|
||||
scope.ruleTypes = [
|
||||
# { id: "DiscountOrder", name: 'Apply a discount to orders' }
|
||||
{ id: "FilterShippingMethods", name: 'Show/Hide shipping methods' }
|
||||
{ id: "FilterProducts", name: 'Show or Hide variants in my shopfront' }
|
||||
{ id: "FilterShippingMethods", name: 'Show or Hide shipping methods at checkout' }
|
||||
]
|
||||
|
||||
scope.ruleType = "DiscountOrder"
|
||||
scope.ruleType = scope.ruleTypes[0].id
|
||||
|
||||
# Set Dialog options
|
||||
template.dialog
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
angular.module("admin.tagRules").directive "filterProducts", ->
|
||||
restrict: "E"
|
||||
replace: true
|
||||
templateUrl: "admin/tag_rules/filter_products.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::FilterProducts" }
|
||||
|
||||
%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_variant_tags",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_variant_tags]",
|
||||
ng: { value: "rule.preferred_customer_tags" } }
|
||||
|
||||
%span.text-normal {{ $index + 1 }}. Variants with matching tags are
|
||||
%input.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_variants_visibility",
|
||||
name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_variants_visibility]",
|
||||
ng: { model: "rule.preferred_matched_variants_visibility"},
|
||||
data: 'visibilityOptions', "min-search" => 5 }
|
||||
-# %tags-with-translation{ object: "rule", "tags-attr" => "shipping_method_tags", "tag-list-attr" => "preferred_shipping_method_tags" }
|
||||
@@ -24,4 +24,12 @@ module Api::Admin::TagRule
|
||||
object.preferred_shipping_method_tags.split(",")
|
||||
end
|
||||
end
|
||||
|
||||
class FilterProductsSerializer < BaseSerializer
|
||||
attributes :preferred_matched_variants_visibility, :variant_tags
|
||||
|
||||
def variant_tags
|
||||
object.preferred_variant_tags.split(",")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
%td
|
||||
%discount-order{ ng: { if: "::rule.type == 'TagRule::DiscountOrder'" } }
|
||||
%filter-shipping-methods{ ng: { if: "::rule.type == 'TagRule::FilterShippingMethods'" } }
|
||||
%filter-products{ ng: { if: "::rule.type == 'TagRule::FilterProducts'" } }
|
||||
%td.actions
|
||||
%a{ ng: { click: "deleteTagRule(tagGroup, rule)" }, :class => "delete-tag-rule icon-trash no-text" }
|
||||
.add_rule.text-center
|
||||
|
||||
@@ -22,13 +22,19 @@ feature 'Tag Rules', js: true do
|
||||
find(:css, "tags-input .tags input").set "volunteer\n"
|
||||
|
||||
# New FilterShippingMethods Rule
|
||||
expect(page).to have_content 'No rules apply to this tag yet'
|
||||
click_button '+ Add A New Rule'
|
||||
select2_select 'Show/Hide shipping methods', from: 'rule_type_selector'
|
||||
select2_select 'Show or Hide shipping methods at checkout', from: 'rule_type_selector'
|
||||
click_button "Add Rule"
|
||||
select2_select "NOT VISIBLE", from: "enterprise_tag_rules_attributes_0_preferred_matched_shipping_methods_visibility"
|
||||
|
||||
# New FilterProducts Rule
|
||||
click_button '+ Add A New Rule'
|
||||
select2_select 'Show or Hide variants in my shop', from: 'rule_type_selector'
|
||||
click_button "Add Rule"
|
||||
select2_select "VISIBLE", from: "enterprise_tag_rules_attributes_1_preferred_matched_variants_visibility"
|
||||
|
||||
# New DiscountOrder Rule
|
||||
# expect(page).to have_content 'No rules apply to this tag yet'
|
||||
# click_button '+ Add A New Rule'
|
||||
# select2_select 'Apply a discount to orders', from: 'rule_type_selector'
|
||||
# click_button "Add Rule"
|
||||
@@ -44,12 +50,18 @@ feature 'Tag Rules', js: true do
|
||||
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_shipping_method_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_matched_shipping_methods_visibility).to eq "hidden"
|
||||
|
||||
tag_rule = TagRule::FilterProducts.last
|
||||
expect(tag_rule.preferred_customer_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_variant_tags).to eq "volunteer"
|
||||
expect(tag_rule.preferred_matched_variants_visibility).to eq "visible"
|
||||
end
|
||||
end
|
||||
|
||||
context "updating" do
|
||||
let!(:do_tag_rule) { create(:tag_rule, enterprise: enterprise, preferred_customer_tags: "member" ) }
|
||||
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" ) }
|
||||
|
||||
before do
|
||||
login_to_admin_section
|
||||
@@ -72,6 +84,10 @@ feature 'Tag Rules', js: true do
|
||||
expect(page).to have_select2 "enterprise_tag_rules_attributes_1_preferred_matched_shipping_methods_visibility", selected: 'NOT VISIBLE'
|
||||
select2_select 'VISIBLE', from: "enterprise_tag_rules_attributes_1_preferred_matched_shipping_methods_visibility"
|
||||
|
||||
# FilterProducts rule
|
||||
expect(page).to have_select2 "enterprise_tag_rules_attributes_2_preferred_matched_variants_visibility", selected: 'VISIBLE'
|
||||
select2_select 'NOT VISIBLE', from: "enterprise_tag_rules_attributes_2_preferred_matched_variants_visibility"
|
||||
|
||||
click_button 'Update'
|
||||
|
||||
# DiscountOrder rule
|
||||
@@ -82,6 +98,11 @@ feature 'Tag Rules', js: true do
|
||||
expect(fsm_tag_rule.preferred_customer_tags).to eq "member,volunteer"
|
||||
expect(fsm_tag_rule.preferred_shipping_method_tags).to eq "member,volunteer"
|
||||
expect(fsm_tag_rule.preferred_matched_shipping_methods_visibility).to eq "visible"
|
||||
|
||||
# FilterProducts rule
|
||||
expect(fp_tag_rule.preferred_customer_tags).to eq "member,volunteer"
|
||||
expect(fp_tag_rule.preferred_variant_tags).to eq "member,volunteer"
|
||||
expect(fp_tag_rule.preferred_matched_variants_visibility).to eq "hidden"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user