simple-navigation-acl 0.1.0 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 01d931fc73723efb53a9738a8e81fbbd6822c233
4
- data.tar.gz: 573121676f3c02e1831f9af7e42b20dab12fe40e
3
+ metadata.gz: 44533625930b4bbeb0113b6f09eb759655caa231
4
+ data.tar.gz: 44bdfbe67ee60d6e0fff103aa6177afe48bce08f
5
5
  SHA512:
6
- metadata.gz: 9225225ba2d5953d3638f095ad9f32b8f9029f9b9c4e43e187537f31819c97abd9652938be933dbd39dbeef2a706b726263740d7c4cf48e191f5875f69bba95c
7
- data.tar.gz: 873dc6026fdea9ada2b007bfdfa0b122580e964675d2881c3e950c965f76149dca7c45d5bf4704d3fa6cfdae022772975eb97ff042ab101b0648af7051b2624e
6
+ metadata.gz: cbf70c8d790c3374a1b3be466ad9e9ebe9cd380bcc29e09a0fea3affb21049bd47a82bf15571d9ed8c8359cb1b4c2a2a7b4162dc6912322e7c02483012acd372
7
+ data.tar.gz: ab4541c501eeeeb31f792b4b12258b2dd5f22a83ba15b8f207a1b69d7c5a58b0fa68f84335dad55644063bb88f7460bc5f392c72597f052eebb49fcd5afacc69
data/README.md CHANGED
@@ -31,6 +31,7 @@ Modify simple-navigation helper `render_navigation` in your views to simple-navi
31
31
  = render_navigation_acl acl_id: current_user.role, level:(1..3), :renderer => :bootstrap3, :expand_all => true
32
32
  ```
33
33
 
34
+
34
35
  ## ID and CONTEXT
35
36
 
36
37
  The simple-navigation-acl have id and [context](https://github.com/codeplant/simple-navigation/wiki/Configuration) to create rules for you:
@@ -103,6 +104,20 @@ And to save via HTTP PATCH, PUT or POST, like:
103
104
 
104
105
  ```
105
106
 
107
+ ### Editing default views
108
+
109
+ On install is created two views: **edit** and **show**
110
+
111
+ In `views/simple_navigation_acl/show.html.erb`:
112
+ ```html
113
+ <% SimpleNavigationAcl::Base.contexts.each do |context| %>
114
+ <%= render 'simple_navigation_acl/list', context: context, readonly: true %>
115
+ <% end %>
116
+ ```
117
+ You can List all navigations contexts with `SimpleNavigationAcl::Base.contexts` and can render only permissions list with: `render 'simple_navigation_acl/list', context: context`
118
+ By default `context=:default` and `readonly=false` (readonly define if permissiosn list is editable or not)
119
+
120
+
106
121
  ### Example Form for ACL by Roles
107
122
 
108
123
  ```haml
@@ -3,6 +3,9 @@ $(document).on('change','.acl_tree_checkbox', function(ev) {
3
3
  if (checkbox.prop('checked')==true) {
4
4
  var acl_tree_parents = checkbox.parents('.acl_tree_item');
5
5
  acl_tree_parents.find('> :checkbox').prop('checked', true);
6
+
7
+ var acl_tree_children = checkbox.parent('.acl_tree_item:first').find('.acl_tree_item');
8
+ acl_tree_children.find('> :checkbox').prop('checked', true);
6
9
  } else {
7
10
  var acl_tree_item = checkbox.parent('.acl_tree_item:first');
8
11
  acl_tree_item.find(':checkbox').prop('checked', false);
@@ -0,0 +1,4 @@
1
+ <% readonly=false if readonly.nil? %>
2
+ <% context=:default if context.nil? %>
3
+ <% navs = navigations_from_context(context) %>
4
+ <%= show_navigation_tree(navs, @rules, readonly: readonly) %>
@@ -0,0 +1,8 @@
1
+ <ul class="acl_tree">
2
+ <% navs = [] if navs.nil? %>
3
+ <% rules = [] if rules.nil? %>
4
+ <% readonly = true if readonly.nil? %>
5
+ <% navs.each do |nav| %>
6
+ <%= render partial: 'simple_navigation_acl/tree_item', locals: {nav: nav, rules: rules, readonly: readonly} %>
7
+ <% end %>
8
+ </ul>
@@ -0,0 +1,19 @@
1
+ <% unless nav.nil? || nav[:key].to_s =~ /^divider/ %>
2
+ <li class="acl_tree_item">
3
+ <% rules = [] if rules.nil? %>
4
+ <% readonly = true if readonly.nil? %>
5
+ <% nav_id = "#{nav[:context]}_#{nav[:key]}" %>
6
+ <% checked = rules.include?([nav[:context].to_s, nav[:key].to_s]) %>
7
+ <% if readonly %>
8
+ <% if checked %>
9
+ <span>&#10004;</span>
10
+ <% end %>
11
+ <% else %>
12
+ <input class="acl_tree_checkbox" type="checkbox" name="acl_item[<%= nav[:context] %>][]" id="<%= nav_id %>" value="<%= nav[:key] %>" <%= checked ? 'checked' : '' %> />
13
+ <% end %>
14
+ <label for="<%= nav_id %>"><%= nav[:name] %></label>
15
+ <% if nav.key?(:items) %>
16
+ <%= show_navigation_tree(nav[:items], rules, readonly: readonly) %>
17
+ <% end %>
18
+ </li>
19
+ <% end %>
@@ -1,11 +1,13 @@
1
- <h1>Edit ACL</h1>
1
+ <h1>Edit ACL of #<%= @id %></h1>
2
2
 
3
3
  <%= form_tag simple_navigation_acl_save_path do %>
4
- <%= render 'simple_navigation_acl/form' %>
4
+ <% SimpleNavigationAcl::Base.contexts.each do |context| %>
5
+ <%= render 'simple_navigation_acl/list', context: context %>
6
+ <% end %>
5
7
  <hr />
6
8
  <%= submit_tag 'Save' %>
7
9
  or
8
10
  <%= link_to 'Back', :back %>
9
11
  |
10
- <%= link_to 'Show', simple_navigation_acl_edit_path(id: @id) %>
12
+ <%= link_to 'Show', simple_navigation_acl_show_path(id: @id) %>
11
13
  <% end %>
@@ -1,6 +1,8 @@
1
- <h1>Show ACL</h1>
1
+ <h1>Show ACL of #<%= @id %></h1>
2
2
 
3
- <%= render 'simple_navigation_acl/form', readonly: true %>
3
+ <% SimpleNavigationAcl::Base.contexts.each do |context| %>
4
+ <%= render 'simple_navigation_acl/list', context: context, readonly: true %>
5
+ <% end %>
4
6
 
5
7
  <hr />
6
8
 
@@ -1,3 +1,3 @@
1
1
  module SimpleNavigationAcl
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.2"
3
3
  end
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple-navigation-acl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bruno Porto
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-11-23 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: haml
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
11
+ date: 2016-11-24 00:00:00.000000000 Z
12
+ dependencies: []
27
13
  description: Great and easy way to control ACL with simple-navigation in your Rails
28
14
  project
29
15
  email:
@@ -41,9 +27,9 @@ files:
41
27
  - app/controllers/simple_navigation_acl/rules_controller.rb
42
28
  - app/helpers/simple_navigation_acl/application_helper.rb
43
29
  - app/models/simple_navigation_acl/acl_rule.rb
44
- - app/views/simple_navigation_acl/_form.haml
45
- - app/views/simple_navigation_acl/_tree.haml
46
- - app/views/simple_navigation_acl/_tree_item.haml
30
+ - app/views/simple_navigation_acl/_list.html.erb
31
+ - app/views/simple_navigation_acl/_tree.html.erb
32
+ - app/views/simple_navigation_acl/_tree_item.html.erb
47
33
  - app/views/simple_navigation_acl/rules/edit.html.erb
48
34
  - app/views/simple_navigation_acl/rules/show.html.erb
49
35
  - config/initializers/assets.rb
@@ -1,6 +0,0 @@
1
- - readonly=false if readonly.nil?
2
- - SimpleNavigationAcl::Base.contexts.each do |context|
3
- - navs = navigations_from_context(context)
4
- %fieldset.simple_navigation_acl_fieldset
5
- %legend= context.to_s.humanize
6
- = show_navigation_tree(navs, @rules, readonly: readonly)
@@ -1,6 +0,0 @@
1
- %ul.acl_tree
2
- - navs = [] if navs.nil?
3
- - rules = [] if rules.nil?
4
- - readonly = true if readonly.nil?
5
- - navs.each do |nav|
6
- = render partial: 'simple_navigation_acl/tree_item', locals: {nav: nav, rules: rules, readonly: readonly}
@@ -1,12 +0,0 @@
1
- - unless nav.nil? || nav[:key].to_s =~ /^divider/
2
- %li.acl_tree_item
3
- - rules = [] if rules.nil?
4
- - readonly = true if readonly.nil?
5
- - nav_id = "#{nav[:context]}_#{nav[:key]}"
6
- - checked = rules.include?([nav[:context].to_s, nav[:key].to_s])
7
- - if readonly
8
- %span= "&#10004;".html_safe if checked
9
- - else
10
- %input.acl_tree_checkbox{type: 'checkbox', name: "acl_item[#{nav[:context]}][]", id: nav_id, value: nav[:key], checked: checked}
11
- %label{for: nav_id}= nav[:name]
12
- = show_navigation_tree(nav[:items], rules, readonly: readonly) if nav.key?(:items)