keystone_ui-app 0.9.1 → 0.9.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
  SHA256:
3
- metadata.gz: d320d8f694c07c97d92a0c0b1a7225940913c14ad9b7081dc631853de7eaac74
4
- data.tar.gz: 5255e01dfd566625865491dd2321c427977814d7023d8e2487c4d905c14cb5cb
3
+ metadata.gz: 44e279866057f3b55373bd071c7bff9e82f3a3f9813b958858e7e773427254e9
4
+ data.tar.gz: 27d97270abd68c1565c980b97fa7314fbafd86b0dbe4246d3327d140e112ff91
5
5
  SHA512:
6
- metadata.gz: 97f4196ac56fc1986675aa77d9871f02116219fc2f27c43ab47e70859b6a7f11fd40d2b690b3e1b76012a789d0ac1a8d0368293713d26cc4f70b03b524931a03
7
- data.tar.gz: e9cd360294440c12118fe91bd281055cd644f09415498b290f139b32fa08f22b5b9c3c0342317ede5a533d5d55714eead16172d1916c66ce6ef2deb5bc107859
6
+ metadata.gz: 6213e9983891a63af6159bb4a74d71e20b6434861243f3087197df3024c38b59ffdfd037da46c4cb09f287a2339f921bad9cf4ad242dd3ad5e07170b24ab943c
7
+ data.tar.gz: 55ae1da39d122d634b09d862ad0638554b067ceaf339233e73d332be0b8fe421bf418906ecc768bcb4ac5200295117fd16a81b6ed625e42018e7029c8d6e34ea
@@ -39,7 +39,7 @@ module KeystoneUi
39
39
  end
40
40
 
41
41
  def permitted_groups
42
- KeystoneUi.configuration.navigation_groups
42
+ KeystoneUi::App::PersonGroups.for(helpers).groups
43
43
  .map { |group| [ group, group.tabs_permitted_for(helpers) ] }
44
44
  .reject { |_group, pages| pages.empty? }
45
45
  end
@@ -13,7 +13,7 @@ module KeystoneUi
13
13
  end
14
14
 
15
15
  def tabs
16
- @tabs ||= KeystoneUi::App::BottomBar.new(helpers).tabs
16
+ @tabs ||= KeystoneUi::App::BottomBar.for(helpers).tabs
17
17
  end
18
18
 
19
19
  def active?(tab)
@@ -56,12 +56,12 @@ module KeystoneUi
56
56
  end
57
57
 
58
58
  def bottom_bar
59
- @bottom_bar ||= KeystoneUi::App::BottomBar.new(helpers)
59
+ @bottom_bar ||= KeystoneUi::App::BottomBar.for(helpers)
60
60
  end
61
61
 
62
62
  def visible_groups
63
63
  @visible_groups ||= KeystoneUi::VisibleNavigation.new(
64
- KeystoneUi.configuration.navigation_groups,
64
+ KeystoneUi::App::PersonGroups.for(helpers).groups,
65
65
  view: helpers,
66
66
  saved_order: saved_order,
67
67
  current_tab: nil
@@ -39,7 +39,7 @@ module KeystoneUi
39
39
  end
40
40
 
41
41
  def bar_tabs
42
- @bar_tabs ||= KeystoneUi::App::BottomBar.new(view).tabs
42
+ @bar_tabs ||= KeystoneUi::App::BottomBar.for(view).tabs
43
43
  end
44
44
 
45
45
  def view
@@ -3,6 +3,7 @@
3
3
  require "keystone_ui/navigation_order"
4
4
  require "keystone_ui/app/shell_check"
5
5
  require "keystone_ui/app/area_choices"
6
+ require "keystone_ui/app/person_groups"
6
7
 
7
8
  module KeystoneUi
8
9
  module App
@@ -12,14 +13,21 @@ module KeystoneUi
12
13
  MORE_LABEL = "More"
13
14
  MOST_TABS = ShellCheck::MOST_BOTTOM_TABS
14
15
 
16
+ ENV_KEY = "keystone_ui_app.bottom_bar"
17
+
18
+ def self.for(view)
19
+ env = view.request.env if view.respond_to?(:request)
20
+ return new(view) unless env
21
+
22
+ env[ENV_KEY] ||= new(view)
23
+ end
24
+
15
25
  def initialize(view)
16
26
  @view = view
17
27
  end
18
28
 
19
29
  def tabs
20
- shown = fixed_tabs + area_tabs
21
- full = shown.first(MOST_TABS)
22
- more_tab_needed?(full) ? shown.first(MOST_TABS - 1) + [ more_tab ] : full
30
+ @tabs ||= arranged_tabs
23
31
  end
24
32
 
25
33
  def opened_href(area)
@@ -28,6 +36,12 @@ module KeystoneUi
28
36
 
29
37
  private
30
38
 
39
+ def arranged_tabs
40
+ shown = fixed_tabs + area_tabs
41
+ full = shown.first(MOST_TABS)
42
+ more_tab_needed?(full) ? shown.first(MOST_TABS - 1) + [ more_tab ] : full
43
+ end
44
+
31
45
  def fixed_tabs
32
46
  configuration.bottom_tabs.select { |tab| tab.permitted.call(@view) }.map do |tab|
33
47
  Tab.new(label: tab.label, href: tab.href_for(@view), icon: tab.icon_for(@view), ios_system_image: tab.ios_system_image, android_icon: tab.android_icon, sections: [ tab.section ].compact, count: tab.count&.call(@view))
@@ -75,7 +89,7 @@ module KeystoneUi
75
89
  end
76
90
 
77
91
  def permitted_groups
78
- @permitted_groups ||= KeystoneUi.configuration.navigation_groups
92
+ @permitted_groups ||= PersonGroups.for(@view).groups
79
93
  .map { |group| [ group, group.tabs_permitted_for(@view) ] }
80
94
  .reject { |_group, pages| pages.empty? }
81
95
  end
@@ -88,7 +102,7 @@ module KeystoneUi
88
102
  end
89
103
 
90
104
  def area_choices
91
- @area_choices ||= AreaChoices.for(configuration, @view)
105
+ @area_choices ||= KeystoneUi::App.area_choices(@view)
92
106
  end
93
107
 
94
108
  def configuration
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require "keystone_ui/visible_navigation"
4
+ require "keystone_ui/app/person_groups"
4
5
 
5
6
  module KeystoneUi
6
7
  module App
@@ -11,7 +12,7 @@ module KeystoneUi
11
12
 
12
13
  def group
13
14
  KeystoneUi::VisibleNavigation.new(
14
- KeystoneUi.configuration.navigation_groups,
15
+ KeystoneUi::App::PersonGroups.for(@view).groups,
15
16
  view: @view,
16
17
  saved_order: [],
17
18
  current_tab: KeystoneUi.configuration.supplied_current_tab(@view)
@@ -0,0 +1,54 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "delegate"
4
+
5
+ module KeystoneUi
6
+ module App
7
+ class PersonGroups
8
+ ENV_KEY = "keystone_ui_app.person_groups"
9
+
10
+ class Page < SimpleDelegator
11
+ def initialize(page, view)
12
+ super(page)
13
+ @view = view
14
+ end
15
+
16
+ def count_for(_view)
17
+ return @count if defined?(@count)
18
+
19
+ @count = __getobj__.count_for(@view)
20
+ end
21
+ end
22
+
23
+ class Group
24
+ def initialize(group, view)
25
+ @group = group
26
+ @view = view
27
+ end
28
+
29
+ def label = @group.label
30
+
31
+ def standalone? = @group.standalone?
32
+
33
+ def tabs = @group.tabs
34
+
35
+ def tabs_permitted_for(_view)
36
+ @permitted ||= @group.tabs.select { |page| page.permitted.call(@view) }.map { |page| Page.new(page, @view) }
37
+ end
38
+ end
39
+
40
+ def self.for(view)
41
+ env = view.request.env if view.respond_to?(:request)
42
+ return new(view) unless env
43
+
44
+ env[ENV_KEY] ||= new(view)
45
+ end
46
+
47
+ attr_reader :groups
48
+
49
+ def initialize(view)
50
+ @groups = KeystoneUi.configuration.navigation_groups.map { |group| Group.new(group, view) }
51
+ end
52
+ end
53
+ end
54
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module KeystoneUi
4
4
  module App
5
- VERSION = "0.9.1"
5
+ VERSION = "0.9.2"
6
6
  end
7
7
  end
@@ -4,6 +4,7 @@ require "turbo-rails"
4
4
  require "keystone_ui/app/version"
5
5
  require "keystone_ui/app/configuration"
6
6
  require "keystone_ui/app/area_choices"
7
+ require "keystone_ui/app/person_groups"
7
8
  require "keystone_ui/app/engine"
8
9
 
9
10
  module KeystoneUi
@@ -17,7 +18,7 @@ module KeystoneUi
17
18
  end
18
19
 
19
20
  def self.areas_open_to(view)
20
- groups = KeystoneUi.configuration.navigation_groups.select { |group| group.tabs_permitted_for(view).any? }.map(&:label)
21
+ groups = PersonGroups.for(view).groups.select { |group| group.tabs_permitted_for(view).any? }.map(&:label)
21
22
  configuration.app_areas.select { |area| area.groups.intersect?(groups) }
22
23
  end
23
24
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: keystone_ui-app
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Schneider
@@ -133,6 +133,7 @@ files:
133
133
  - lib/keystone_ui/app/configuration.rb
134
134
  - lib/keystone_ui/app/current_section.rb
135
135
  - lib/keystone_ui/app/engine.rb
136
+ - lib/keystone_ui/app/person_groups.rb
136
137
  - lib/keystone_ui/app/shell_check.rb
137
138
  - lib/keystone_ui/app/version.rb
138
139
  homepage: https://github.com/DYB-Development/keystone_ui-app