glib-web 0.12.2 → 0.14.1

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: bab29dba5e648d50d03a57bac0904d97aaadfe5f0e5b1a9e01b123fbf6e2c787
4
- data.tar.gz: 245ce0246212f41d87842659d68d83f2634282f9b803e09a278ef051cbfcc962
3
+ metadata.gz: 428d8e7c5b2377d553b7111255fc1de970a80fd6fdbb29671bf98245d79561ef
4
+ data.tar.gz: 824a27ddd5033098ae2f08e59d45595152453c7f2450d8e2fc0dadf17563fced
5
5
  SHA512:
6
- metadata.gz: 671310954e5011e2867d7d1c330c5b218c9af9c36617a81f9461eca1d3f32cc9436fdec208ca1d19b24e73f3eaf0216c0f4f6d5954fc8cc782abde757ae78194
7
- data.tar.gz: fdc79df0a84f2ecec8e599209dbefe87f1709e85d07dffb3fbca4cefdfcd571e6108aa76fc0410576f98a128eee92848458dae6bb53abe05b655b996b08761ec
6
+ metadata.gz: 76f06563453f27f15eb7ca895248c407f7dc0820b506a4a08507e75e679d729d1e4775217c78e0a3cb07fc0738c481f33d816258a59755b930370bff290b02d1
7
+ data.tar.gz: f78f910dcafc532896840230306dab2b09614478d12c01d67aed40c0246bfdd7feded9377fd2e656a2a8e587b50a9aacac1babb3bccb0420c2e34d23a8487d40
@@ -129,13 +129,7 @@ module Glib
129
129
 
130
130
  def self.color(propName)
131
131
  define_method(propName) do |value|
132
- if (value = value&.to_s)
133
- if !Rails.env.production?
134
- if !value.match /^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i
135
- raise "Invalid color: #{value}"
136
- end
137
- end
138
-
132
+ if (value = to_color(value))
139
133
  json.set! propName, value
140
134
  end
141
135
  end
@@ -162,7 +156,7 @@ module Glib
162
156
 
163
157
  def self.string(propName, options = {})
164
158
  define_method(propName) do |value|
165
- str = value&.to_s
159
+ str = to_string(value)
166
160
  instance_variable_set("@#{propName}", str) if options[:cache]
167
161
  json.set! propName, str
168
162
  end
@@ -264,6 +258,15 @@ module Glib
264
258
  end
265
259
  end
266
260
 
261
+ def self.badgeable
262
+ define_method(:badge) do |value|
263
+ json.badge do
264
+ json.text to_string(value[:text])
265
+ json.backgroundColor to_color(value[:backgroundColor])
266
+ end
267
+ end
268
+ end
269
+
267
270
  def self.action(propName)
268
271
  define_method(propName) do |value|
269
272
  json.set!(propName) { value.call(page.action_builder) }
@@ -318,6 +321,26 @@ module Glib
318
321
  # To be overridden
319
322
  end
320
323
 
324
+ ### Reusable value converters
325
+
326
+ def to_string(value)
327
+ value&.to_s
328
+ end
329
+
330
+ def to_color(value)
331
+ value = value&.to_s
332
+
333
+ if value
334
+ if !Rails.env.production?
335
+ if !value.match /^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$/i
336
+ raise "Invalid color: #{value}"
337
+ end
338
+ end
339
+ end
340
+
341
+ value
342
+ end
343
+
321
344
  end
322
345
  end
323
346
  end
@@ -0,0 +1,9 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+ module Components
3
+
4
+ class Update < Action
5
+ string :targetId
6
+ views :views
7
+ end
8
+ end
9
+ end
@@ -22,6 +22,9 @@ class Glib::JsonUi::ActionBuilder
22
22
  end
23
23
  end
24
24
 
25
+ class Get < AbstractHttp
26
+ end
27
+
25
28
  class Post < AbstractHttp
26
29
  end
27
30
 
@@ -31,8 +34,8 @@ class Glib::JsonUi::ActionBuilder
31
34
  end
32
35
 
33
36
  class Delete < AbstractHttp
34
- # string :url, cache: true
35
- # hash :formData
37
+ # string :url, cache: true
38
+ # hash :formData
36
39
  end
37
40
 
38
41
  end
@@ -2,7 +2,10 @@ class Glib::JsonUi::ActionBuilder
2
2
  module Tours
3
3
 
4
4
  class Start < Action
5
+ # https://kamranahmed.info/driver.js/
6
+ # Driver definition
5
7
  hash :options
8
+ # Step definition
6
9
  array :steps
7
10
  int :startFrom
8
11
  end
@@ -39,12 +39,12 @@ module Glib
39
39
  end
40
40
 
41
41
  class Button < MenuItem
42
+ badgeable
43
+
42
44
  string :text
43
45
  icon :icon
44
46
  action :onClick
45
47
  bool :disabled
46
- color :badgeColor
47
- string :badgeContent
48
48
  singleton_array :styleClass, :styleClasses
49
49
 
50
50
  def childButtons(block)
@@ -10,14 +10,31 @@ module Glib
10
10
  end
11
11
  end
12
12
 
13
+ def json_ui_response_with_view(json)
14
+ json.analytics do
15
+ json.disabled true
16
+ end
17
+
18
+ json.onResponse do
19
+ response = Response.new(json, self, true)
20
+ yield response.action_builder
21
+ end
22
+ end
23
+
13
24
  class Response
14
- attr_reader :action_builder
25
+ attr_reader :action_builder, :view_builder, :list_section_builder, :table_section_builder, :current_form
15
26
 
16
- def initialize(json, context)
27
+ def initialize(json, context, with_view_builder = false)
17
28
  @json = json
18
29
  @context = context
19
30
 
20
31
  @action_builder = ActionBuilder.new(json, self, false)
32
+
33
+ if with_view_builder
34
+ @view_builder = ViewBuilder.new(json, self, true)
35
+ @list_section_builder = ListBuilders::Section.new(json, self, ListBuilders::Template.new(json, self))
36
+ @table_section_builder = TableBuilders::Section.new(json, self, TableBuilders::Template.new(json, self))
37
+ end
21
38
  end
22
39
  end
23
40
  end
@@ -24,6 +24,7 @@ module Glib
24
24
  end
25
25
 
26
26
  class View < JsonUiElement
27
+ string :compId
27
28
  string :id
28
29
  length :width
29
30
  length :height
@@ -126,6 +127,8 @@ module Glib
126
127
  end
127
128
 
128
129
  class Image < View
130
+ badgeable
131
+
129
132
  string :url
130
133
  string :base64Data
131
134
  action :onClick
@@ -133,12 +136,16 @@ module Glib
133
136
  end
134
137
 
135
138
  class Avatar < View
139
+ badgeable
140
+
136
141
  int :size
137
142
  string :url
138
143
  action :onClick
139
144
  end
140
145
 
141
146
  class Icon < View
147
+ badgeable
148
+
142
149
  # TODO: Remove later. Deprecated.
143
150
  icon :spec
144
151
 
@@ -170,6 +177,8 @@ module Glib
170
177
  # end
171
178
 
172
179
  class Button < View
180
+ badgeable
181
+
173
182
  icon :icon, cache: true
174
183
  string :text, cache: true
175
184
  action :onClick
@@ -206,11 +215,10 @@ module Glib
206
215
  end
207
216
 
208
217
  class Chip < View
218
+ badgeable
219
+
209
220
  string :text
210
221
  action :onClick
211
-
212
- string :badgeContent
213
- color :badgeColor
214
222
  end
215
223
 
216
224
  class Calendar < View
@@ -52,13 +52,11 @@ if local_assigns[:top_nav] || json_ui_app_is_web?
52
52
  action.windows_open url: json_ui_garage_url
53
53
  end
54
54
 
55
- menu.button icon: 'refresh', text: 'Reload', onClick: ->(action) do
55
+ menu.button icon: 'refresh', text: 'Reload', badge: { text: '!' }, onClick: ->(action) do
56
56
  action.windows_reload
57
57
  end
58
58
 
59
- # Consider deprecating icon badge
60
- # menu.button icon: { name: 'zoom_in', badge: '!' }, text: 'Diagnostics', onClick: ->(action) do
61
- menu.button icon: 'zoom_in', text: 'Diagnostics', badgeContent: '!', onClick: ->(action) do
59
+ menu.button icon: { name: 'zoom_in', badge: { text: '?', backgroundColor: '#00ffff' } }, text: 'Diagnostics', onClick: ->(action) do
62
60
  action.dialogs_alert message: %{
63
61
  Bundle ID: #{json_ui_app_bundle_id || '<unknown>'}
64
62
  App Version: #{json_ui_app_build_version || '<unknown>'}
@@ -0,0 +1,37 @@
1
+ json.title 'Forms'
2
+
3
+ page = json_ui_page json
4
+
5
+ render "#{@path_prefix}/nav_menu", json: json, page: page
6
+
7
+ # The form will be automatically injected into the window.
8
+ page.template 'full_window_form'
9
+
10
+ page.scroll padding: glib_json_padding_body, childViews: ->(form) do
11
+ form.fields_text name: 'user[name]', width: 'matchParent', label: 'Name'
12
+ form.fields_password name: 'user[password]', width: 'matchParent', label: 'Password'
13
+
14
+ # form.panels_split width: 'matchParent', content: ->(split) do
15
+ # split.left childViews: ->(left) do
16
+ # left.panels_horizontal height: 'matchParent', align: 'middle', childViews: ->(horizontal) do
17
+ # case params[:mode]
18
+ # when 'dialog'
19
+ # horizontal.fields_hidden name: 'mode', value: 'dialog'
20
+ # horizontal.button styleClass: 'link', text: 'cancel', onClick: ->(action) { action.dialogs_close }
21
+ # when 'dialog_reload'
22
+ # horizontal.button styleClass: 'link', text: 'back', onClick: ->(action) do
23
+ # render 'json_ui/garage/actions/dialogs_show', json: json, action: action, dialog_mode: :reload
24
+ # end
25
+ # end
26
+ # end
27
+ # end
28
+ # split.right childViews: ->(right) do
29
+ # # right.button text: 'Submit', onClick: ->(action) { action.forms_submit }
30
+ # right.fields_submit text: 'Submit'
31
+ # end
32
+ # end
33
+ end
34
+
35
+ page.footer padding: glib_json_padding_body, backgroundColor: '#b3bac2', childViews: ->(footer) do
36
+ footer.fields_submit text: 'Submit'
37
+ end
@@ -91,6 +91,11 @@ page.list sections: [
91
91
  action.windows_open url: json_ui_garage_url(path: 'forms/styled_boxes')
92
92
  end
93
93
  end
94
+ section.rows builder: ->(template) do
95
+ template.thumbnail title: 'Full Window', onClick: ->(action) do
96
+ action.windows_open url: json_ui_garage_url(path: 'forms/full_window_form')
97
+ end
98
+ end
94
99
  end, ->(section) do
95
100
  section.header padding: glib_json_padding_list, childViews: ->(header) do
96
101
  header.h2 text: 'Web Only'
@@ -49,7 +49,7 @@ page.scroll childViews: ->(scroll) do
49
49
  end
50
50
 
51
51
  form.spacer height: 20
52
- form.h1 text: 'Radio Group'
52
+ form.h2 text: 'Radio Group'
53
53
  form.fields_radioGroup \
54
54
  name: 'user[seniority]',
55
55
  value: 'show',
@@ -65,6 +65,18 @@ page.scroll childViews: ->(scroll) do
65
65
  end
66
66
  end
67
67
 
68
+ form.spacer height: 20
69
+ form.h2 text: 'Text'
70
+ form.fields_text \
71
+ name: 'user[video_url]',
72
+ width: 'matchParent',
73
+ onChange: ->(action) do
74
+ action.sheets_select message: 'Submit data?', buttons: ->(menu) do
75
+ menu.button text: 'Yes, submit', onClick: ->(subaction) do
76
+ action.forms_submit
77
+ end
78
+ end
79
+ end
68
80
  end
69
81
 
70
82
  end
@@ -1,29 +1,29 @@
1
1
  json.title 'Pages'
2
2
 
3
- json_ui_page json do |page|
4
- render "#{@path_prefix}/nav_menu", json: json, page: page
3
+ page = json_ui_page json
5
4
 
6
- page.template 'fullWidth'
5
+ render "#{@path_prefix}/nav_menu", json: json, page: page
7
6
 
8
- page.header childViews: ->(header) do
9
- header.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
10
- vertical.h1 text: 'Header'
11
- end
12
- header.spacer height: 10
7
+ page.template 'fullWidth'
8
+
9
+ page.header childViews: ->(header) do
10
+ header.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
11
+ vertical.h1 text: 'Header'
13
12
  end
13
+ header.spacer height: 10
14
+ end
14
15
 
15
- page.footer childViews: ->(footer) do
16
- footer.spacer height: 10
17
- footer.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
18
- vertical.h1 text: 'Footer'
19
- end
16
+ page.footer childViews: ->(footer) do
17
+ footer.spacer height: 10
18
+ footer.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
19
+ vertical.h1 text: 'Footer'
20
20
  end
21
+ end
21
22
 
22
- page.body childViews: ->(scroll) do
23
- scroll.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
24
- (1..100).each do |index|
25
- vertical.label text: 'Content'
26
- end
23
+ page.body childViews: ->(scroll) do
24
+ scroll.panels_vertical width: 'matchParent', styleClass: 'card', padding: glib_json_padding_body, childViews: ->(vertical) do
25
+ (1..100).each do |index|
26
+ vertical.label text: 'Content'
27
27
  end
28
28
  end
29
29
  end
@@ -7,6 +7,20 @@ json_ui_page json do |page|
7
7
  scroll.panels_column lg: { cols: 8 }, childViews: ->(column) do
8
8
  column.h2 text: 'Tab Bar with Badge'
9
9
  column.tabBar buttons: ->(menu) do
10
+ badges = [
11
+ {
12
+ text: nil,
13
+ backgroundColor: nil
14
+ },
15
+ {
16
+ text: 8,
17
+ backgroundColor: '#272551'
18
+ },
19
+ {
20
+ text: '⭐⭐⭐',
21
+ backgroundColor: '#008000'
22
+ }
23
+ ]
10
24
  {
11
25
  'FIRST' => 'home',
12
26
  'SECOND' => 'schedule',
@@ -15,8 +29,7 @@ json_ui_page json do |page|
15
29
  menu.button \
16
30
  icon: icon,
17
31
  text: text,
18
- badgeContent: [nil, 8, '⭐⭐⭐'][index],
19
- badgeColor: [nil, '#272551', '#008000'][index],
32
+ badge: badges[index],
20
33
  disabled: params[:tab].to_i == index,
21
34
  onClick: ->(action) do
22
35
  action.windows_reload \
@@ -11,13 +11,20 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
11
11
  action.dialogs_alert message: 'Perform action'
12
12
  end
13
13
 
14
- scroll.button text: 'Buton with build-in classes', styleClasses: ['rounded', 'outlined', 'tile', 'depressed'], onClick: ->(action) do
14
+ scroll.spacer height: 10
15
+ scroll.button text: 'Button with built-in classes', styleClasses: ['rounded', 'outlined', 'tile', 'depressed'], onClick: ->(action) do
15
16
  action.dialogs_alert message: 'Perform action'
16
17
  end
17
18
 
18
- scroll.button icon: 'info', text: 'Button with Icon and Tooltip', tooltip: { text: 'Tooltip text' }, onClick: ->(action) do
19
- action.dialogs_alert message: 'Perform action'
20
- end
19
+ scroll.spacer height: 10
20
+ scroll.button \
21
+ icon: 'info',
22
+ text: 'Button with Icon and Tooltip',
23
+ tooltip: { text: 'Tooltip text' },
24
+ badge: { text: '3' },
25
+ onClick: ->(action) do
26
+ action.dialogs_alert message: 'Perform action'
27
+ end
21
28
  scroll.spacer height: 20
22
29
 
23
30
  scroll.button \
@@ -38,7 +45,7 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
38
45
  action.dialogs_alert message: 'Perform action'
39
46
  end
40
47
  scroll.spacer height: 10
41
- scroll.chip text: 'With Badge', badgeContent: '99'
48
+ scroll.chip text: 'With Badge', badge: { text: '99' }
42
49
 
43
50
  scroll.spacer height: 20
44
51
  scroll.h2 text: 'Switch'
@@ -12,4 +12,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
12
12
  scroll.h2 text: 'Icon with color'
13
13
  scroll.icon name: 'home', color: '#9370DB'
14
14
  scroll.icon name: 'home', color: '#9370DB80'
15
+
16
+ scroll.spacer height: 20
17
+ scroll.h2 text: 'Icon with badge'
18
+ scroll.icon name: 'home', badge: { text: '22', backgroundColor: '#00ff00' }
15
19
  end
@@ -13,10 +13,11 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
13
13
  url: glib_json_image_avatar_url,
14
14
  tooltip: { text: 'This is a tooltip' }
15
15
 
16
- # scroll.spacer height: 20
17
- # scroll.h2 text: 'Icon'
18
- # scroll.spacer height: 6
19
- # scroll.icon spec: 'info'
16
+ scroll.h2 text: 'Avatar with badge'
17
+ scroll.spacer height: 6
18
+ scroll.avatar \
19
+ url: glib_json_image_avatar_url,
20
+ badge: { text: '1', backgroundColor: '#0000ff' }
20
21
 
21
22
  scroll.spacer height: 20
22
23
  scroll.h2 text: 'Image with base64 data'
@@ -46,9 +47,9 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
46
47
  scroll.image url: glib_json_image_standard_url
47
48
 
48
49
  scroll.spacer height: 20
49
- scroll.h2 text: 'Original size'
50
+ scroll.h2 text: 'Original size with badge'
50
51
  scroll.spacer height: 6
51
- scroll.image url: small_image_url
52
+ scroll.image url: small_image_url, badge: { text: '1', backgroundColor: '#0000ff' }
52
53
 
53
54
  # Reference: https://docs.imgix.com/apis/url/size/fit#clip
54
55
  scroll.spacer height: 20
@@ -19,6 +19,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
19
19
  end
20
20
  end
21
21
 
22
+ f.spacer width: 10
23
+
22
24
  # For testing: https://developers.facebook.com/tools/debug/
23
25
  f.shareButton \
24
26
  network: 'facebook',
@@ -28,6 +30,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
28
30
  facebookQuote: 'This is a quote',
29
31
  text: 'Facebook'
30
32
 
33
+ f.spacer width: 10
34
+
31
35
  f.shareButton \
32
36
  network: 'linkedin',
33
37
  url: 'https://www.google.com',
@@ -35,6 +39,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
35
39
  description: 'This is a description',
36
40
  text: 'LinkedIn'
37
41
 
42
+ f.spacer width: 10
43
+
38
44
  f.shareButton \
39
45
  network: 'whatsapp',
40
46
  url: 'https://www.google.com',
@@ -42,6 +48,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
42
48
  description: 'This is a description',
43
49
  text: 'WhatsApp'
44
50
 
51
+ f.spacer width: 10
52
+
45
53
  f.shareButton \
46
54
  network: 'telegram',
47
55
  url: 'https://www.google.com',
@@ -59,18 +67,24 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
59
67
  title: 'This is a title',
60
68
  description: 'This is a description'
61
69
 
70
+ f.spacer width: 10
71
+
62
72
  f.shareButton \
63
73
  network: 'linkedin',
64
74
  url: 'https://www.google.com',
65
75
  title: 'This is a title',
66
76
  description: 'This is a description'
67
77
 
78
+ f.spacer width: 10
79
+
68
80
  f.shareButton \
69
81
  network: 'whatsapp',
70
82
  url: 'https://www.google.com',
71
83
  title: 'This is a title',
72
84
  description: 'This is a description'
73
85
 
86
+ f.spacer width: 10
87
+
74
88
  f.shareButton \
75
89
  network: 'telegram',
76
90
  url: 'https://www.google.com',
@@ -89,6 +103,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
89
103
  description: 'This is a description',
90
104
  text: 'Facebook'
91
105
 
106
+ v.spacer height: 10
107
+
92
108
  v.shareButton \
93
109
  network: 'linkedin',
94
110
  url: 'https://www.google.com',
@@ -96,6 +112,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
96
112
  description: 'This is a description',
97
113
  text: 'LinkedIn'
98
114
 
115
+ v.spacer height: 10
116
+
99
117
  v.shareButton \
100
118
  width: 'matchParent',
101
119
  network: 'whatsapp',
@@ -104,6 +122,8 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
104
122
  description: 'This is a description',
105
123
  text: 'WhatsApp'
106
124
 
125
+ v.spacer height: 10
126
+
107
127
  v.shareButton \
108
128
  width: 'matchParent',
109
129
  network: 'telegram',
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glib-web
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.2
4
+ version: 0.14.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -92,6 +92,7 @@ files:
92
92
  - app/helpers/glib/json_ui/abstract_builder.rb
93
93
  - app/helpers/glib/json_ui/action_builder.rb
94
94
  - app/helpers/glib/json_ui/action_builder/commands.rb
95
+ - app/helpers/glib/json_ui/action_builder/components.rb
95
96
  - app/helpers/glib/json_ui/action_builder/dialogs.rb
96
97
  - app/helpers/glib/json_ui/action_builder/http.rb
97
98
  - app/helpers/glib/json_ui/action_builder/iap.rb
@@ -152,6 +153,7 @@ files:
152
153
  - app/views/json_ui/garage/forms/dynamic_select_data.json.jbuilder
153
154
  - app/views/json_ui/garage/forms/file_upload.json.jbuilder
154
155
  - app/views/json_ui/garage/forms/floating_submit.json.jbuilder
156
+ - app/views/json_ui/garage/forms/full_window_form.json.jbuilder
155
157
  - app/views/json_ui/garage/forms/generic_post.json.jbuilder
156
158
  - app/views/json_ui/garage/forms/index.json.jbuilder
157
159
  - app/views/json_ui/garage/forms/local_request.json.jbuilder