glib-web 0.5.4 → 0.5.11

Sign up to get free protection for your applications and to get access to all the features.
Files changed (44) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/concerns/glib/json/ui.rb +7 -0
  3. data/app/helpers/glib/app_feature_support_helper.rb +16 -0
  4. data/app/helpers/glib/json_ui/abstract_builder.rb +9 -3
  5. data/app/helpers/glib/json_ui/action_builder.rb +36 -6
  6. data/app/helpers/glib/json_ui/action_builder/windows.rb +1 -0
  7. data/app/helpers/glib/json_ui/page_helper.rb +13 -5
  8. data/app/helpers/glib/json_ui/response_helper.rb +1 -1
  9. data/app/helpers/glib/json_ui/styling_helper.rb +22 -0
  10. data/app/helpers/glib/json_ui/view_builder.rb +16 -16
  11. data/app/helpers/glib/json_ui/view_builder/fields.rb +9 -1
  12. data/app/helpers/glib/json_ui/view_builder/panels.rb +2 -0
  13. data/app/helpers/glib/urls_helper.rb +7 -0
  14. data/app/policies/glib/application_policy.rb +27 -30
  15. data/app/views/json_ui/garage/actions/index.json.jbuilder +2 -2
  16. data/app/views/json_ui/garage/forms/dynamic_group.json.jbuilder +9 -18
  17. data/app/views/json_ui/garage/forms/pickers.json.jbuilder +6 -3
  18. data/app/views/json_ui/garage/forms/show_hide.json.jbuilder +20 -3
  19. data/app/views/json_ui/garage/forms/styled_boxes.json.jbuilder +4 -1
  20. data/app/views/json_ui/garage/forms/text_validation.json.jbuilder +1 -1
  21. data/app/views/json_ui/garage/notifications/web_socket.json.jbuilder +19 -21
  22. data/app/views/json_ui/garage/pages/index.json.jbuilder +11 -0
  23. data/app/views/json_ui/garage/pages/layout.json.jbuilder +12 -13
  24. data/app/views/json_ui/garage/pages/nav_buttons.json.jbuilder +28 -16
  25. data/app/views/json_ui/garage/pages/nested_scroll.json.jbuilder +40 -0
  26. data/app/views/json_ui/garage/panels/carousel.json.jbuilder +24 -3
  27. data/app/views/json_ui/garage/tables/autoload_as_needed.json.jbuilder +37 -0
  28. data/app/views/json_ui/garage/tables/index.json.jbuilder +3 -0
  29. data/app/views/json_ui/garage/views/icons.json.jbuilder +22 -0
  30. data/app/views/json_ui/garage/views/images.json.jbuilder +4 -4
  31. data/app/views/json_ui/garage/views/index.json.jbuilder +3 -3
  32. data/lib/glib/json_crawler.rb +2 -0
  33. data/lib/glib/json_crawler/action_crawler.rb +4 -1
  34. data/lib/glib/json_crawler/action_crawlers/action_http.rb +2 -5
  35. data/lib/glib/json_crawler/action_crawlers/forms_submit.rb +2 -2
  36. data/lib/glib/json_crawler/action_crawlers/menu.rb +12 -0
  37. data/lib/glib/json_crawler/action_crawlers/nav_initiate.rb +3 -1
  38. data/lib/glib/json_crawler/action_crawlers/run_multiple.rb +13 -0
  39. data/lib/glib/json_crawler/action_crawlers/windows_open.rb +3 -0
  40. data/lib/glib/json_crawler/http.rb +3 -2
  41. data/lib/glib/json_crawler/router.rb +35 -28
  42. data/lib/glib/test_helpers.rb +4 -4
  43. metadata +8 -2
  44. data/app/views/json_ui/garage/views/carousels.json.jbuilder +0 -37
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c258b37bbad81871f329c41e5b854b5b6563fb4f
4
- data.tar.gz: 3e8d5f94006a46084869252b667d0c9e405de569
3
+ metadata.gz: 9c409da37352d6e9066f4b7895d76c3cba5e81f2
4
+ data.tar.gz: 7116d6e9e13cc00d98811010acb550749acdcbba
5
5
  SHA512:
6
- metadata.gz: bece2c2bae109009e5b468e9e43cd52591b5c367977a8fec1b623e27876efd28d25a1432bde847943eb310fe62bef9f4e3b1b38ea93924f2767cb9e1a42c4477
7
- data.tar.gz: 756e23d1771b4f1dae8eebe2d4d0f0c4f5397fc8762baac96c2c5bfe7ffc73a6fcab6cad2575d8aae760d84570edffeb456231d70a815918c234a8e5153895bf
6
+ metadata.gz: 5ce3e630395c565eb252a653db28eb026388100082105109d4f2a380f19bab6d0465bd5d04ff65ff0da4c729c4273a08d800c2e8db614678767349ef279a8422
7
+ data.tar.gz: cb22a75b02ed382066e4d6060026600093cd543032c0d9c0679f64628750068a8ffa3dca4070995907040db5871b75ae171a4a5172ec445aa4e762357bd73235
@@ -31,6 +31,13 @@ module Glib::Json::Ui
31
31
  @__json_ui_activated
32
32
  end
33
33
 
34
+ def json_ui_page_lifecycle_prop(name)
35
+ if (hash = json_transformation_start).is_a?(Hash) && hash['body'] # A valid page
36
+ hash[name] ||= { 'action' => 'runMultiple', 'childActions' => [] }
37
+ hash[name]['childActions']
38
+ end
39
+ end
40
+
34
41
  def __json_ui_start(options)
35
42
  @__json_ui_activated = false
36
43
  @__json_ui_rendering = nil
@@ -0,0 +1,16 @@
1
+ module Glib
2
+ module AppFeatureSupportHelper
3
+ def glib_app_feature_supported?(name, app_version, dictionary)
4
+ device = (app_device_os || :default).to_sym
5
+
6
+ version = dictionary[name.to_sym].try(:[], device)
7
+ except = dictionary[name.to_sym].try(:[], :except).try(:[], device)
8
+
9
+ !version.nil? && (version == :all || glib_app_version_gte(version, app_version)) && (except.nil? || except.to_s != app_version)
10
+ end
11
+
12
+ def glib_app_version_gte(feature_version, app_version)
13
+ app_version.blank? || Gem::Version.new(app_version) >= Gem::Version.new(feature_version)
14
+ end
15
+ end
16
+ end
@@ -13,7 +13,7 @@ module Glib
13
13
  str.slice(0,1).capitalize + str.slice(1..-1)
14
14
  end
15
15
 
16
- def add_singleton_element type, name, *args
16
+ def add_singleton_element(type, name, *args)
17
17
  name_components = name.to_s.split('_')
18
18
  json.set! type, "#{name_components.join('/')}" if type
19
19
  args = [yield] if block_given?
@@ -22,7 +22,7 @@ module Glib
22
22
  "#{self.class.name}::#{name_components.map{ |str| capitalize_first_letter_and_leave_others_alone(str) }.join('::')}".constantize.new(json, @page).props(*args)
23
23
  end
24
24
 
25
- def add_element_to_array type, name, *args
25
+ def add_element_to_array(type, name, *args)
26
26
  json.child! do
27
27
  add_singleton_element type, name, *args
28
28
  end
@@ -69,6 +69,12 @@ module Glib
69
69
 
70
70
  private
71
71
 
72
+ def self.any(propName)
73
+ define_method(propName) do |value|
74
+ json.set! propName, value
75
+ end
76
+ end
77
+
72
78
  def self.date(propName)
73
79
  define_method(propName) do |value|
74
80
  json.set! propName, value&.to_date
@@ -191,7 +197,7 @@ module Glib
191
197
  json.set!(propName) do
192
198
  if name
193
199
  data[:material] ||= {}
194
- data[:material][:name] = name
200
+ data[:material][:name] = name
195
201
  end
196
202
 
197
203
  if (material = data[:material])
@@ -1,8 +1,18 @@
1
1
  module Glib
2
2
  module JsonUi
3
3
  class ActionBuilder < AbstractBuilder
4
- def method_missing m, *args
5
- add_singleton_element_v1 'action', m, *args
4
+ def initialize(json, page, multiple)
5
+ super(json, page)
6
+
7
+ @multiple = multiple
8
+ end
9
+
10
+ def method_missing(m, *args)
11
+ if @multiple
12
+ add_element_to_array_v1 'action', m, *args
13
+ else
14
+ add_singleton_element_v1 'action', m, *args
15
+ end
6
16
  end
7
17
 
8
18
  class Action < JsonUiElement
@@ -38,19 +48,31 @@ module Glib
38
48
 
39
49
  ### Action definitions
40
50
 
51
+ class RunMultiple < Action
52
+ def childActions(block)
53
+ json.childActions do
54
+ block.call ActionBuilder.new(json, page, true)
55
+ end
56
+ end
57
+ end
58
+
41
59
  module Forms
42
60
  class Submit < Action
43
61
  end
44
-
45
62
  end
46
63
 
47
- # Consider deprecating this. See Data
48
64
  module Auth
49
65
  class SaveCsrfToken < Action
50
66
  string :token
51
67
  action :onSave
52
68
  end
69
+ end
53
70
 
71
+ module Analytics
72
+ class LogEvent < Action
73
+ string :name
74
+ hash :params
75
+ end
54
76
  end
55
77
 
56
78
  module Timeouts
@@ -59,6 +81,10 @@ module Glib
59
81
  action :onTimeout
60
82
  end
61
83
 
84
+ # FUTURE
85
+ class Remove < Action
86
+ end
87
+
62
88
  # FUTURE
63
89
  class Clear < Action
64
90
  end
@@ -66,11 +92,15 @@ module Glib
66
92
 
67
93
  # FUTURE
68
94
  module Data
69
- class SaveCsrfToken < Action
70
- string :token
95
+ class Save < Action
96
+ string :key
97
+ string :value
71
98
  action :onSave
72
99
  end
73
100
 
101
+ class Remove < Action
102
+ end
103
+
74
104
  class Clear < Action
75
105
  end
76
106
  end
@@ -2,6 +2,7 @@ class Glib::JsonUi::ActionBuilder
2
2
  module Windows
3
3
  class Close < Action
4
4
  action :onClose
5
+ # action :onAfterClose
5
6
  end
6
7
 
7
8
  class CloseAll < Action
@@ -35,11 +35,16 @@ module Glib
35
35
  # json.attributes!
36
36
  # end
37
37
 
38
- def json_ui_section(json, &block)
38
+ def json_ui_section(json)
39
39
  @__json_ui_section ||= Page.new(json, self)
40
40
  @__json_ui_section.list_section_builder
41
41
  end
42
42
 
43
+ def json_ui_action(json)
44
+ @__json_ui_section ||= Page.new(json, self)
45
+ @__json_ui_section.action_builder
46
+ end
47
+
43
48
  class Page
44
49
  attr_reader :json, :context, :view_builder, :action_builder, :menu_builder
45
50
  attr_reader :list_section_builder, :table_section_builder, :drawer_content_builder, :split_content_builder
@@ -52,7 +57,7 @@ module Glib
52
57
  @context = context
53
58
 
54
59
  @view_builder = ViewBuilder.new(json, self, true)
55
- @action_builder = ActionBuilder.new(json, self)
60
+ @action_builder = ActionBuilder.new(json, self, false)
56
61
  @menu_builder = MenuBuilder.new(json, self)
57
62
 
58
63
  @list_section_builder = ListBuilders::Section.new(json, self, ListBuilders::Template.new(json, self))
@@ -99,9 +104,12 @@ module Glib
99
104
  # options[:leftItems]&.call @menu_builder
100
105
  # end
101
106
  # json.logoUrl "http://localhost:3000/assets/logo_dark-02d9b6a91fdbf22515da7b921d31367b70696214415f6789d2f90232e4a287b7.svg"
102
- json.rightItems do
103
- options[:rightItems]&.call @menu_builder
104
- end
107
+
108
+ # json.rightItems do
109
+ # options[:rightItems]&.call @menu_builder
110
+ # end
111
+
112
+ @view_builder.add_singleton_view('appBar', options)
105
113
  end
106
114
  end
107
115
 
@@ -15,7 +15,7 @@ module Glib
15
15
  @json = json
16
16
  @context = context
17
17
 
18
- @action_builder = ActionBuilder.new(json, self)
18
+ @action_builder = ActionBuilder.new(json, self, false)
19
19
  end
20
20
  end
21
21
  end
@@ -1,6 +1,9 @@
1
1
  module Glib
2
2
  module JsonUi
3
3
  module StylingHelper
4
+
5
+ ### Padding
6
+
4
7
  def glib_json_padding_body
5
8
  { top: 12, left: 20, right: 20, bottom: 12 }
6
9
  end
@@ -9,6 +12,12 @@ module Glib
9
12
  { top: 12, bottom: 12, left: 16, right: 16 }
10
13
  end
11
14
 
15
+ ###
16
+
17
+
18
+
19
+ ### Image
20
+
12
21
  def glib_json_image_standard_url
13
22
  'https://cdn-images-1.medium.com/max/1200/1*Qc0XxYm-qAZL-7tjjlNfrg.png'
14
23
  end
@@ -20,6 +29,19 @@ module Glib
20
29
  def glib_json_image_blob_key
21
30
  'o6CKzNt67PWnkPdUEnWMt7pr'
22
31
  end
32
+
33
+ ###
34
+
35
+
36
+
37
+ ### Color
38
+
39
+ def glib_color_panel_background
40
+ '#b3bac2'
41
+ end
42
+
43
+ ###
44
+
23
45
  end
24
46
  end
25
47
  end
@@ -15,6 +15,10 @@ module Glib
15
15
  end
16
16
  end
17
17
 
18
+ def add_singleton_view(name, *args)
19
+ add_singleton_element 'view', name, *args
20
+ end
21
+
18
22
  def method_missing(m, *args)
19
23
  add_view m, *args
20
24
  end
@@ -152,26 +156,22 @@ module Glib
152
156
  block.call page.menu_builder
153
157
  end
154
158
  end
159
+ end
155
160
 
156
- # Should be deprecated
157
- # def tabButtons(block)
158
- # json.tabButtons do
159
- # block.call page.menu_builder
160
- # end
161
- # end
162
-
163
- # def options(options)
164
- # current_url = page.context.request.base_url + page.context.request.fullpath
161
+ class AppBar < View
162
+ color :color
165
163
 
166
- # buttons ->(menu) do
167
- # options.each do |tab|
168
- # menu.button text: tab[:text], disabled: tab[:url] == current_url, onClick: ->(action) do
169
- # action.windows_reload url: tab[:url]
170
- # end
171
- # end
164
+ # def leftButtons(block)
165
+ # json.leftButtons do
166
+ # block.call page.menu_builder
172
167
  # end
173
168
  # end
174
169
 
170
+ def rightButtons(block)
171
+ json.rightButtons do
172
+ block.call page.menu_builder
173
+ end
174
+ end
175
175
  end
176
176
 
177
177
  class Datetime < View
@@ -182,4 +182,4 @@ module Glib
182
182
 
183
183
  end
184
184
  end
185
- end
185
+ end
@@ -103,7 +103,15 @@ class Glib::JsonUi::ViewBuilder
103
103
  end
104
104
 
105
105
  class Check < Text
106
- string :uncheckValue
106
+ any :uncheckValue
107
+ any :checkValue
108
+
109
+
110
+ def value(value)
111
+ @value = value if value != Glib::Value::DEFAULT
112
+ end
113
+
114
+ # Where possible, use value instead of this
107
115
  bool :checked
108
116
  end
109
117
 
@@ -123,6 +123,8 @@ class Glib::JsonUi::ViewBuilder
123
123
  hash :nextPage
124
124
  hash :export
125
125
  hash :import
126
+ action :onScrollToTop
127
+ action :onScrollToBottom
126
128
 
127
129
  def firstSection(block)
128
130
  json.sections [1] do
@@ -0,0 +1,7 @@
1
+ module Glib
2
+ module UrlsHelper
3
+ def glib_url_current(new_params)
4
+ url_for(params.to_unsafe_h.merge(new_params.merge(only_path: false)))
5
+ end
6
+ end
7
+ end
@@ -113,41 +113,17 @@ module Glib
113
113
  controller.policy_scope(record.class, policy_scope_class: policy_scope_class)
114
114
  end
115
115
 
116
- # TODO: Remove. Deprecated
117
- private # Used by child
118
- def public?
119
- true
120
- end
121
-
122
- private # Used by child
123
- def everyone
124
- true
125
- end
126
-
127
- # TODO: Deprecate `user()`
128
- private # Used by child
129
- def current_user
130
- user
131
- end
132
-
133
- # # TODO: Revise because it seems there is no justification for allowing owner to see any of the deleted entities, which include User, Guild, and Post
134
- # private # Used by child
135
- # def not_deleted_unless_owner_or_moderator?(&block)
136
- # block ||= lambda { |unused_arg| @user.moderator? }
137
- # !@record.deleted? || (@user && (@user.id == @record.user_owner_id || block.call(@record)))
138
- # end
139
-
140
- # private # Used by child
141
- # def not_deleted_unless_moderator?(&block)
142
- # block ||= lambda { |unused_arg| @user.moderator? }
143
- # !@record.deleted? || (@user && block.call(@record))
144
- # end
145
-
146
116
  public
147
117
  def self.args_builder
148
118
  Proc.new { |controller| [] }
149
119
  end
150
120
 
121
+ # TODO: Remove. Deprecated
122
+ # private # Used by child
123
+ # def public?
124
+ # true
125
+ # end
126
+
151
127
  class Scope
152
128
  attr_reader :user, :scope
153
129
 
@@ -156,9 +132,30 @@ module Glib
156
132
  @scope = scope
157
133
  end
158
134
 
135
+ # def current_user
136
+ # user
137
+ # end
138
+
139
+ # To be overridden
159
140
  def resolve
160
141
  scope.none
161
142
  end
162
143
  end
144
+
145
+ private # Used by child
146
+ def everyone
147
+ true
148
+ end
149
+
150
+ # def current_user
151
+ # user
152
+ # end
153
+
154
+ # TODO: Bad pattern. Implement explicit policy parameter instead.
155
+ # - E.g. can? :destroy, :service_subscription_auto_renewal, { service_subscription: @service_subscription }
156
+ # - E.g. super class: :service_subscription_auto_renewal, { service_subscription: @service_subscription }
157
+ def controller_var(name)
158
+ controller.instance_variable_get(:"@#{name}")
159
+ end
163
160
  end
164
161
  end
@@ -5,6 +5,8 @@ json_ui_page json do |page|
5
5
 
6
6
  page.list sections: [
7
7
  ->(section) do
8
+ render "#{@path_prefix}/actions/reload", section: section
9
+ end, ->(section) do
8
10
  render "#{@path_prefix}/actions/dialogs", section: section
9
11
  end, ->(section) do
10
12
  render "#{@path_prefix}/actions/snackbars", section: section
@@ -16,8 +18,6 @@ json_ui_page json do |page|
16
18
  render "#{@path_prefix}/actions/timeouts", section: section
17
19
  end, ->(section) do
18
20
  render "#{@path_prefix}/actions/http", section: section
19
- end, ->(section) do
20
- render "#{@path_prefix}/actions/reload", section: section
21
21
  end
22
22
  ]
23
23
  end