Skip to content

Commit

Permalink
Merge branch 'master' into rob-github-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RohanM committed Jun 16, 2015
2 parents 30af5d4 + 80bf6e6 commit 3870219
Show file tree
Hide file tree
Showing 10 changed files with 55 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Original file line number Diff line number Diff line change
@@ -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)'}
5 changes: 4 additions & 1 deletion app/views/admin/enterprise_relationships/_form.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Original file line number Diff line number Diff line change
@@ -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) }}
2 changes: 1 addition & 1 deletion app/views/admin/enterprise_relationships/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/shared/_enterprises_sub_menu.html.haml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"

0 comments on commit 3870219

Please sign in to comment.