From d717c38f6d3622ecce953baa354705e33a400d23 Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Fri, 12 Jun 2015 17:02:40 +1000 Subject: [PATCH] Filter relationships by permission --- .../enterprise_relationships_controller.js.coffee | 12 ++++++++++++ .../admin/filters/keywords_filter.js.coffee | 7 +++++++ .../services/enterprise_relationships.js.coffee | 8 ++++---- .../_enterprise_relationship.html.haml | 4 ++-- .../enterprise_relationships/_search_input.html.haml | 5 +++++ .../admin/enterprise_relationships/index.html.haml | 2 +- 6 files changed, 31 insertions(+), 7 deletions(-) create mode 100644 app/assets/javascripts/admin/filters/keywords_filter.js.coffee create mode 100644 app/views/admin/enterprise_relationships/_search_input.html.haml 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 1b90e18a34..47083d443a 100644 --- a/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee +++ b/app/assets/javascripts/admin/controllers/enterprise_relationships_controller.js.coffee @@ -10,6 +10,18 @@ angular.module("ofn.admin").controller "AdminEnterpriseRelationshipsCtrl", ($sco 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] 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 0000000000..7d207518f0 --- /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 e6dcbf15df..8c7d798138 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 45e79b1877..996bc487d8 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/_search_input.html.haml b/app/views/admin/enterprise_relationships/_search_input.html.haml new file mode 100644 index 0000000000..b8bcbc62c6 --- /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 0807a37825..40fbdbc415 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