glib-web 0.2.10 → 0.2.11

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
  SHA1:
3
- metadata.gz: c3adb040610928c28643f3b77533d8801492d903
4
- data.tar.gz: 480c9264c9cf49e6ef035a298a910e512ee29a52
3
+ metadata.gz: 28296441cfbabaa9915d315407f81ee8ff6c3d0f
4
+ data.tar.gz: 44bafc6c627fe454fca1630bd9e3288f8c71b52c
5
5
  SHA512:
6
- metadata.gz: 0b0a885853c31a7f21d06abccca26f08d219f56fa70dd276746f3c21cc741a5803f28ca3ee69dfeb837a8e64772d8c008cf4c75990f721a96f39fc2a786ad979
7
- data.tar.gz: '095bbad9b01f7af4798bd1f813d5b5843af1c58ccd947956ca80982c228de9831e972f503e188c387cfced23459734b732531441529305b3b770218cfcc8d1a2'
6
+ metadata.gz: 6e043b39a9176c67a66027b2aed616d9c0b30c423047c72e3a48a075c5854ab85ae75e8ef50050b7a00faf6ad9afe535231e17b422642cf6c4c2a60e8be19ac0
7
+ data.tar.gz: e35a72b90a294c8cfee957d62788dab43a78801308cb17db43d0889ffce133e97175102456b70a4b5df6607ba3b10969719169dccafbb4d5758d7d585ff4c926
@@ -123,9 +123,11 @@ module Glib
123
123
  end
124
124
  end
125
125
 
126
- def self.string propName
127
- define_method(propName) do |value|
128
- json.set! propName, value&.to_s
126
+ def self.string propName, options = {}
127
+ define_method(propName) do |value|
128
+ str = value&.to_s
129
+ instance_variable_set("@#{propName}", str) if options[:cache]
130
+ json.set! propName, str
129
131
  end
130
132
  end
131
133
 
@@ -147,12 +149,15 @@ module Glib
147
149
  end
148
150
  end
149
151
 
150
- def self.icon propName
152
+ def self.icon propName, options = {}
151
153
  define_method(propName) do |value|
154
+
152
155
  if value.is_a?(Hash)
156
+ name = value[:name]
157
+
153
158
  json.set!(propName) do
154
159
  json.set value[:set] || 'material'
155
- json.name value[:name]
160
+ json.name name
156
161
 
157
162
  if (badge = value[:badge]).is_a?(Hash)
158
163
  json.badge badge
@@ -164,10 +169,15 @@ module Glib
164
169
 
165
170
  end
166
171
  else
172
+ name = value
173
+
167
174
  json.set!(propName) do
168
- json.name value
175
+ json.name name
169
176
  end
170
177
  end
178
+
179
+ instance_variable_set("@#{propName}", name) if options[:cache]
180
+
171
181
  end
172
182
  end
173
183
 
@@ -6,6 +6,34 @@ module Glib
6
6
  end
7
7
 
8
8
  class Action < JsonUiElement
9
+ def analytics(value)
10
+ if value.is_a?(String)
11
+ @analyticsEnabled = true
12
+ @analyticsId = value
13
+ else
14
+ @analyticsEnabled = value == true
15
+ end
16
+ end
17
+
18
+ # Override
19
+ def created
20
+ if @analyticsEnabled
21
+ suffix = @analyticsId
22
+ # TODO: recognize_path() needs `method` as a second argument for POST request
23
+ if suffix.nil? && @url && (route = Rails.application.routes.recognize_path(@url))
24
+ suffix = "#{route[:controller]}_#{route[:action]}"
25
+ end
26
+
27
+ if suffix
28
+ json.analytics do
29
+ json.track :event
30
+ json.nameSuffix suffix
31
+ end
32
+ end
33
+
34
+ end
35
+ end
36
+
9
37
  end
10
38
 
11
39
  ### Action definitions
@@ -33,7 +61,7 @@ module Glib
33
61
  end
34
62
 
35
63
  class Open < Action
36
- string :url
64
+ string :url, cache: true
37
65
  end
38
66
 
39
67
  # Consider renaming to ShowSnackbar
@@ -59,7 +87,7 @@ module Glib
59
87
  end
60
88
 
61
89
  class Open < Action
62
- string :url
90
+ string :url, cache: true
63
91
  end
64
92
 
65
93
  class OpenWeb < Action
@@ -67,7 +95,7 @@ module Glib
67
95
  end
68
96
 
69
97
  class Reload < Action
70
- string :url
98
+ string :url, cache: true
71
99
  end
72
100
  end
73
101
 
@@ -93,17 +121,17 @@ module Glib
93
121
 
94
122
  module Http
95
123
  class Post < Action
96
- string :url
124
+ string :url, cache: true
97
125
  hash :formData
98
126
  end
99
127
 
100
128
  class Patch < Action
101
- string :url
129
+ string :url, cache: true
102
130
  hash :formData
103
131
  end
104
132
 
105
133
  class Delete < Action
106
- string :url
134
+ string :url, cache: true
107
135
  hash :formData
108
136
  end
109
137
 
@@ -16,6 +16,27 @@ module Glib
16
16
  hash :padding
17
17
  array :styleClasses
18
18
  singleton_array :styleClass, :styleClasses
19
+
20
+ def analytics(value)
21
+ if value.is_a?(String)
22
+ @analyticsEnabled = true
23
+ @analyticsId = value
24
+ else
25
+ @analyticsEnabled = value == true
26
+ end
27
+ end
28
+
29
+ # Override
30
+ def created
31
+ if @analyticsEnabled
32
+ context = page.context
33
+ json.analytics do
34
+ content = @analyticsId || (@text || @icon)&.gsub(/\s+/, '_')&.downcase || 'nil'
35
+ json.namePrefix [context.controller_name, context.action_name, content].join('_')
36
+ end
37
+ end
38
+ end
39
+
19
40
  end
20
41
 
21
42
  ### View definitions
@@ -44,8 +65,8 @@ module Glib
44
65
  end
45
66
 
46
67
  class Button < View
47
- icon :icon
48
- string :text
68
+ icon :icon, cache: true
69
+ string :text, cache: true
49
70
  action :onClick
50
71
  color :color
51
72
  end
@@ -61,10 +61,12 @@ class Glib::JsonUi::ViewBuilder
61
61
  # end
62
62
 
63
63
  json.childViews do
64
- json.child! do
65
- json.view 'fields/hidden-v1'
66
- json.name 'authenticity_token'
67
- json.value page.context.form_authenticity_token
64
+ if @method.downcase != 'get'
65
+ json.child! do
66
+ json.view 'fields/hidden-v1'
67
+ json.name 'authenticity_token'
68
+ json.value page.context.form_authenticity_token
69
+ end
68
70
  end
69
71
 
70
72
  # if insert_method_field
@@ -1,4 +1,4 @@
1
- info = "Submitted information:\n{\n"
1
+ info = "Method: #{request.method}\nForm Data:\n{\n"
2
2
  params.require(:user).each do |k, v|
3
3
  value = v.is_a?(String) ? '"' + v + '"' : v
4
4
  info += " #{k} => #{value}\n"
@@ -0,0 +1,22 @@
1
+ json.title 'Forms'
2
+
3
+ data = params[:user] || {}
4
+
5
+ json_ui_page json do |page|
6
+ render "#{@path_prefix}/nav_menu", json: json, page: page
7
+
8
+ page.form url: json_ui_garage_url(path: 'forms/get_request'), method: 'get', padding: json_padding_body, childViews: ->(form) do
9
+ # TODO: Potential improvement:
10
+ # Use `reload` behaviour instead of `open` (i.e. don't keep adding URL to history).
11
+ # Probably introduce a flag to panels_form so developer can enable/disable this behaviour.
12
+ form.h3 text: "Hello #{ data[:name] }"
13
+ form.spacer height: 6
14
+ form.label text: 'On the web, upon submit, URL needs to change on the browser'
15
+ form.spacer height: 10
16
+ form.fields_text name: 'user[name]', width: 'matchParent', label: 'Name'
17
+
18
+ form.panels_split width: 'matchParent', rightViews: ->(split) do
19
+ split.button text: 'Submit', onClick: ->(action) { action.forms_submit }
20
+ end
21
+ end
22
+ end
@@ -22,6 +22,9 @@ json_ui_page json do |page|
22
22
  template.thumbnail title: 'Text Validation', onClick: ->(action) do
23
23
  action.windows_open url: json_ui_garage_url(path: 'forms/text_validation')
24
24
  end
25
+ template.thumbnail title: 'GET Request', onClick: ->(action) do
26
+ action.windows_open url: json_ui_garage_url(path: 'forms/get_request')
27
+ end
25
28
 
26
29
  end
27
30
  end, ->(section) do
@@ -30,9 +33,12 @@ json_ui_page json do |page|
30
33
  end
31
34
 
32
35
  section.rows builder: ->(template) do
33
- template.thumbnail title: 'Pickers (TODO: ios, android)', onClick: ->(action) do
36
+ template.thumbnail title: 'Pickers', onClick: ->(action) do
34
37
  action.windows_open url: json_ui_garage_url(path: 'forms/pickers')
35
38
  end
39
+ template.thumbnail title: 'Select Fields', onClick: ->(action) do
40
+ action.windows_open url: json_ui_garage_url(path: 'forms/selects')
41
+ end
36
42
  template.thumbnail title: 'File Upload', onClick: ->(action) do
37
43
  action.windows_open url: json_ui_garage_url(path: 'forms/file_upload')
38
44
  end
@@ -17,20 +17,20 @@ json_ui_page json do |page|
17
17
  form.fields_check name: 'user[age_range]', value: '16+', uncheckValue: '0-16', label: 'I am over 16 (has default value)'
18
18
  form.fields_check name: 'user[employer]', value: 1, label: 'I am an employer (no default value)'
19
19
 
20
- form.spacer height: 20
21
- form.h2 text: 'Select'
22
- form.spacer height: 6
23
- languages = {
24
- 'zh-HK' => 'Hong Kong',
25
- 'zh-TW' => 'Taiwan',
26
- 'zh-CN' => 'China',
27
- 'ja-JP' => 'Japan',
28
- 'ko-KR' => 'Korea',
29
- 'ru-RU' => 'Russian',
30
- 'en-PH' => 'Philippines'
31
- }
32
- form.fields_select name: 'user[primary_language]', width: 'matchParent', label: 'Primary Language', options: languages.map { |k, v| { value: k, text: v } }, value: 'ja-JP'
33
- form.fields_select name: 'user[preferred_languages][]', width: 'matchParent', label: 'Preferred Languages', options: languages.map { |k, v| { value: k, text: v } }, value: ['ja-JP', 'ko-KR'], multiple: true
20
+ # form.spacer height: 20
21
+ # form.h2 text: 'Select'
22
+ # form.spacer height: 6
23
+ # languages = {
24
+ # 'zh-HK' => 'Hong Kong',
25
+ # 'zh-TW' => 'Taiwan',
26
+ # 'zh-CN' => 'China',
27
+ # 'ja-JP' => 'Japan',
28
+ # 'ko-KR' => 'Korea',
29
+ # 'ru-RU' => 'Russian',
30
+ # 'en-PH' => 'Philippines'
31
+ # }
32
+ # form.fields_select name: 'user[primary_language]', width: 'matchParent', label: 'Primary Language', options: languages.map { |k, v| { value: k, text: v } }, value: 'ja-JP'
33
+ # form.fields_select name: 'user[preferred_languages][]', width: 'matchParent', label: 'Preferred Languages', options: languages.map { |k, v| { value: k, text: v } }, value: ['ja-JP', 'ko-KR'], multiple: true
34
34
 
35
35
  form.spacer height: 20
36
36
  form.h2 text: 'Date/Time'
@@ -0,0 +1,41 @@
1
+ json.title 'Forms'
2
+
3
+ json_ui_page json do |page|
4
+ render "#{@path_prefix}/nav_menu", json: json, page: page
5
+
6
+ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', padding: json_padding_body, childViews: ->(form) do
7
+
8
+ form.spacer height: 20
9
+ form.h2 text: 'Basic select fields'
10
+ form.spacer height: 6
11
+ languages = {
12
+ 'zh-HK' => 'Hong Kong',
13
+ 'zh-TW' => 'Taiwan',
14
+ 'zh-CN' => 'China',
15
+ 'ja-JP' => 'Japan',
16
+ 'ko-KR' => 'Korea',
17
+ 'ru-RU' => 'Russian',
18
+ 'en-PH' => 'Philippines'
19
+ }
20
+ form.fields_select name: 'user[primary_language]', width: 'matchParent', label: 'Primary Language', options: languages.map { |k, v| { value: k, text: v } }, value: 'ja-JP'
21
+ form.fields_select name: 'user[preferred_languages][]', width: 'matchParent', label: 'Preferred Languages', options: languages.map { |k, v| { value: k, text: v } }, value: ['ja-JP', 'ko-KR'], multiple: true
22
+
23
+ form.spacer height: 20
24
+ form.h2 text: 'Select fields with manual entry'
25
+ form.spacer height: 6
26
+ skills = ['Singing', 'Dancing', 'Fighting']
27
+ form.fields_select name: 'user[skill]', width: 'matchParent', label: 'Skill', options: skills, value: 'Singing', manualEntry: true
28
+ form.fields_select name: 'user[skills][]', width: 'matchParent', label: 'Skills', options: skills, value: ['Dancing', 'Fencing'], multiple: true, manualEntry: true
29
+
30
+ form.spacer height: 20
31
+ form.h2 text: 'Select fields with auto complete'
32
+ form.spacer height: 6
33
+ form.label text: 'Applicable to select fields with many options'
34
+ form.spacer height: 6
35
+ # TODO
36
+
37
+ form.button text: 'Submit', onClick: ->(action) { action.forms_submit }
38
+
39
+ end
40
+
41
+ end
@@ -1,3 +1,5 @@
1
+ sleep 0.5
2
+
1
3
  json.title 'Menu'
2
4
 
3
5
  json_ui_page json do |page|
@@ -11,6 +11,13 @@ json_ui_page json do |page|
11
11
  action.windows_open url: json_ui_garage_url(path: 'home/blank')
12
12
  end
13
13
 
14
+ scroll.spacer height: 20
15
+ scroll.h2 text: 'Button with icon'
16
+ scroll.spacer height: 6
17
+ scroll.button icon: 'info', text: 'Button', onClick: ->(action) do
18
+ action.windows_open url: json_ui_garage_url(path: 'home/blank')
19
+ end
20
+
14
21
  scroll.spacer height: 20
15
22
  scroll.h2 text: 'Button with link style'
16
23
  scroll.spacer height: 6
@@ -34,6 +41,9 @@ json_ui_page json do |page|
34
41
  action.windows_open url: json_ui_garage_url(path: 'home/blank')
35
42
  end
36
43
 
44
+ scroll.fab icon: 'add', onClick: ->(action) do
45
+ action.windows_open url: json_ui_garage_url(path: 'home/blank')
46
+ end
37
47
 
38
48
  end
39
49
  end
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.2.10
4
+ version: 0.2.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -58,9 +58,11 @@ files:
58
58
  - app/views/json_ui/garage/forms/file_upload.json.jbuilder
59
59
  - app/views/json_ui/garage/forms/floating_submit.json.jbuilder
60
60
  - app/views/json_ui/garage/forms/generic_post.json.jbuilder
61
+ - app/views/json_ui/garage/forms/get_request.json.jbuilder
61
62
  - app/views/json_ui/garage/forms/index.json.jbuilder
62
63
  - app/views/json_ui/garage/forms/pickers.json.jbuilder
63
64
  - app/views/json_ui/garage/forms/rich_text.json.jbuilder
65
+ - app/views/json_ui/garage/forms/selects.json.jbuilder
64
66
  - app/views/json_ui/garage/forms/submission_flow.json.jbuilder
65
67
  - app/views/json_ui/garage/forms/submission_flow_post.json.jbuilder
66
68
  - app/views/json_ui/garage/forms/submission_indicator.json.jbuilder