glib-web 0.5.60 → 0.5.66

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: 0325e5e576b06ce312006f6888566fdb7e827107efd814e2c764359243a1cc28
4
- data.tar.gz: 2ca33ca06ceece2210a0fe9007bad0c49c32311a5561dba1c97f9e3771e720a5
3
+ metadata.gz: 7c51f81f729ea985bfb0b33ab4df25a6f614acf722ff529bcc6405518caa3c38
4
+ data.tar.gz: f7c3aa756c17b0a4b36d013b2523b3b25194505af2aa4baab0cfac10b1011dd8
5
5
  SHA512:
6
- metadata.gz: 9a615bdc1ef6f2876da56d926b024e248371280d9a1f932d93adb8574d7ff96170bf2a99bca4201aa2a2654d85b22fb3ed890f9156937eea79669547d81fcf78
7
- data.tar.gz: a85f2814be1ca5f3d0ce34c9646226461f93f9de1e33a13f9190605a775a1339afb3bd57316449bfca261de6156a9b94c1a3dfd217aa1c31ba3dbcaad4935567
6
+ metadata.gz: a5419f4136f708d8e069884e54e63f6fbf9e73f6d64a22b21548ef06f42a26a327cada5f8731e1616d94f9cb3aee6978d35f4a5c81a8a6d7d6861b58cdfeb4f5
7
+ data.tar.gz: a77c0ea82bf85bf3f6218448224666b0b569d9cafaa2bd1fa8d9520d34f9caf8421a2b2e9de92f3821761d52ab67ac5101cb13e9401f9a1478d63e4b99a0be2c
@@ -0,0 +1,29 @@
1
+ module Glib
2
+ module Channel
3
+ class OnlineChannel < ApplicationCable::Channel
4
+ class << self
5
+ attr_accessor :channel_name
6
+ end
7
+
8
+ def channel_name
9
+ self.class.channel_name
10
+ end
11
+
12
+ def subscribed
13
+ stream_from "#{self.class.channel_name}_#{params['conversation_id']}"
14
+ end
15
+
16
+ def online_status(data)
17
+ ActionCable.server.broadcast \
18
+ "#{self.class.channel_name}_#{params['conversation_id']}",
19
+ action: {
20
+ action: 'component/set',
21
+ name: User.find(data['user_id']).full_name,
22
+ status: data['status'],
23
+ user_id: data['user_id'],
24
+ event: 'online_status'
25
+ }
26
+ end
27
+ end
28
+ end
29
+ end
@@ -129,8 +129,29 @@ module Glib
129
129
  end
130
130
 
131
131
  class Icon < View
132
+ # TODO: Remove later. Deprecated.
132
133
  icon :spec
134
+
133
135
  action :onClick
136
+ color :color
137
+
138
+ def name(value)
139
+ @name = value
140
+ end
141
+
142
+ def size(value)
143
+ @size = value
144
+ end
145
+
146
+ # Override
147
+ def created
148
+ if @name
149
+ json.material do
150
+ json.name @name
151
+ json.size @size if @size
152
+ end
153
+ end
154
+ end
134
155
  end
135
156
 
136
157
  # class Banner < View
@@ -9,6 +9,7 @@ class Glib::JsonUi::ViewBuilder
9
9
  end
10
10
 
11
11
  class Select < View
12
+ string :id
12
13
  icon :icon
13
14
  string :message
14
15
  singleton_array :styleClass, :styleClasses
@@ -97,6 +97,10 @@ class Glib::JsonUi::ViewBuilder
97
97
  class Hidden < Text
98
98
  end
99
99
 
100
+ class Timer < Text
101
+ bool :forward
102
+ end
103
+
100
104
  # Benefits of using `fields/submit` over `button`
101
105
  # - On the web, it translates to input[type=submit] which provides builtin functionality such as
102
106
  # submitting upon pressing enter on a field and remembering values for autofill.
@@ -9,6 +9,12 @@ section.rows builder: ->(template) do
9
9
  subaction.snackbars_alert message: 'Timeout elapsed'
10
10
  end
11
11
  end
12
+
13
+ template.thumbnail title: 'timeouts/set with repeat', onClick: ->(action) do
14
+ action.timeouts_set interval: 1000, repeat: true, onTimeout: ->(subaction) do
15
+ subaction.snackbars_alert message: 'Timeout elapsed every 1 second'
16
+ end
17
+ end
12
18
  end
13
19
 
14
20
  # section.rows builder: ->(template) do
@@ -59,6 +59,12 @@ page.list sections: [
59
59
  template.thumbnail title: 'Floating Submit', onClick: ->(action) do
60
60
  action.windows_open url: json_ui_garage_url(path: 'forms/floating_submit')
61
61
  end
62
+ template.thumbnail title: 'Ratings', onClick: ->(action) do
63
+ action.windows_open url: json_ui_garage_url(path: 'forms/ratings')
64
+ end
65
+ template.thumbnail title: 'Misc', onClick: ->(action) do
66
+ action.windows_open url: json_ui_garage_url(path: 'forms/misc')
67
+ end
62
68
  end
63
69
  end, ->(section) do
64
70
  section.header padding: glib_json_padding_list, childViews: ->(header) do
@@ -0,0 +1,29 @@
1
+ json.title 'Forms'
2
+
3
+ page = json_ui_page json
4
+ render "#{@path_prefix}/nav_menu", json: json, page: page
5
+
6
+ page.form \
7
+ url: json_ui_garage_url(path: 'forms/generic_post'),
8
+ method: 'post',
9
+ padding: glib_json_padding_body,
10
+ childViews: ->(form) do
11
+
12
+ form.spacer height: 20
13
+ form.h2 text: 'Standard (Backward)'
14
+ form.spacer height: 6
15
+ form.fields_timer \
16
+ name: 'user[timer]',
17
+ value: 60
18
+
19
+ form.spacer height: 20
20
+ form.h2 text: 'Stop Watch (Forward)'
21
+ form.spacer height: 6
22
+ form.fields_timer \
23
+ name: 'user[stop_watch]',
24
+ value: 10,
25
+ forward: true
26
+
27
+ form.spacer height: 20
28
+ form.fields_submit text: 'Submit'
29
+ end
@@ -74,29 +74,6 @@ page.form \
74
74
  longitudeField: { view: 'fields/text', name: 'user[longitude]', label: 'Long', value: 151.21078710000006, readOnly: true },
75
75
  zoomField: { view: 'fields/text', name: 'user[zoom]', label: 'Zoom' }
76
76
 
77
- form.spacer height: 20
78
- form.h2 text: 'Rating'
79
- form.spacer height: 6
80
- form.fields_rating \
81
- name: 'user[rating_summary1]',
82
- value: 1,
83
- color: 'primary'
84
- form.fields_rating \
85
- name: 'user[rating_summary2]',
86
- value: 1.5,
87
- halfIncrements: true,
88
- color: 'secondary'
89
- form.fields_rating \
90
- name: 'user[rating_summary3]',
91
- value: 2,
92
- color: 'ternary',
93
- size: 35
94
- form.fields_rating \
95
- name: 'user[rating_summary4]',
96
- value: 3,
97
- readOnly: true,
98
- size: 40
99
-
100
77
  form.spacer height: 20
101
78
  form.fields_submit text: 'Submit'
102
79
  end
@@ -0,0 +1,49 @@
1
+ json.title 'Forms'
2
+
3
+ page = json_ui_page json
4
+ render "#{@path_prefix}/nav_menu", json: json, page: page
5
+
6
+ page.form \
7
+ url: json_ui_garage_url(path: 'forms/generic_post'),
8
+ method: 'post',
9
+ padding: glib_json_padding_body,
10
+ childViews: ->(form) do
11
+
12
+ form.spacer height: 20
13
+ form.h2 text: 'Full Increments'
14
+ form.spacer height: 6
15
+ form.fields_rating \
16
+ name: 'user[rating_summary1]',
17
+ value: 1,
18
+ color: 'primary'
19
+
20
+ form.spacer height: 20
21
+ form.h2 text: 'Half Increments'
22
+ form.spacer height: 6
23
+ form.fields_rating \
24
+ name: 'user[rating_summary2]',
25
+ value: 1.5,
26
+ halfIncrements: true,
27
+ color: 'secondary'
28
+
29
+ form.spacer height: 20
30
+ form.h2 text: 'Custom Size'
31
+ form.spacer height: 6
32
+ form.fields_rating \
33
+ name: 'user[rating_summary3]',
34
+ value: 2,
35
+ color: 'ternary',
36
+ size: 35
37
+
38
+ form.spacer height: 20
39
+ form.h2 text: 'Read Only'
40
+ form.spacer height: 6
41
+ form.fields_rating \
42
+ name: 'user[rating_summary4]',
43
+ value: 3,
44
+ readOnly: true,
45
+ size: 40
46
+
47
+ form.spacer height: 20
48
+ form.fields_submit text: 'Submit'
49
+ end
@@ -5,7 +5,7 @@ render "#{@path_prefix}/nav_menu", json: json, page: page
5
5
 
6
6
  page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', padding: glib_json_padding_body, childViews: ->(form) do
7
7
  form.h1 text: 'Text'
8
- form.fields_password name: 'user[text1]', width: 'matchParent', label: 'Type "show"'
8
+ form.fields_password name: 'user[text1]', width: 'matchParent', label: 'Type "show"', value: ''
9
9
  form.label text: 'Typed', showIf: {
10
10
  "==": [
11
11
  {
@@ -14,6 +14,14 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
14
14
  'show'
15
15
  ]
16
16
  }
17
+ form.label text: 'Type something', showIf: {
18
+ "==": [
19
+ {
20
+ "var": 'user[text1]'
21
+ },
22
+ ''
23
+ ]
24
+ }
17
25
 
18
26
  form.spacer height: 20
19
27
  form.h1 text: 'Textarea'
@@ -45,6 +53,7 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
45
53
  form.fields_radioGroup name: 'user[radio1]', value: 'F', childViews: ->(group) do
46
54
  group.fields_radio value: 'show', label: 'Show'
47
55
  group.fields_radio value: 'hide', label: 'Hide'
56
+ group.fields_radio value: '', label: 'Empty'
48
57
  end
49
58
  form.spacer height: 10
50
59
  form.label text: 'Chosen', showIf: {
@@ -55,11 +64,19 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
55
64
  'show'
56
65
  ]
57
66
  }
67
+ form.label text: 'Unspecified', showIf: {
68
+ "==": [
69
+ {
70
+ "var": 'user[radio1]'
71
+ },
72
+ ''
73
+ ]
74
+ }
58
75
 
59
76
  form.spacer height: 20
60
77
  form.h1 text: 'Select'
61
- options = ['show', 'hide']
62
- form.fields_select name: 'user[select1]', width: 'matchParent', label: 'Select "show"', options: options
78
+ options = ['', 'show', 'hide']
79
+ form.fields_select name: 'user[select1]', width: 'matchParent', label: 'Select "show"', options: options, value: ''
63
80
  form.label text: 'Selected', showIf: {
64
81
  "==": [
65
82
  {
@@ -68,6 +85,14 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
68
85
  'show'
69
86
  ]
70
87
  }
88
+ form.label text: 'Unspecified', showIf: {
89
+ "==": [
90
+ {
91
+ "var": 'user[select1]'
92
+ },
93
+ ''
94
+ ]
95
+ }
71
96
 
72
97
  form.spacer height: 20
73
98
  form.h1 text: 'Combined conditions'
@@ -90,7 +115,7 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
90
115
  form.spacer height: 10
91
116
  form.fields_check name: 'user[check2]', checkValue: 'on', label: 'Show field'
92
117
  form.spacer height: 10
93
- form.fields_text width: 'matchParent', label: 'Comment (optional)', name: 'user[comment]', value: 'This field can be submitted when it is hidden, but it is not necessary (i.e. up to the app)', showIf: {
118
+ form.fields_text width: 'matchParent', label: 'Comment (optional)', name: 'user[comment]', value: 'This field should be submitted even when it is hidden', showIf: {
94
119
  "==": [
95
120
  {
96
121
  "var": 'user[check2]'
@@ -1,11 +1,18 @@
1
1
  json.title 'Lists'
2
2
 
3
- json_ui_page json do |page|
4
- render "#{@path_prefix}/nav_menu", json: json, page: page
3
+ page_index = params[:page].to_i
4
+ if page_index > 2
5
+ page_index = 2
6
+ end
7
+ page = json_ui_page json
8
+ render "#{@path_prefix}/nav_menu", json: json, page: page
5
9
 
6
- page.list firstSection: ->(section) do
7
- section.rows builder: ->(template) do
8
- template.thumbnail title: 'Click menu (web) or swipe left (Android/iOS)', leftButtons: ->(menu) do
10
+ page.list firstSection: ->(section) do
11
+ section.rows builder: ->(template) do
12
+ template.thumbnail \
13
+ title: 'Click menu (web) or swipe left (Android/iOS)',
14
+ subtitle: "Page index: #{page_index}",
15
+ leftButtons: ->(menu) do
9
16
  menu.button styleClass: 'icon', icon: 'check_box', onClick: ->(subaction) do
10
17
  subaction.dialogs_alert message: 'Tick/untick'
11
18
  end
@@ -17,38 +24,39 @@ json_ui_page json do |page|
17
24
  subaction.dialogs_alert message: 'Open'
18
25
  end
19
26
  end, editButtons: ->(menu) do
20
- menu.button text: 'Edit', onClick: ->(action) do
21
- action.dialogs_alert message: 'Perform action'
27
+ menu.button text: "Edit (ID: #{page_index})", onClick: ->(action) do
28
+ action.dialogs_alert message: 'Perform Edit action'
22
29
  end
23
30
  menu.button text: 'Delete', onClick: ->(action) do
24
- action.dialogs_alert message: 'Perform action'
31
+ action.dialogs_alert message: 'Perform Delete action'
25
32
  end
33
+ end, onClick: ->(action) do
34
+ action.windows_open url: json_ui_garage_url(path: 'lists/edit_actions', page: page_index + 1)
26
35
  end
27
36
 
28
- template.thumbnail title: 'Long press to get an alert', onLongPress: ->(action) do
29
- action.dialogs_alert message: 'This is an alert'
30
- end
37
+ template.thumbnail title: 'Long press to get an alert', onLongPress: ->(action) do
38
+ action.dialogs_alert message: 'This is an alert'
39
+ end
31
40
 
32
- template.thumbnail title: 'Long press to see menu', onLongPress: ->(action) do
33
- action.sheets_select message: 'Context Menu', buttons: ->(menu) do
34
- menu.button icon: 'edit', text: 'Edit', onClick: ->(subaction) do
35
- subaction.dialogs_alert message: 'Perform action'
36
- end
37
- menu.button icon: 'delete', text: 'Delete', onClick: ->(subaction) do
38
- subaction.dialogs_alert message: 'Perform action'
39
- end
41
+ template.thumbnail title: 'Long press to see menu', onLongPress: ->(action) do
42
+ action.sheets_select message: 'Context Menu', buttons: ->(menu) do
43
+ menu.button icon: 'edit', text: 'Edit', onClick: ->(subaction) do
44
+ subaction.dialogs_alert message: 'Perform action'
45
+ end
46
+ menu.button icon: 'delete', text: 'Delete', onClick: ->(subaction) do
47
+ subaction.dialogs_alert message: 'Perform action'
40
48
  end
41
49
  end
42
-
43
- # template.thumbnail title: 'Long press to see menu', contextButtons: ->(menu) do
44
- # menu.button text: 'Edit', onClick: ->(action) do
45
- # action.dialogs_alert message: 'Perform action'
46
- # end
47
- # menu.button text: 'Delete', onClick: ->(action) do
48
- # action.dialogs_alert message: 'Perform action'
49
- # end
50
- # end
51
50
  end
52
51
 
52
+ # template.thumbnail title: 'Long press to see menu', contextButtons: ->(menu) do
53
+ # menu.button text: 'Edit', onClick: ->(action) do
54
+ # action.dialogs_alert message: 'Perform action'
55
+ # end
56
+ # menu.button text: 'Delete', onClick: ->(action) do
57
+ # action.dialogs_alert message: 'Perform action'
58
+ # end
59
+ # end
53
60
  end
61
+
54
62
  end
@@ -1,6 +1,10 @@
1
1
  json.title 'ActionCable Real-time Update'
2
2
  page = json_ui_page json
3
3
 
4
+ online_channel = 'OnlineChannel'
5
+ typing_channel = 'IsTypingChannel'
6
+ first_user = User.first
7
+ second_user = User.offset(1).first
4
8
  # Implement a page that shows how ActionCable works in json_ui
5
9
 
6
10
  # 1. Example for list
@@ -21,13 +25,19 @@ page = json_ui_page json
21
25
 
22
26
 
23
27
  # 3. Example for online status
24
- # - TODO: Implement "repeat: true" in glib-web-npm
25
- # page.on load: ->(action) do
26
- # action.timeouts_set interval: 10000, repeat: true, onTimeout: ->(subaction) do
27
- # subaction.cables_push channel: 'message', event: 'online'
28
- # end
28
+
29
+ # put on app/channels/online_channel.rb
30
+ # class OnlineChannel < Glib::Channel::OnlineChannel
31
+ # self.channel_name = 'OnlineChannel'
29
32
  # end
30
33
 
34
+ page.on load: ->(action) do
35
+ action.timeouts_set interval: 1000, repeat: true, onTimeout: ->(subaction) do
36
+ subaction.cables_push channel: online_channel, event: 'online_status', payload: { status: true, user_id: first_user.id }
37
+ end
38
+ end
39
+
40
+ # 4. Example for typing status
31
41
 
32
42
  # put on app/channels/is_typing_channel.rb
33
43
  # class IsTypingChannel < Glib::Channel::IsTypingChannel
@@ -36,30 +46,35 @@ page = json_ui_page json
36
46
 
37
47
  page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
38
48
 
39
- channel = 'IsTypingChannel'
40
- first_user = User.first
41
- second_user = User.offset(1).first
42
-
43
49
  scroll.panels_split width: 'matchParent', content: ->(content) do
44
50
  content.left childViews: ->(left) do
51
+ online_socket_config = {
52
+ channel: online_channel,
53
+ filterKey: second_user.id,
54
+ params: {
55
+ conversation: 2
56
+ }
57
+ }
58
+ left.label actionCable: online_socket_config, text: ' '
59
+
45
60
  left.fields_textarea \
46
61
  width: 440,
47
62
  label: "Messages from #{first_user.full_name}",
48
63
  onTypeStart: lambda { |action|
49
64
  action.cables_push \
50
- channel: channel, event: 'typing',
65
+ channel: typing_channel, event: 'typing',
51
66
  payload: { status: true, user_id: first_user.id }
52
67
  },
53
68
  onTypeEnd: lambda { |action|
54
69
  action.cables_push \
55
- channel: channel,
70
+ channel: typing_channel,
56
71
  event: 'typing',
57
72
  payload: { status: false, user_id: first_user.id }
58
73
  }
59
74
  left.spacer height: 10
60
75
 
61
76
  socket_config = {
62
- channel: channel,
77
+ channel: typing_channel,
63
78
  filterKey: first_user.id,
64
79
  params: {
65
80
  conversation: 2
@@ -67,25 +82,26 @@ page.scroll padding: glib_json_padding_body, childViews: ->(scroll) do
67
82
  }
68
83
  left.label actionCable: socket_config, text: ' '
69
84
  end
85
+
70
86
  content.right childViews: ->(right) do
71
87
  right.fields_textarea \
72
88
  width: 440,
73
89
  label: "Messages from #{second_user.full_name}",
74
90
  onTypeStart: lambda { |action|
75
91
  action.cables_push \
76
- channel: channel, event: 'typing',
92
+ channel: typing_channel, event: 'typing',
77
93
  payload: { status: true, user_id: second_user.id }
78
94
  },
79
95
  onTypeEnd: lambda { |action|
80
96
  action.cables_push \
81
- channel: channel,
97
+ channel: typing_channel,
82
98
  event: 'typing',
83
99
  payload: { status: false, user_id: second_user.id }
84
100
  }
85
101
  right.spacer height: 10
86
102
 
87
103
  socket_config = {
88
- channel: channel,
104
+ channel: typing_channel,
89
105
  filterKey: second_user.id,
90
106
  params: {
91
107
  conversation: 2