From 9d9f7e8717ac284d308efa9e58bbfaeefadbdb4c Mon Sep 17 00:00:00 2001 From: Gaetan Craig-Riou Date: Fri, 29 Aug 2025 14:18:38 +1000 Subject: [PATCH] Remove Angularjs files related to tag rules --- .../admin/enterprises/enterprises.js.coffee | 1 - .../tag_rules_controller.js.coffee | 58 ------------- .../directives/invert_number.js.coffee | 11 --- .../directives/new_rule_dialog.js.coffee | 26 ------ .../directives/tag_rules/tag_rule.js.coffee | 41 ---------- .../admin/new_tag_rule_dialog.html.haml | 10 --- .../tag_rules/discount_order_input.html.haml | 3 - .../filter_order_cycles_input.html.haml | 5 -- .../filter_payment_methods_input.html.haml | 5 -- .../tag_rules/filter_products_input.html.haml | 5 -- .../filter_shipping_methods_input.html.haml | 6 -- .../admin/tag_rules/tag_rule.html.haml | 32 -------- .../tag_rules_controller_spec.js.coffee | 81 ------------------- 13 files changed, 284 deletions(-) delete mode 100644 app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee delete mode 100644 app/assets/javascripts/admin/tag_rules/directives/invert_number.js.coffee delete mode 100644 app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee delete mode 100644 app/assets/javascripts/admin/tag_rules/directives/tag_rules/tag_rule.js.coffee delete mode 100644 app/assets/javascripts/templates/admin/new_tag_rule_dialog.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/discount_order_input.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/filter_order_cycles_input.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/filter_payment_methods_input.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/filter_products_input.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/filter_shipping_methods_input.html.haml delete mode 100644 app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml delete mode 100644 spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee diff --git a/app/assets/javascripts/admin/enterprises/enterprises.js.coffee b/app/assets/javascripts/admin/enterprises/enterprises.js.coffee index 36c43fb440..5e41433805 100644 --- a/app/assets/javascripts/admin/enterprises/enterprises.js.coffee +++ b/app/assets/javascripts/admin/enterprises/enterprises.js.coffee @@ -6,7 +6,6 @@ angular.module("admin.enterprises", [ "admin.side_menu", "admin.taxons", 'admin.indexUtils', - 'admin.tagRules', 'admin.dropdown', 'ngSanitize'] ) diff --git a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee b/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee deleted file mode 100644 index 35a522c74f..0000000000 --- a/app/assets/javascripts/admin/tag_rules/controllers/tag_rules_controller.js.coffee +++ /dev/null @@ -1,58 +0,0 @@ -angular.module("admin.tagRules").controller "TagRulesCtrl", ($scope, $http, $filter, enterprise) -> - $scope.tagGroups = enterprise.tag_groups - $scope.defaultTagGroup = enterprise.default_tag_group - - $scope.visibilityOptions = [ { id: "visible", name: t('js.tag_rules.visible') }, { id: "hidden", name: t('js.tag_rules.not_visible') } ] - - $scope.updateRuleCounts = -> - index = $scope.defaultTagGroup.rules.length - for tagGroup in $filter('orderBy')($scope.tagGroups, 'position') - tagGroup.startIndex = index - index = index + tagGroup.rules.length - - $scope.updateRuleCounts() - - $scope.updateTagsRulesFor = (tagGroup) -> - for tagRule in tagGroup.rules - tagRule.preferred_customer_tags = (tag.text for tag in tagGroup.tags).join(",") - - $scope.addNewRuleTo = (tagGroup, ruleType) -> - newRule = - id: null - is_default: tagGroup == $scope.defaultTagGroup - preferred_customer_tags: (tag.text for tag in tagGroup.tags).join(",") - type: "TagRule::#{ruleType}" - switch ruleType - when "FilterShippingMethods" - newRule.peferred_shipping_method_tags = [] - newRule.preferred_matched_shipping_methods_visibility = "visible" - when "FilterPaymentMethods" - newRule.peferred_payment_method_tags = [] - newRule.preferred_matched_payment_methods_visibility = "visible" - 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) - $scope.updateRuleCounts() - - $scope.addNewTag = -> - $scope.tagGroups.push { tags: [], rules: [], position: $scope.tagGroups.length + 1 } - - $scope.deleteTagRule = (tagGroup, tagRule) -> - index = tagGroup.rules.indexOf(tagRule) - return unless index >= 0 - if tagRule.id is null - tagGroup.rules.splice(index, 1) - $scope.updateRuleCounts() - else - if confirm("Are you sure?") - $http - method: "DELETE" - url: "/admin/enterprises/#{enterprise.id}/tag_rules/#{tagRule.id}.json" - .then -> - tagGroup.rules.splice(index, 1) - $scope.updateRuleCounts() - $scope.enterprise_form.$setDirty() diff --git a/app/assets/javascripts/admin/tag_rules/directives/invert_number.js.coffee b/app/assets/javascripts/admin/tag_rules/directives/invert_number.js.coffee deleted file mode 100644 index 2412eec18c..0000000000 --- a/app/assets/javascripts/admin/tag_rules/directives/invert_number.js.coffee +++ /dev/null @@ -1,11 +0,0 @@ -angular.module("admin.tagRules").directive "invertNumber", -> - restrict: "A" - require: "ngModel" - link: (scope, element, attrs, ngModel) -> - ngModel.$parsers.push (viewValue) -> - return -parseInt(viewValue) unless isNaN(parseInt(viewValue)) - viewValue - - ngModel.$formatters.push (modelValue) -> - return -parseInt(modelValue) unless isNaN(parseInt(modelValue)) - modelValue diff --git a/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee b/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee deleted file mode 100644 index 779404924f..0000000000 --- a/app/assets/javascripts/admin/tag_rules/directives/new_rule_dialog.js.coffee +++ /dev/null @@ -1,26 +0,0 @@ -angular.module("admin.tagRules").directive 'newTagRuleDialog', ($rootScope, $compile, $templateCache, DialogDefaults, ruleTypes) -> - restrict: 'A' - scope: - tagGroup: '=' - addNewRuleTo: '=' - link: (scope, element, attr) -> - # Compile modal template - template = $compile($templateCache.get('admin/new_tag_rule_dialog.html'))(scope) - - scope.ruleTypes = ruleTypes - - scope.ruleType = scope.ruleTypes[0].id - - # Set Dialog options - template.dialog(DialogDefaults) - - # Link opening of dialog to click event on element - element.bind 'click', (e) -> - template.dialog('open') - $rootScope.$evalAsync() - - scope.addRule = (tagGroup, ruleType) -> - scope.addNewRuleTo(tagGroup, ruleType) - template.dialog('close') - $rootScope.$evalAsync() - return diff --git a/app/assets/javascripts/admin/tag_rules/directives/tag_rules/tag_rule.js.coffee b/app/assets/javascripts/admin/tag_rules/directives/tag_rules/tag_rule.js.coffee deleted file mode 100644 index 22746bbafa..0000000000 --- a/app/assets/javascripts/admin/tag_rules/directives/tag_rules/tag_rule.js.coffee +++ /dev/null @@ -1,41 +0,0 @@ -angular.module("admin.tagRules").directive "tagRule", -> - restrict: "C" - templateUrl: "admin/tag_rules/tag_rule.html" - link: (scope, element, attrs) -> - scope.opt = - "TagRule::FilterShippingMethods": - textTop: t('js.admin.tag_rules.shipping_method_tagged_top') - textBottom: t('js.admin.tag_rules.shipping_method_tagged_bottom') - taggable: "shipping_method" - tagsAttr: "shipping_method_tags" - tagListAttr: "preferred_shipping_method_tags" - inputTemplate: "admin/tag_rules/filter_shipping_methods_input.html" - tagListFor: (rule) -> - rule.preferred_shipping_method_tags - "TagRule::FilterPaymentMethods": - textTop: t('js.admin.tag_rules.payment_method_tagged_top') - textBottom: t('js.admin.tag_rules.payment_method_tagged_bottom') - taggable: "payment_method" - tagsAttr: "payment_method_tags" - tagListAttr: "preferred_payment_method_tags" - inputTemplate: "admin/tag_rules/filter_payment_methods_input.html" - tagListFor: (rule) -> - rule.preferred_payment_method_tags - "TagRule::FilterOrderCycles": - textTop: t('js.admin.tag_rules.order_cycle_tagged_top') - textBottom: t('js.admin.tag_rules.order_cycle_tagged_bottom') - taggable: "exchange" - tagsAttr: "exchange_tags" - tagListAttr: "preferred_exchange_tags" - inputTemplate: "admin/tag_rules/filter_order_cycles_input.html" - tagListFor: (rule) -> - rule.preferred_exchange_tags - "TagRule::FilterProducts": - textTop: t('js.admin.tag_rules.inventory_tagged_top') - textBottom: t('js.admin.tag_rules.inventory_tagged_bottom') - taggable: "variant" - tagsAttr: "variant_tags" - tagListAttr: "preferred_variant_tags" - inputTemplate: "admin/tag_rules/filter_products_input.html" - tagListFor: (rule) -> - rule.preferred_variant_tags diff --git a/app/assets/javascripts/templates/admin/new_tag_rule_dialog.html.haml b/app/assets/javascripts/templates/admin/new_tag_rule_dialog.html.haml deleted file mode 100644 index cc43116af1..0000000000 --- a/app/assets/javascripts/templates/admin/new_tag_rule_dialog.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -#new-tag-rule-dialog - .text-normal.margin-bottom-30.text-center - {{ 'js.admin.new_tag_rule_dialog.select_rule_type' | t }} - - .text-center.margin-bottom-30 - -# %select.fullwidth{ 'select2-min-search' => 5, 'ng-model' => 'newRuleType', 'ng-options' => 'ruleType.id as ruleType.name for ruleType in availableRuleTypes' } - %input.ofn-select2.fullwidth{ id: 'rule_type_selector', data: "ruleTypes", "min-search": "5", "ng-model": "ruleType" } - - .text-center - %input.button.red.icon-plus{ type: 'button', value: "{{ 'js.admin.new_tag_rule_dialog.add_rule' | t }}", "ng-click": 'addRule(tagGroup, ruleType)' } diff --git a/app/assets/javascripts/templates/admin/tag_rules/discount_order_input.html.haml b/app/assets/javascripts/templates/admin/tag_rules/discount_order_input.html.haml deleted file mode 100644 index ac087096ad..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/discount_order_input.html.haml +++ /dev/null @@ -1,3 +0,0 @@ -%div - %input{ type: "number", id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_calculator_attributes_preferred_flat_percent", min: -100, max: 100, "invert-number": true, "ng-model": "rule.calculator.preferred_flat_percent" } - %span.text-normal % diff --git a/app/assets/javascripts/templates/admin/tag_rules/filter_order_cycles_input.html.haml b/app/assets/javascripts/templates/admin/tag_rules/filter_order_cycles_input.html.haml deleted file mode 100644 index 43458b40c6..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/filter_order_cycles_input.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%div - %input.fullwidth.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]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_order_cycles_visibility", "ng-if": "!rule.is_default" } - %input{ type: "hidden", 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-value": "'hidden'", "ng-if": "rule.is_default" } - %span.text-normal{ "ng-if": "rule.is_default" } - =t(:not_visible) diff --git a/app/assets/javascripts/templates/admin/tag_rules/filter_payment_methods_input.html.haml b/app/assets/javascripts/templates/admin/tag_rules/filter_payment_methods_input.html.haml deleted file mode 100644 index 013e606987..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/filter_payment_methods_input.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%div - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_payment_methods_visibility", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_payment_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_payment_methods_visibility", "ng-if": "!rule.is_default" } - %input{ type: "hidden", id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_payment_methods_visibility", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_payment_methods_visibility]", "ng-value": "'hidden'", "ng-if": "rule.is_default" } - %span.text-normal{ "ng-if": "rule.is_default" } - = t(:not_visible) diff --git a/app/assets/javascripts/templates/admin/tag_rules/filter_products_input.html.haml b/app/assets/javascripts/templates/admin/tag_rules/filter_products_input.html.haml deleted file mode 100644 index 302b5fb85b..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/filter_products_input.html.haml +++ /dev/null @@ -1,5 +0,0 @@ -%div - %input.fullwidth.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]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_variants_visibility", "ng-if": "!rule.is_default" } - %input{ type: "hidden", 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-value": "'hidden'", "ng-if": "rule.is_default" } - %span.text-normal{ "ng-if": "rule.is_default" } - = t(:not_visible) diff --git a/app/assets/javascripts/templates/admin/tag_rules/filter_shipping_methods_input.html.haml b/app/assets/javascripts/templates/admin/tag_rules/filter_shipping_methods_input.html.haml deleted file mode 100644 index ab6a5aeb80..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/filter_shipping_methods_input.html.haml +++ /dev/null @@ -1,6 +0,0 @@ -%div - %input.fullwidth.light.ofn-select2{ id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_shipping_methods_visibility", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_shipping_methods_visibility]", data: 'visibilityOptions', "min-search": 5, "ng-model": "rule.preferred_matched_shipping_methods_visibility", "ng-if": "!rule.is_default" } - %input{ type: "hidden", id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_preferred_matched_shipping_methods_visibility", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_matched_shipping_methods_visibility]", "ng-value": "'hidden'", "ng-if": "rule.is_default" } - %span.text-normal{ "ng-if": "rule.is_default" } - = t(:not_visible) - diff --git a/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml b/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml deleted file mode 100644 index 598eafe972..0000000000 --- a/app/assets/javascripts/templates/admin/tag_rules/tag_rule.html.haml +++ /dev/null @@ -1,32 +0,0 @@ -%div{ id: "tr_{{tagGroup.startIndex + $index}}" } - %table - %colgroup - %col.text{ width: "35%" } - %col.inputs{ width: "55%" } - %col.actions{ width: "10%" } - %tr - %td - %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]", "ng-value": "rule.type" } - - %input{ type: "hidden", id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_priority", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][priority]", "ng-value": "tagGroup.startIndex + $index" } - - %input{ type: "hidden", id: "enterprise_tag_rules_attributes_{{tagGroup.startIndex + $index}}_is_default", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][is_default]", "ng-value": "rule.is_default" } - - %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_{{opt[rule.type].taggable}}_tags", name: "enterprise[tag_rules_attributes][{{tagGroup.startIndex + $index}}][preferred_{{opt[rule.type].taggable}}_tags]", "ng-value": "opt[rule.type].tagListFor(rule)" } - - %span.text-normal {{ opt[rule.type].textTop }} - %td - %tags-with-translation{ object: "rule", max: 1, "tags-attr" => "{{opt[rule.type].tagsAttr}}", "tag-list-attr" => "{{opt[rule.type].tagListAttr}}" } - %td.actions{ rowspan: 2 } - %a{ class: "delete-tag-rule icon-trash no-text", "ng-click": "deleteTagRule(tagGroup || defaultTagGroup, rule)" } - %tr - %td - %span.text-normal {{ opt[rule.type].textBottom }} - %td - %div{ "ng-include": "opt[rule.type].inputTemplate" } - - %hr diff --git a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee b/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee deleted file mode 100644 index 4758d4222e..0000000000 --- a/spec/javascripts/unit/admin/tag_rules/controllers/tag_rules_controller_spec.js.coffee +++ /dev/null @@ -1,81 +0,0 @@ -describe "TagRulesCtrl", -> - ctrl = null - scope = null - enterprise = null - - beforeEach -> - module('admin.tagRules') - enterprise = - id: 45 - default_tag_group: { tags: "", rules: [{ id: 7, preferred_customer_tags: "trusted" }] } - tag_groups: [ - { tags: "member", rules: [{ id: 1, preferred_customer_tags: "member" }, { id: 2, preferred_customer_tags: "member" }] }, - { tags: "volunteer", rules: [{ id: 3, preferred_customer_tags: "local" }] } - ] - - inject ($rootScope, $controller) -> - scope = $rootScope - scope.enterprise_form = jasmine.createSpyObj('enterprise_form', ['$setDirty']) - ctrl = $controller 'TagRulesCtrl', {$scope: scope, enterprise: enterprise} - - describe "tagGroup start indices", -> - it "updates on initialization", -> - expect(scope.tagGroups[0].startIndex).toEqual 1 - expect(scope.tagGroups[1].startIndex).toEqual 3 - - describe "adding a new tag group", -> - beforeEach -> - scope.addNewRuleTo(scope.tagGroups[0], "FilterOrderCycles") - - it "adds a new rule of the specified type to the rules array for the tagGroup", -> - expect(scope.tagGroups[0].rules.length).toEqual 3 - expect(scope.tagGroups[0].rules[2].type).toEqual "TagRule::FilterOrderCycles" - - it "updates tagGroup start indices", -> - expect(scope.tagGroups[0].startIndex).toEqual 1 - expect(scope.tagGroups[1].startIndex).toEqual 4 - - describe "deleting a tag group", -> - describe "where the rule is not in the rule list for the tagGroup", -> - beforeEach -> - scope.deleteTagRule(scope.tagGroups[0],scope.tagGroups[1].rules[0]) - - it "does not remove any rules", -> - expect(scope.tagGroups[0].rules.length).toEqual 2 - expect(scope.tagGroups[1].rules.length).toEqual 1 - - describe "with an id", -> - rule = null - - beforeEach inject ($httpBackend) -> - rule = scope.tagGroups[0].rules[0] - spyOn(window, "confirm").and.returnValue(true) - $httpBackend.expectDELETE('/admin/enterprises/45/tag_rules/1.json').respond(status: 204) - scope.deleteTagRule(scope.tagGroups[0], rule) - $httpBackend.flush() - - it "removes the specified rule from the rules list", -> - expect(scope.tagGroups[0].rules.length).toEqual 1 - expect(scope.tagGroups[1].rules.length).toEqual 1 - expect(scope.tagGroups[0].rules.indexOf(rule)).toEqual -1 - - it "updates tagGroup start indices", -> - expect(scope.tagGroups[0].startIndex).toEqual 1 - expect(scope.tagGroups[1].startIndex).toEqual 2 - - describe "without an id", -> - rule = null - - beforeEach inject ($httpBackend) -> - rule = scope.tagGroups[0].rules[0] - rule.id = null - scope.deleteTagRule(scope.tagGroups[0], rule) - - it "removes the specified rule from the rules list", -> - expect(scope.tagGroups[0].rules.length).toEqual 1 - expect(scope.tagGroups[1].rules.length).toEqual 1 - expect(scope.tagGroups[0].rules.indexOf(rule)).toEqual -1 - - it "updates tagGroup start indices", -> - expect(scope.tagGroups[0].startIndex).toEqual 1 - expect(scope.tagGroups[1].startIndex).toEqual 2