adminterface 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7aa4367f85794395d6b92b141c12488c2158b99f0585f4a76f201bb080fb167c
4
- data.tar.gz: 88a7bb2ecafe63f80145908a0cd4d1289011a71352ee9960f2870a80c91fc08f
3
+ metadata.gz: 2b30a8aff4bfb6cf7d7b27a339506303115d5405b0469235a8bc30b742dfc83d
4
+ data.tar.gz: fb9a449e608873ef279011a2aa28842c0ea58ebffe536c2e5dd5ea86073554bc
5
5
  SHA512:
6
- metadata.gz: 92dfa1e53f319043ee355df3d0d70e9888f070727c5828851ee1e10d6e2aa590af464dc7ad75ef871d8e375676dfc68ed4c97decc0fc3f0492868d642f2f2667
7
- data.tar.gz: 650a23ef8b8f323f6f792fa591aec71d60701c7b5c32d3d2d311cb51ed73a42f9ef8bf0d988498d60aba2cfe0b8a87e82bd8aa7c8e5162b209ac6f72e5d60004
6
+ metadata.gz: fa068e11984acb0479d6cf5b91b9af4ca200da51fd5eca97db028350cf5aac3069c5f1d31fd02232e0b0a8f2cb265e9f93ce87d24bb9c86b8dbbd8daec7362e8
7
+ data.tar.gz: 38bd9d91f3748df7c4e81482eccf9262e8426aaf02be1a7014be6ef9a4074432608688dabd3ae0b4b37cd3fa8e9ffb68b22fb96e26e7322539cc1cbfcd408e82
data/README.md CHANGED
@@ -50,7 +50,7 @@ Check our [website](https://adminterface.io) to find in-depth documentation for
50
50
  See [CONTRIBUTING.md](CONTRIBUTING.md).
51
51
 
52
52
  ## License
53
- Adminterface is free for personal and non-commercial use and with a yearly subscription for commercial purposes. See [our Terms of Service in full text](LICENSE.md) for more information.
53
+ Adminterface is free for personal and non-commercial use and with a yearly subscription for commercial purposes. See our [Terms of Service in full text](LICENSE.md) for more information.
54
54
 
55
55
  ### For Commerical License
56
56
  Get a license at https://adminterface.io/pricing, then create and add the `license_key` into the following file in your project:
data/Rakefile CHANGED
@@ -18,7 +18,7 @@ task :prepare_assets do
18
18
  system "rm -rf test/dummy/public/packs"
19
19
  system "rm -rf test/dummy/public/packs-test"
20
20
  system "yarn install --frozen-lockfile"
21
- system "(cd test/dummy && yarn install --frozen-lockfile)"
21
+ system "cd test/dummy && yarn install --frozen-lockfile"
22
22
  end
23
23
 
24
24
  # Generate dependency licenses
@@ -9,11 +9,19 @@ module Adminterface
9
9
 
10
10
  def set_resource_scope
11
11
  session[:resource_scope] = {
12
- controller: controller_name,
13
- action: action_name
12
+ controller: controller_path,
13
+ action: action_name_pairing(action_name)
14
14
  }
15
15
  end
16
16
 
17
+ def action_name_pairing(name)
18
+ case name
19
+ when "create" then "new"
20
+ when "update" then "edit"
21
+ else name
22
+ end
23
+ end
24
+
17
25
  def reset_tab
18
26
  params.delete(:tab)
19
27
  params.delete(:anchor_id)
@@ -26,30 +34,26 @@ module Adminterface
26
34
  def same_controller?
27
35
  return true if resource_scope[:controller].blank?
28
36
 
29
- resource_scope[:controller] == controller_name
37
+ resource_scope[:controller] == controller_path
30
38
  end
31
39
 
32
40
  def same_action?
33
- return true if resource_scope[:action].blank?
34
-
35
- case resource_scope[:action]
36
- when "edit", "update" then %w[edit update].include? action_name
37
- else action_name == resource_scope[:action]
38
- end
41
+ resource_scope[:action].presence &&
42
+ action_name_pairing(action_name).eql?(resource_scope[:action])
39
43
  end
40
44
 
41
45
  def resource_scope
42
- session.fetch(:resource_scope, {})
46
+ session.fetch(:resource_scope, {}).with_indifferent_access
43
47
  end
44
48
  end
45
49
  end
46
50
  end
47
51
 
48
52
  # Overwrite activeadmin/lib/active_admin/base_controller.rb
49
- ActiveSupport.on_load(:active_admin) do
53
+ ActiveAdmin.after_load do
50
54
  ActiveAdmin::BaseController.class_eval do
51
55
  prepend Adminterface::Extensions::BaseController
52
56
  before_action :reset_tab, if: :should_reset_tab?
53
- after_action :set_resource_scope
57
+ before_action :set_resource_scope
54
58
  end
55
59
  end
@@ -4,7 +4,9 @@ module Adminterface
4
4
  module AlertHelper
5
5
  def flashes_html
6
6
  flash.each do |type, msg|
7
- concat(content_tag(:div, msg, class: "flash flash_#{type} alert #{flash_css_classes[type.to_sym]}".squish))
7
+ concat(content_tag(:div, msg,
8
+ class: "flash flash_#{type} alert #{flash_css_classes[type.to_sym]}".squish,
9
+ role: "alert"))
8
10
  end
9
11
  nil
10
12
  end
@@ -47,7 +47,10 @@ ActiveAdmin::Views::DropdownMenu.class_eval do
47
47
  button_options[:class] = "#{button_options[:class]} dropdown-toggle".squish
48
48
  options[:class] = "#{options[:class]} dropdown".squish
49
49
 
50
- @button = build_button(name, button_options.merge("data-bs-toggle": "dropdown"))
50
+ @button = build_button(
51
+ name,
52
+ button_options.merge("data-bs-toggle": "dropdown", role: "button", "aria-expanded": "false")
53
+ )
51
54
  @menu = build_menu(menu_options)
52
55
 
53
56
  super(options)
@@ -15,8 +15,13 @@ module Adminterface
15
15
  end
16
16
  end
17
17
 
18
- def item_class(item)
19
- "#{item.html_options[:class]} #{item.current?(assigns[:current_tab]) ? "active" : nil}".squish
18
+ def current_item_options(item)
19
+ return {} unless item.current?(assigns[:current_tab])
20
+
21
+ {
22
+ class: "#{item.html_options[:class]} active".squish,
23
+ "aria-current": "page"
24
+ }
20
25
  end
21
26
  end
22
27
  end
@@ -51,7 +56,7 @@ ActiveAdmin::Views::MenuItem.class_eval do
51
56
  end
52
57
 
53
58
  if url
54
- item_options = item.html_options.merge(class: item_class(item)).delete_if { |_k, v| v.blank? }
59
+ item_options = item.html_options.merge(current_item_options(item)).delete_if { |_k, v| v.blank? }
55
60
  text_node link_to(menu_label, url, **item_options)
56
61
  else
57
62
  span menu_label, item.html_options.merge(class: "navbar-text")
@@ -6,20 +6,16 @@ module Adminterface
6
6
  def build_menu_item(title, options, &_block)
7
7
  fragment = options.fetch(:id, fragmentize(title))
8
8
  html_options = options.fetch(:html_options, {})
9
- li html_options.merge(class: "nav-item") do
10
- if @http
11
- params[:tab] ||= @default_tab || fragment
12
- link_to title, url_for(tab: fragment, anchor: id, anchor_id: id), class: toggler_class(fragment)
13
- else
14
- link_to title, "##{fragment}", class: toggler_class(fragment), data: {"bs-toggle": "tab", "bs-target": "##{fragment}"}
15
- end
9
+
10
+ li html_options.merge(class: "nav-item", role: "presentation") do
11
+ @http ? link_to_http(title, fragment) : link_to_js(title, fragment)
16
12
  end
17
13
  end
18
14
 
19
15
  def build_content_item(title, options, &block)
20
16
  fragment = options.fetch(:id, fragmentize(title))
21
- options = options.reverse_merge(id: fragmentize(title))
22
- div(options.merge(class: tab_pane_class(fragment)), &block)
17
+ options = options.reverse_merge(id: fragment, "aria-labelledby": "#{fragment}-tab")
18
+ div(options.merge(tab_pane_options(fragment)), &block)
23
19
  end
24
20
 
25
21
  def default_css_class
@@ -39,12 +35,41 @@ module Adminterface
39
35
 
40
36
  private
41
37
 
42
- def toggler_class(fragment)
43
- "nav-link #{current_tab?(fragment) ? "active" : nil}".squish
38
+ def link_to_js(title, fragment)
39
+ options = toggler_options(fragment).merge(data: {"bs-toggle": "tab", "bs-target": "##{fragment}"})
40
+ link_to(title, "##{fragment}", **options)
41
+ end
42
+
43
+ def link_to_http(title, fragment)
44
+ params[:tab] ||= @default_tab || fragment
45
+
46
+ link_to(title,
47
+ url_for(controller: resource_scope[:controller],
48
+ action: resource_scope[:action], tab: fragment, anchor: id, anchor_id: id),
49
+ **toggler_options(fragment))
50
+ end
51
+
52
+ def resource_scope
53
+ session.fetch(:resource_scope, {}).with_indifferent_access
54
+ end
55
+
56
+ def toggler_options(fragment)
57
+ defaults = {id: "#{fragment}-tab", "aria-controls": fragment}
58
+ options =
59
+ if current_tab?(fragment)
60
+ {class: "nav-link active", "aria-selected": "true"}
61
+ else
62
+ {class: "nav-link", "aria-selected": "false"}
63
+ end
64
+
65
+ defaults.merge(options)
44
66
  end
45
67
 
46
- def tab_pane_class(fragment)
47
- "tab-pane #{current_tab?(fragment) ? "active" : nil}".squish
68
+ def tab_pane_options(fragment)
69
+ {
70
+ class: "tab-pane #{current_tab?(fragment) ? "active" : nil}".squish,
71
+ role: "tabpanel"
72
+ }
48
73
  end
49
74
 
50
75
  def current_tab?(fragment)
@@ -26,7 +26,8 @@ module Adminterface
26
26
  end
27
27
 
28
28
  def navbar_toggler
29
- button(class: "navbar-toggler", 'data-bs-target': "##{ID}", 'data-bs-toggle': "collapse") do
29
+ button(class: "navbar-toggler", 'data-bs-target': "##{ID}",
30
+ 'data-bs-toggle': "collapse", "aria-expanded": "false") do
30
31
  span class: "navbar-toggler-icon"
31
32
  end
32
33
  end
@@ -102,7 +102,8 @@ module Adminterface
102
102
  div class: "flashes" do
103
103
  flash_messages.each do |type, messages|
104
104
  [*messages].each do |message|
105
- div class: "flash flash_#{type} alert #{flash_css_classes[type.to_sym]} #{flash_dismissible_class}".squish do
105
+ div class: "flash flash_#{type} alert #{flash_css_classes[type.to_sym]} #{flash_dismissible_class}".squish,
106
+ role: "alert" do
106
107
  text_node(message)
107
108
  button(class: "btn-close", "data-bs-dismiss": "alert", "aria-label": "Close") if flash_dismissible?
108
109
  end
@@ -25,7 +25,7 @@ module Adminterface
25
25
 
26
26
  meta_tags = {
27
27
  version: Adminterface::VERSION,
28
- viewport: "width=device-width, height=device-height, initial-scale=1.0, user-scalable=no"
28
+ viewport: "width=device-width, height=device-height, initial-scale=1.0"
29
29
  }
30
30
 
31
31
  config.meta_tags_for_logged_out_pages = meta_tags
@@ -1,3 +1,3 @@
1
1
  module Adminterface
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: adminterface
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - I-Lung Lee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-10-29 00:00:00.000000000 Z
11
+ date: 2021-11-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin