diff --git a/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee b/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee index 88524fb3309..47083d443a1 100644 --- a/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee @@ -9,3 +9,26 @@ angular.module("ofn.admin").controller "AdminEnterpriseRelationshipsCtrl", ($sco $scope.delete = (enterprise_relationship) -> if confirm("Are you sure?") $scope.EnterpriseRelationships.delete enterprise_relationship + + $scope.toggleKeyword = (string, key) -> + string = '' unless string + words = string.split ' ' + words = words.filter (s) -> + s + index = words.indexOf key + if index > -1 + words.splice index, 1 + else + words.push key + words.join ' ' + + $scope.allPermissionsChecked = -> + for i in EnterpriseRelationships.all_permissions + if !$scope.permissions[i] + return false + return true + + $scope.checkAllPermissions = -> + newValue = !$scope.allPermissionsChecked() + EnterpriseRelationships.all_permissions.forEach (p) -> + $scope.permissions[p] = newValue diff --git a/app/assets/javascripts/admin/filters/keywords_filter.js.coffee b/app/assets/javascripts/admin/filters/keywords_filter.js.coffee new file mode 100644 index 00000000000..7d207518f00 --- /dev/null +++ b/app/assets/javascripts/admin/filters/keywords_filter.js.coffee @@ -0,0 +1,7 @@ +angular.module("ofn.admin").filter "keywords", ($filter) -> + return (array, query) -> + return array unless query + keywords = query.split ' ' + keywords.forEach (key) -> + array = $filter('filter')(array, key) + array diff --git a/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee b/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee index e6dcbf15df9..8c7d798138b 100644 --- a/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee +++ b/app/assets/javascripts/admin/services/enterprise_relationships.js.coffee @@ -26,7 +26,7 @@ angular.module("ofn.admin").factory 'EnterpriseRelationships', ($http, enterpris permission_presentation: (permission) -> switch permission - when "add_to_order_cycle" then "to add to order cycle" - when "manage_products" then "to manage products" - when "edit_profile" then "to edit profile" - when "create_variant_overrides" then "to override variant details" + when "add_to_order_cycle" then "add to order cycle" + when "manage_products" then "manage products" + when "edit_profile" then "edit profile" + when "create_variant_overrides" then "override variant details" diff --git a/app/views/admin/enterprise_relationships/_enterprise_relationship.html.haml b/app/views/admin/enterprise_relationships/_enterprise_relationship.html.haml index 45e79b1877a..996bc487d8d 100644 --- a/app/views/admin/enterprise_relationships/_enterprise_relationship.html.haml +++ b/app/views/admin/enterprise_relationships/_enterprise_relationship.html.haml @@ -1,10 +1,10 @@ -%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships | filter:query"} +%tr{"ng-repeat" => "enterprise_relationship in EnterpriseRelationships.enterprise_relationships | keywords:query"} %td {{ enterprise_relationship.parent_name }} %td permits %td {{ enterprise_relationship.child_name }} %td %ul %li{"ng-repeat" => "permission in enterprise_relationship.permissions"} - {{ EnterpriseRelationships.permission_presentation(permission.name) }} + to {{ EnterpriseRelationships.permission_presentation(permission.name) }} %td.actions %a.delete-enterprise-relationship.icon-trash.no-text{'ng-click' => 'delete(enterprise_relationship)'} diff --git a/app/views/admin/enterprise_relationships/_form.html.haml b/app/views/admin/enterprise_relationships/_form.html.haml index 9d031a57c5a..433f9f4ca04 100644 --- a/app/views/admin/enterprise_relationships/_form.html.haml +++ b/app/views/admin/enterprise_relationships/_form.html.haml @@ -7,10 +7,13 @@ %td %select{name: "enterprise_relationship_child_id", "ng-model" => "child_id", "ng-options" => "e.id as e.name for e in Enterprises.all_enterprises"} %td + %label + %input{type: "checkbox", ng: {checked: "allPermissionsChecked()", click: "checkAllPermissions()"}} + Everything %div{"ng-repeat" => "permission in EnterpriseRelationships.all_permissions"} %label %input{type: "checkbox", "ng-model" => "permissions[permission]"} - {{ EnterpriseRelationships.permission_presentation(permission) }} + to {{ EnterpriseRelationships.permission_presentation(permission) }} %td.actions %input{type: "button", value: "Create", "ng-click" => "create()"} .errors {{ EnterpriseRelationships.create_errors }} diff --git a/app/views/admin/enterprise_relationships/_search_input.html.haml b/app/views/admin/enterprise_relationships/_search_input.html.haml new file mode 100644 index 00000000000..b8bcbc62c69 --- /dev/null +++ b/app/views/admin/enterprise_relationships/_search_input.html.haml @@ -0,0 +1,5 @@ +%input.search{"ng-model" => "query", "placeholder" => "Search"} + +%label{ng: {repeat: "permission in EnterpriseRelationships.all_permissions"}} + %input{type: "checkbox", ng: {click: "$parent.query = toggleKeyword($parent.query, permission)"}} + {{ EnterpriseRelationships.permission_presentation(permission) }} diff --git a/app/views/admin/enterprise_relationships/index.html.haml b/app/views/admin/enterprise_relationships/index.html.haml index 0807a378254..40fbdbc4152 100644 --- a/app/views/admin/enterprise_relationships/index.html.haml +++ b/app/views/admin/enterprise_relationships/index.html.haml @@ -6,7 +6,7 @@ %div{"ng-app" => "ofn.admin", "ng-controller" => "AdminEnterpriseRelationshipsCtrl"} = render 'data' - %input.search{"ng-model" => "query", "placeholder" => "Search"} + = render 'search_input' %table#enterprise-relationships %tbody diff --git a/app/views/admin/shared/_enterprises_sub_menu.html.haml b/app/views/admin/shared/_enterprises_sub_menu.html.haml index 31366091ef3..3088b7e73ee 100644 --- a/app/views/admin/shared/_enterprises_sub_menu.html.haml +++ b/app/views/admin/shared/_enterprises_sub_menu.html.haml @@ -1,4 +1,4 @@ = content_for :sub_menu do %ul#sub_nav.inline-menu{"data-hook" => "admin_enterprise_sub_tabs"} = tab :enterprises, url: main_app.admin_enterprises_path - = tab :relationships, url: main_app.admin_enterprise_relationships_path, match_path: '/enterprise_relationships' + = tab :enterprise_relationships, url: main_app.admin_enterprise_relationships_path diff --git a/config/routes.rb b/config/routes.rb index 4996b3a768a..9855f96fe04 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,10 @@ Openfoodnetwork::Application.routes.draw do root :to => 'home#index' + # Redirects from old URLs avoid server errors and helps search engines + get "/enterprises", to: redirect("/") + get "/products", to: redirect("/") + get "/t/products/:id", to: redirect("/") get "/#/login", to: "home#index", as: :spree_login get "/login", to: redirect("/#/login") diff --git a/spec/javascripts/unit/admin/services/enterprise_relationships_spec.js.coffee b/spec/javascripts/unit/admin/services/enterprise_relationships_spec.js.coffee index 0d8e50fc5a6..0d0a01215da 100644 --- a/spec/javascripts/unit/admin/services/enterprise_relationships_spec.js.coffee +++ b/spec/javascripts/unit/admin/services/enterprise_relationships_spec.js.coffee @@ -12,7 +12,7 @@ describe "enterprise relationships", -> EnterpriseRelationships = _EnterpriseRelationships_ it "presents permission names", -> - expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "to add to order cycle" - expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "to manage products" - expect(EnterpriseRelationships.permission_presentation("edit_profile")).toEqual "to edit profile" - expect(EnterpriseRelationships.permission_presentation("create_variant_overrides")).toEqual "to override variant details" + expect(EnterpriseRelationships.permission_presentation("add_to_order_cycle")).toEqual "add to order cycle" + expect(EnterpriseRelationships.permission_presentation("manage_products")).toEqual "manage products" + expect(EnterpriseRelationships.permission_presentation("edit_profile")).toEqual "edit profile" + expect(EnterpriseRelationships.permission_presentation("create_variant_overrides")).toEqual "override variant details"