glib-web 0.3.11 → 0.3.12
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 +4 -4
- data/app/controllers/concerns/application/json/libs.rb +11 -12
- data/app/controllers/concerns/application/json/transformation.rb +1 -1
- data/app/controllers/concerns/application/json/ui.rb +3 -3
- data/app/controllers/concerns/application/json/validation.rb +1 -1
- data/app/helpers/glib/json_ui/abstract_builder.rb +2 -0
- data/app/helpers/glib/json_ui/action_builder.rb +25 -32
- data/app/helpers/glib/json_ui/list_builders.rb +0 -10
- data/app/helpers/glib/json_ui/page_helper.rb +17 -3
- data/app/helpers/glib/json_ui/split_builders.rb +0 -7
- data/app/helpers/glib/json_ui/view_builder/charts.rb +19 -0
- data/app/helpers/glib/json_ui/view_builder/fields.rb +9 -0
- data/app/helpers/glib/json_ui/view_builder.rb +18 -9
- data/app/views/json_ui/garage/forms/submission_indicator.json.jbuilder +5 -1
- data/app/views/json_ui/garage/notifications/index.json.jbuilder +2 -2
- data/app/views/json_ui/garage/views/_chart_data.json.jbuilder +17 -0
- data/app/views/json_ui/garage/views/charts.json.jbuilder +24 -17
- data/lib/glib/json_crawler/http.rb +4 -2
- metadata +5 -22
- data/app/controllers/concerns/glib/json/libs.rb +0 -93
- data/app/controllers/concerns/glib/json/transformation.rb +0 -11
- data/app/controllers/concerns/glib/json/ui.rb +0 -66
- data/app/controllers/concerns/glib/json/validation.rb +0 -13
- data/app/helpers/glib/dynamic_texts_helper.rb +0 -18
- data/app/models/glib/dynamic_text_record.rb +0 -6
- data/app/models/glib/text.rb +0 -36
- data/lib/generators/glib/install_generator.rb +0 -19
- data/lib/generators/templates/20191017062519_create_texts.rb +0 -12
- data/lib/generators/templates/20191024063257_add_scope_to_texts.rb +0 -7
- data/lib/generators/templates/20191112095018_add_lang_to_texts.rb +0 -7
- data/lib/generators/templates/database.yml +0 -107
- data/lib/generators/templates/dynamic_text.rb +0 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d9c8901bfee8243bbc64b4693fbd3f3d2395ce3dacfdf394456204ec5c995c9
|
4
|
+
data.tar.gz: 3c1fbb85bd85b9b2c58eabb5824cac8dbd94a0b97b815e01b442142ebcff9e80
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8531f46175119fbc397cda8ee0a7e7c4ad4cecad00a6935973a0d1d25a17b34a8a62680f06e45a099dde054816d6e60c3ed24597b5c2213bb41c1e3658c2a589
|
7
|
+
data.tar.gz: 2b78a224ac48364902f42fbc24f6fcce9478e49665f86137aae30167a1d3892ccabab15ee40bfb3c129378956de037b55c20d8e5d9a2d26fc519fb84ad6a3290
|
@@ -1,5 +1,4 @@
|
|
1
|
-
|
2
|
-
module Application::Json::Libs
|
1
|
+
module Concerns::Application::Json::Libs
|
3
2
|
extend ActiveSupport::Concern
|
4
3
|
|
5
4
|
included do
|
@@ -28,7 +27,7 @@ module Application::Json::Libs
|
|
28
27
|
def json_ui_app_is_android?
|
29
28
|
json_ui_app_device_os == 'android'
|
30
29
|
end
|
31
|
-
|
30
|
+
|
32
31
|
def json_ui_app_is_ios?
|
33
32
|
json_ui_app_device_os == 'ios'
|
34
33
|
end
|
@@ -42,9 +41,9 @@ module Application::Json::Libs
|
|
42
41
|
module ClassMethods
|
43
42
|
|
44
43
|
def json_libs_init(options)
|
45
|
-
include Application::Json::Transformation
|
46
|
-
include Application::Json::Validation
|
47
|
-
include Application::Json::Ui
|
44
|
+
include Concerns::Application::Json::Transformation
|
45
|
+
include Concerns::Application::Json::Validation
|
46
|
+
include Concerns::Application::Json::Ui
|
48
47
|
|
49
48
|
before_action :__json_ui_start
|
50
49
|
|
@@ -55,7 +54,7 @@ module Application::Json::Libs
|
|
55
54
|
after_action :__json_transformation_commit
|
56
55
|
after_action :__json_validate_perform
|
57
56
|
end
|
58
|
-
|
57
|
+
|
59
58
|
def json_libs_set_locale
|
60
59
|
before_action do
|
61
60
|
# Need to explicitly fallback to EN
|
@@ -64,7 +63,7 @@ module Application::Json::Libs
|
|
64
63
|
I18n.locale = :en
|
65
64
|
end
|
66
65
|
end
|
67
|
-
|
66
|
+
|
68
67
|
def json_libs_force_json_ui
|
69
68
|
before_action do
|
70
69
|
if params[:_render] != 'v1'
|
@@ -73,17 +72,17 @@ module Application::Json::Libs
|
|
73
72
|
end
|
74
73
|
end
|
75
74
|
|
76
|
-
def json_libs_rescue_csrf
|
75
|
+
def json_libs_rescue_csrf
|
77
76
|
rescue_from ActionController::InvalidAuthenticityToken do |exception|
|
78
77
|
sign_out(:user)
|
79
78
|
|
80
79
|
respond_to do |format|
|
81
80
|
format.json do
|
82
|
-
render json: {
|
83
|
-
onResponse: {
|
81
|
+
render json: {
|
82
|
+
onResponse: {
|
84
83
|
action: 'windows/open-v1',
|
85
84
|
url: root_url
|
86
|
-
}
|
85
|
+
}
|
87
86
|
}
|
88
87
|
end
|
89
88
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
module Application::Json::Ui
|
1
|
+
module Concerns::Application::Json::Ui
|
2
2
|
extend ActiveSupport::Concern
|
3
3
|
|
4
4
|
included do
|
5
5
|
rescue_from ActionController::UnknownFormat do |exception|
|
6
6
|
if json_ui_activated?
|
7
|
-
# Tell `__json_ui_start()` to avoid rendering this page while still retaining the `_render` param
|
7
|
+
# Tell `__json_ui_start()` to avoid rendering this page while still retaining the `_render` param
|
8
8
|
# so that the page remains linking to other json_ui pages.
|
9
9
|
redirect_to url_for(format: nil, _skip_render: true)
|
10
10
|
else
|
@@ -61,6 +61,6 @@ module Application::Json::Ui
|
|
61
61
|
def __json_ui_vue(hash, options)
|
62
62
|
renderer_path = options[:renderer_path]
|
63
63
|
@__json_ui_orig_page = response.body
|
64
|
-
response.body = render_to_string(
|
64
|
+
response.body = render_to_string(file: renderer_path, layout: false, content_type: 'text/html', locals: { page: hash, options: options })
|
65
65
|
end
|
66
66
|
end
|
@@ -18,6 +18,8 @@ module Glib
|
|
18
18
|
name_components = name.to_s.split('_')
|
19
19
|
json.set! type, "#{name_components.join('/')}" if type
|
20
20
|
args = [yield] if block_given?
|
21
|
+
|
22
|
+
# TODO: consider caching these instances
|
21
23
|
"#{self.class.name}::#{name_components.map{ |str| capitalize_first_letter_and_leave_others_alone(str) }.join('::')}".constantize.new(json, @page).parse(*args)
|
22
24
|
end
|
23
25
|
|
@@ -4,7 +4,7 @@ module Glib
|
|
4
4
|
def method_missing m, *args
|
5
5
|
add_singleton_element_v1 'action', m, *args
|
6
6
|
end
|
7
|
-
|
7
|
+
|
8
8
|
class Action < JsonUiElement
|
9
9
|
def analytics(value)
|
10
10
|
if value.is_a?(String)
|
@@ -43,31 +43,31 @@ module Glib
|
|
43
43
|
string :message
|
44
44
|
action :onClose
|
45
45
|
end
|
46
|
-
|
46
|
+
|
47
47
|
# class Confirm < Action
|
48
48
|
# string :message
|
49
49
|
# action :onConfirm
|
50
50
|
# action :onCancel
|
51
51
|
# end
|
52
|
-
|
52
|
+
|
53
53
|
class Options < Action
|
54
54
|
string :message
|
55
|
-
|
55
|
+
|
56
56
|
def buttons(block)
|
57
57
|
json.buttons do
|
58
58
|
block.call page.menu_builder
|
59
59
|
end
|
60
60
|
end
|
61
61
|
end
|
62
|
-
|
62
|
+
|
63
63
|
class Open < Action
|
64
64
|
string :url, cache: true
|
65
65
|
end
|
66
|
-
|
66
|
+
|
67
67
|
class Close < Action
|
68
68
|
action :onClose
|
69
69
|
end
|
70
|
-
|
70
|
+
|
71
71
|
# TODO: Deprecate
|
72
72
|
# Consider renaming to ShowSnackbar
|
73
73
|
class Snackbar < Action
|
@@ -76,16 +76,9 @@ module Glib
|
|
76
76
|
string :horizontalPosition
|
77
77
|
singleton_array :styleClass, :styleClasses
|
78
78
|
end
|
79
|
-
|
80
|
-
class Notification < Action
|
81
|
-
string :title
|
82
|
-
string :body
|
83
|
-
string :tag
|
84
|
-
int :timeout
|
85
|
-
end
|
86
|
-
|
79
|
+
|
87
80
|
end
|
88
|
-
|
81
|
+
|
89
82
|
module Snackbars
|
90
83
|
class Alert < Action
|
91
84
|
string :message
|
@@ -95,20 +88,20 @@ module Glib
|
|
95
88
|
string :horizontalPosition
|
96
89
|
singleton_array :styleClass, :styleClasses
|
97
90
|
end
|
98
|
-
|
91
|
+
|
99
92
|
# class Confirm < Action
|
100
93
|
# string :message
|
101
94
|
# action :onConfirm
|
102
95
|
# action :onCancel
|
103
|
-
|
96
|
+
|
104
97
|
# string :verticalPosition
|
105
98
|
# string :horizontalPosition
|
106
99
|
# singleton_array :styleClass, :styleClasses
|
107
100
|
# end
|
108
|
-
|
101
|
+
|
109
102
|
class Options < Action
|
110
103
|
string :message
|
111
|
-
|
104
|
+
|
112
105
|
string :verticalPosition
|
113
106
|
string :horizontalPosition
|
114
107
|
singleton_array :styleClass, :styleClasses
|
@@ -118,15 +111,15 @@ module Glib
|
|
118
111
|
block.call page.menu_builder
|
119
112
|
end
|
120
113
|
end
|
121
|
-
|
114
|
+
|
122
115
|
end
|
123
|
-
|
116
|
+
|
124
117
|
end
|
125
118
|
|
126
119
|
module Forms
|
127
120
|
class Submit < Action
|
128
121
|
end
|
129
|
-
|
122
|
+
|
130
123
|
end
|
131
124
|
|
132
125
|
module Windows
|
@@ -137,16 +130,16 @@ module Glib
|
|
137
130
|
class CloseAll < Action
|
138
131
|
action :onClose
|
139
132
|
end
|
140
|
-
|
133
|
+
|
141
134
|
class Open < Action
|
142
135
|
string :url, cache: true
|
143
136
|
action :onOpen
|
144
137
|
end
|
145
|
-
|
138
|
+
|
146
139
|
class OpenWeb < Action
|
147
140
|
string :url
|
148
141
|
end
|
149
|
-
|
142
|
+
|
150
143
|
class Reload < Action
|
151
144
|
string :url, cache: true
|
152
145
|
end
|
@@ -158,16 +151,16 @@ module Glib
|
|
158
151
|
string :token
|
159
152
|
action :onSave
|
160
153
|
end
|
161
|
-
|
154
|
+
|
162
155
|
end
|
163
|
-
|
156
|
+
|
164
157
|
# FUTURE
|
165
158
|
module Data
|
166
159
|
class SaveCsrfToken < Action
|
167
160
|
string :token
|
168
161
|
action :onSave
|
169
162
|
end
|
170
|
-
|
163
|
+
|
171
164
|
class Clear < Action
|
172
165
|
end
|
173
166
|
end
|
@@ -177,17 +170,17 @@ module Glib
|
|
177
170
|
string :url, cache: true
|
178
171
|
hash :formData
|
179
172
|
end
|
180
|
-
|
173
|
+
|
181
174
|
class Patch < Action
|
182
175
|
string :url, cache: true
|
183
176
|
hash :formData
|
184
177
|
end
|
185
|
-
|
178
|
+
|
186
179
|
class Delete < Action
|
187
180
|
string :url, cache: true
|
188
181
|
hash :formData
|
189
182
|
end
|
190
|
-
|
183
|
+
|
191
184
|
end
|
192
185
|
|
193
186
|
###
|
@@ -38,11 +38,6 @@ module Glib
|
|
38
38
|
def header(options = {})
|
39
39
|
json.header do
|
40
40
|
page.vertical_content(options)
|
41
|
-
|
42
|
-
# json.padding options[:padding]
|
43
|
-
# json.childViews do
|
44
|
-
# options[:childViews]&.call page.view_builder
|
45
|
-
# end
|
46
41
|
end
|
47
42
|
end
|
48
43
|
|
@@ -62,11 +57,6 @@ module Glib
|
|
62
57
|
def footer(options = {})
|
63
58
|
json.footer do
|
64
59
|
page.vertical_content(options)
|
65
|
-
|
66
|
-
# json.padding options[:padding]
|
67
|
-
# json.childViews do
|
68
|
-
# options[:childViews]&.call page.view_builder
|
69
|
-
# end
|
70
60
|
end
|
71
61
|
end
|
72
62
|
end
|
@@ -10,8 +10,10 @@ module Glib
|
|
10
10
|
)
|
11
11
|
end
|
12
12
|
|
13
|
-
def json_ui_page json
|
14
|
-
|
13
|
+
def json_ui_page json, &block
|
14
|
+
page = Page.new(json, self)
|
15
|
+
block&.call page
|
16
|
+
page
|
15
17
|
end
|
16
18
|
|
17
19
|
class Page
|
@@ -25,7 +27,7 @@ module Glib
|
|
25
27
|
@json = json
|
26
28
|
@context = context
|
27
29
|
|
28
|
-
@view_builder = ViewBuilder.new(json, self)
|
30
|
+
@view_builder = ViewBuilder.new(json, self, true)
|
29
31
|
@action_builder = ActionBuilder.new(json, self)
|
30
32
|
@menu_builder = MenuBuilder.new(json, self)
|
31
33
|
|
@@ -57,6 +59,14 @@ module Glib
|
|
57
59
|
options[:content]&.call drawer_content_builder
|
58
60
|
end
|
59
61
|
end
|
62
|
+
|
63
|
+
def navBar(options = {})
|
64
|
+
json.navBar do
|
65
|
+
json.rightItems do
|
66
|
+
options[:rightItems]&.call @menu_builder
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
60
70
|
|
61
71
|
def header(options = {})
|
62
72
|
json.header do
|
@@ -106,6 +116,10 @@ module Glib
|
|
106
116
|
end
|
107
117
|
end
|
108
118
|
|
119
|
+
def data(options = {})
|
120
|
+
options[:content].call(ViewBuilder.new(json, self, false))
|
121
|
+
end
|
122
|
+
|
109
123
|
def vertical_content(options)
|
110
124
|
options = options.reverse_merge(width: 'matchParent')
|
111
125
|
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Glib::JsonUi::ViewBuilder
|
2
|
+
module Charts
|
3
|
+
class Line < View
|
4
|
+
hash :nextPage
|
5
|
+
|
6
|
+
def dataSeries(blocks)
|
7
|
+
json.dataSeries do
|
8
|
+
blocks.each do |block|
|
9
|
+
json.child! do
|
10
|
+
block.call
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
end
|
@@ -85,6 +85,15 @@ class Glib::JsonUi::ViewBuilder
|
|
85
85
|
|
86
86
|
class Hidden < Text
|
87
87
|
end
|
88
|
+
|
89
|
+
# Benefits of using `fields/submit` over `button`
|
90
|
+
# - On the web, it translates to input[type=submit] which provides builtin functionality such as
|
91
|
+
# submitting upon pressing enter on a field and remembering values for autofill.
|
92
|
+
# - We can attach name-value param to it. See https://www.w3schools.com/tags/att_button_value.asp
|
93
|
+
# - It has a default onClick so no need to specify `onClick: ->(action) { action.forms_submit }`
|
94
|
+
class Submit < AbstractField
|
95
|
+
string :text
|
96
|
+
end
|
88
97
|
|
89
98
|
class CheckGroup < AbstractField
|
90
99
|
views :childViews
|
@@ -1,8 +1,18 @@
|
|
1
1
|
module Glib
|
2
2
|
module JsonUi
|
3
3
|
class ViewBuilder < AbstractBuilder
|
4
|
+
def initialize json, page, multiple
|
5
|
+
super(json, page)
|
6
|
+
|
7
|
+
@multiple = multiple
|
8
|
+
end
|
9
|
+
|
4
10
|
def add_view name, *args
|
5
|
-
|
11
|
+
if @multiple
|
12
|
+
add_element_to_array_v1 'view', name, *args
|
13
|
+
else
|
14
|
+
add_singleton_element_v1 'view', name, *args
|
15
|
+
end
|
6
16
|
end
|
7
17
|
|
8
18
|
def method_missing m, *args
|
@@ -61,9 +71,8 @@ module Glib
|
|
61
71
|
|
62
72
|
class P < AbstractText
|
63
73
|
end
|
64
|
-
|
74
|
+
|
65
75
|
class Label < AbstractText
|
66
|
-
string :format
|
67
76
|
action :onClick
|
68
77
|
end
|
69
78
|
|
@@ -77,7 +86,7 @@ module Glib
|
|
77
86
|
string :url
|
78
87
|
action :onClick
|
79
88
|
end
|
80
|
-
|
89
|
+
|
81
90
|
class Icon < View
|
82
91
|
string :name
|
83
92
|
action :onClick
|
@@ -87,7 +96,7 @@ module Glib
|
|
87
96
|
# icon :icon
|
88
97
|
# string :text
|
89
98
|
# end
|
90
|
-
|
99
|
+
|
91
100
|
class Button < View
|
92
101
|
icon :icon, cache: true
|
93
102
|
string :text, cache: true
|
@@ -112,7 +121,7 @@ module Glib
|
|
112
121
|
int :zoom
|
113
122
|
string :dataUrl
|
114
123
|
end
|
115
|
-
|
124
|
+
|
116
125
|
class Chip < View
|
117
126
|
string :text
|
118
127
|
end
|
@@ -120,10 +129,10 @@ module Glib
|
|
120
129
|
class Calendar < View
|
121
130
|
string :dataUrl
|
122
131
|
end
|
123
|
-
|
132
|
+
|
124
133
|
class TabBar < View
|
125
134
|
color :color
|
126
|
-
|
135
|
+
|
127
136
|
def tabButtons(block)
|
128
137
|
json.tabButtons do
|
129
138
|
block.call page.menu_builder
|
@@ -141,7 +150,7 @@ module Glib
|
|
141
150
|
# end
|
142
151
|
# end
|
143
152
|
# end
|
144
|
-
|
153
|
+
|
145
154
|
end
|
146
155
|
|
147
156
|
end
|
@@ -4,7 +4,11 @@ json_ui_page json do |page|
|
|
4
4
|
render "#{@path_prefix}/nav_menu", json: json, page: page
|
5
5
|
|
6
6
|
page.form url: json_ui_garage_url(path: 'forms/submission_indicator_post'), method: 'post', padding: { top: 12, left: 20, right: 20, bottom: 12 }, childViews: ->(form) do
|
7
|
-
form.
|
7
|
+
form.label text: 'These buttons get disabled on submit'
|
8
|
+
form.spacer height: 10
|
9
|
+
form.button text: 'Normal Button', onClick: ->(action) { action.forms_submit }
|
10
|
+
form.spacer height: 10
|
11
|
+
form.fields_submit text: 'Submit Button'
|
8
12
|
|
9
13
|
# This needs to be long enough that the FAB is roughly at the bottom of a mobile screen.
|
10
14
|
# Ideally the spacer can expand dynamically depending on available space.
|
@@ -2,11 +2,11 @@ json.title 'Notifications'
|
|
2
2
|
|
3
3
|
json_ui_page json do |page|
|
4
4
|
render "#{@path_prefix}/nav_menu", json: json, page: page, top_nav: true
|
5
|
-
|
5
|
+
|
6
6
|
page.list firstSection: ->(section) do
|
7
7
|
section.rows builder: ->(template) do
|
8
8
|
template.thumbnail title: 'Send Desktop Notification', onClick: ->(action) do
|
9
|
-
|
9
|
+
# TODO: Send and display desktop notification
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
page_index = params[:page].to_i
|
2
|
+
next_page = {
|
3
|
+
url: json_ui_garage_url(path: 'views/charts', page: page_index + 1, data_only: 'v1'),
|
4
|
+
autoload: 'all'
|
5
|
+
}
|
6
|
+
|
7
|
+
if page_index < 3
|
8
|
+
builder.charts_line nextPage: next_page, dataSeries: [
|
9
|
+
-> do
|
10
|
+
json.title "Page #{page_index + 1}"
|
11
|
+
|
12
|
+
from = page_index + 1
|
13
|
+
to = page_index
|
14
|
+
json.points (from.month.ago.to_date..to.month.ago.to_date).map { |d| { x: d, y: 100 + rand(40) } }
|
15
|
+
end
|
16
|
+
]
|
17
|
+
end
|
@@ -1,16 +1,20 @@
|
|
1
|
-
json.title 'Views'
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
if params[:data_only].present?
|
3
|
+
json_ui_page json do |page|
|
4
|
+
page.data content: ->(data) do
|
5
|
+
render "#{@path_prefix}/views/chart_data", json: json, builder: data
|
6
|
+
end
|
7
|
+
end
|
8
|
+
else
|
9
|
+
json.title 'Views'
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
json_ui_page json do |page|
|
12
|
+
render "#{@path_prefix}/nav_menu", json: json, page: page
|
13
|
+
|
14
|
+
page.scroll padding: {top: 20, left: 20, right: 20, bottom: 20}, childViews: ->(scroll) do
|
15
|
+
scroll.h1 text: 'Line chart'
|
16
|
+
scroll.charts_line dataSeries: [
|
17
|
+
-> do
|
14
18
|
json.title 'Line 1'
|
15
19
|
|
16
20
|
points = {
|
@@ -22,10 +26,9 @@ json_ui_page json do |page|
|
|
22
26
|
'Thu, 15 Nov 2018' => 1,
|
23
27
|
'Fri, 16 Nov 2018' => 5,
|
24
28
|
}
|
25
|
-
json.
|
26
|
-
end
|
27
|
-
|
28
|
-
json.child! do
|
29
|
+
json.points points.map { |k, v| { x: k, y: v } }
|
30
|
+
end,
|
31
|
+
-> do
|
29
32
|
json.title 'Line 2'
|
30
33
|
|
31
34
|
points = {
|
@@ -37,11 +40,15 @@ json_ui_page json do |page|
|
|
37
40
|
'Thu, 15 Nov 2018' => 5,
|
38
41
|
'Fri, 16 Nov 2018' => 1,
|
39
42
|
}
|
40
|
-
json.
|
43
|
+
json.points points.map { |k, v| { x: k, y: v } }
|
41
44
|
end
|
45
|
+
]
|
42
46
|
|
43
|
-
|
47
|
+
scroll.spacer height: 20
|
48
|
+
scroll.h1 text: 'Line chart using remote data'
|
49
|
+
render "#{@path_prefix}/views/chart_data", json: json, builder: scroll
|
44
50
|
|
45
51
|
end
|
46
52
|
end
|
53
|
+
|
47
54
|
end
|
@@ -30,7 +30,7 @@ module Glib
|
|
30
30
|
# # Allow repeating urls because excluding them makes the test results really hard to analyze.
|
31
31
|
# # if history.include?(url)
|
32
32
|
|
33
|
-
# if url.blank?
|
33
|
+
# if url.blank?
|
34
34
|
# nil
|
35
35
|
# else
|
36
36
|
# @context.assert_match URI_REGEXP, url
|
@@ -52,6 +52,7 @@ module Glib
|
|
52
52
|
# end
|
53
53
|
# end
|
54
54
|
# end
|
55
|
+
|
55
56
|
end
|
56
57
|
|
57
58
|
def post(url, controller, params)
|
@@ -103,13 +104,14 @@ module Glib
|
|
103
104
|
else
|
104
105
|
response_times << response.headers['X-Runtime'].to_f
|
105
106
|
@context.assert_includes VALID_RESPONSE_CODES, code, "Expected a valid response but was [#{response.code}] #{Rack::Utils::HTTP_STATUS_CODES[response.code.to_i]}:\n#{url}"
|
106
|
-
if response.
|
107
|
+
if response.content_type == 'application/json'
|
107
108
|
JSON.parse(response.body)
|
108
109
|
else
|
109
110
|
nil
|
110
111
|
end
|
111
112
|
end
|
112
113
|
end
|
114
|
+
|
113
115
|
end
|
114
116
|
end
|
115
117
|
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.3.
|
4
|
+
version: 0.3.12
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ''
|
@@ -14,22 +14,16 @@ dependencies:
|
|
14
14
|
name: activestorage
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 5.2.3
|
20
|
-
- - "<"
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version: 6.1.0
|
23
20
|
type: :runtime
|
24
21
|
prerelease: false
|
25
22
|
version_requirements: !ruby/object:Gem::Requirement
|
26
23
|
requirements:
|
27
|
-
- - "
|
24
|
+
- - "~>"
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 5.2.3
|
30
|
-
- - "<"
|
31
|
-
- !ruby/object:Gem::Version
|
32
|
-
version: 6.1.0
|
33
27
|
description:
|
34
28
|
email: ''
|
35
29
|
executables: []
|
@@ -40,12 +34,7 @@ files:
|
|
40
34
|
- app/controllers/concerns/application/json/transformation.rb
|
41
35
|
- app/controllers/concerns/application/json/ui.rb
|
42
36
|
- app/controllers/concerns/application/json/validation.rb
|
43
|
-
- app/controllers/concerns/glib/json/libs.rb
|
44
|
-
- app/controllers/concerns/glib/json/transformation.rb
|
45
|
-
- app/controllers/concerns/glib/json/ui.rb
|
46
|
-
- app/controllers/concerns/glib/json/validation.rb
|
47
37
|
- app/controllers/glib/home_controller.rb
|
48
|
-
- app/helpers/glib/dynamic_texts_helper.rb
|
49
38
|
- app/helpers/glib/json_ui/abstract_builder.rb
|
50
39
|
- app/helpers/glib/json_ui/action_builder.rb
|
51
40
|
- app/helpers/glib/json_ui/list_builders.rb
|
@@ -57,10 +46,9 @@ files:
|
|
57
46
|
- app/helpers/glib/json_ui/table_builders.rb
|
58
47
|
- app/helpers/glib/json_ui/view_builder.rb
|
59
48
|
- app/helpers/glib/json_ui/view_builder/banners.rb
|
49
|
+
- app/helpers/glib/json_ui/view_builder/charts.rb
|
60
50
|
- app/helpers/glib/json_ui/view_builder/fields.rb
|
61
51
|
- app/helpers/glib/json_ui/view_builder/panels.rb
|
62
|
-
- app/models/glib/dynamic_text_record.rb
|
63
|
-
- app/models/glib/text.rb
|
64
52
|
- app/views/app/views/json_ui/vue/renderer.html.erb
|
65
53
|
- app/views/json_ui/garage/_nav_menu.json.jbuilder
|
66
54
|
- app/views/json_ui/garage/actions/index.json.jbuilder
|
@@ -112,6 +100,7 @@ files:
|
|
112
100
|
- app/views/json_ui/garage/tables/export_import.json.jbuilder
|
113
101
|
- app/views/json_ui/garage/tables/horizontal_scroll.json.jbuilder
|
114
102
|
- app/views/json_ui/garage/tables/index.json.jbuilder
|
103
|
+
- app/views/json_ui/garage/views/_chart_data.json.jbuilder
|
115
104
|
- app/views/json_ui/garage/views/banners.json.jbuilder
|
116
105
|
- app/views/json_ui/garage/views/calendar_data.json.jbuilder
|
117
106
|
- app/views/json_ui/garage/views/carousels.json.jbuilder
|
@@ -124,12 +113,6 @@ files:
|
|
124
113
|
- app/views/json_ui/garage/views/misc.json.jbuilder
|
125
114
|
- app/views/json_ui/garage/views/texts.json.jbuilder
|
126
115
|
- config/routes.rb
|
127
|
-
- lib/generators/glib/install_generator.rb
|
128
|
-
- lib/generators/templates/20191017062519_create_texts.rb
|
129
|
-
- lib/generators/templates/20191024063257_add_scope_to_texts.rb
|
130
|
-
- lib/generators/templates/20191112095018_add_lang_to_texts.rb
|
131
|
-
- lib/generators/templates/database.yml
|
132
|
-
- lib/generators/templates/dynamic_text.rb
|
133
116
|
- lib/glib-web.rb
|
134
117
|
- lib/glib/engine.rb
|
135
118
|
- lib/glib/json_crawler.rb
|
@@ -1,93 +0,0 @@
|
|
1
|
-
module Glib::Json::Libs
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
extend ClassMethods
|
6
|
-
|
7
|
-
helper_method :json_ui_app_bundle_id, :json_ui_app_build_version, :json_ui_app_device_os
|
8
|
-
helper_method :json_ui_app_is_android?, :json_ui_app_is_ios?, :json_ui_app_is_web?
|
9
|
-
end
|
10
|
-
|
11
|
-
def json_ui_app_bundle_id
|
12
|
-
@json_ui_app_bundle_id ||= request.headers['JsonUiApp-Bundle-Id']
|
13
|
-
end
|
14
|
-
|
15
|
-
def json_ui_app_build_version
|
16
|
-
@json_ui_app_build_version ||= request.headers['JsonUiApp-Build-Version']
|
17
|
-
@json_ui_app_build_version = params[:build_version] if @json_ui_app_build_version.nil? && Rails.env.development? # For easy testing
|
18
|
-
@json_ui_app_build_version
|
19
|
-
end
|
20
|
-
|
21
|
-
def json_ui_app_device_os
|
22
|
-
@json_ui_app_device_os ||= request.headers['JsonUiApp-Device-Os']
|
23
|
-
@json_ui_app_device_os = params[:device_os] if @json_ui_app_device_os.nil? && Rails.env.development? # For easy testing
|
24
|
-
@json_ui_app_device_os || 'web'
|
25
|
-
end
|
26
|
-
|
27
|
-
def json_ui_app_is_android?
|
28
|
-
json_ui_app_device_os == 'android'
|
29
|
-
end
|
30
|
-
|
31
|
-
def json_ui_app_is_ios?
|
32
|
-
json_ui_app_device_os == 'ios'
|
33
|
-
end
|
34
|
-
|
35
|
-
def json_ui_app_is_web?
|
36
|
-
json_ui_app_device_os == 'web'
|
37
|
-
end
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
module ClassMethods
|
42
|
-
|
43
|
-
def json_libs_init(options)
|
44
|
-
include Glib::Json::Transformation
|
45
|
-
include Glib::Json::Validation
|
46
|
-
include Glib::Json::Ui
|
47
|
-
|
48
|
-
before_action :__json_ui_start
|
49
|
-
|
50
|
-
# Note that after_action gets executed in reverse
|
51
|
-
after_action do
|
52
|
-
__json_ui_commit(options)
|
53
|
-
end
|
54
|
-
after_action :__json_transformation_commit
|
55
|
-
after_action :__json_validate_perform
|
56
|
-
end
|
57
|
-
|
58
|
-
def json_libs_set_locale
|
59
|
-
before_action do
|
60
|
-
# Need to explicitly fallback to EN
|
61
|
-
I18n.locale = params[:_locale] || :en
|
62
|
-
rescue
|
63
|
-
I18n.locale = :en
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def json_libs_force_json_ui
|
68
|
-
before_action do
|
69
|
-
if params[:_render] != 'v1'
|
70
|
-
redirect_to url_for(params.to_unsafe_h.merge(_render: 'v1'))
|
71
|
-
end
|
72
|
-
end
|
73
|
-
end
|
74
|
-
|
75
|
-
def json_libs_rescue_csrf
|
76
|
-
rescue_from ActionController::InvalidAuthenticityToken do |exception|
|
77
|
-
sign_out(:user)
|
78
|
-
|
79
|
-
respond_to do |format|
|
80
|
-
format.json do
|
81
|
-
render json: {
|
82
|
-
onResponse: {
|
83
|
-
action: 'windows/open-v1',
|
84
|
-
url: root_url
|
85
|
-
}
|
86
|
-
}
|
87
|
-
end
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
|
92
|
-
end
|
93
|
-
end
|
@@ -1,11 +0,0 @@
|
|
1
|
-
module Glib::Json::Transformation
|
2
|
-
def json_transformation_start
|
3
|
-
if request.format == 'json'
|
4
|
-
@__transformed_json ||= JSON.parse(response.body) rescue nil
|
5
|
-
end
|
6
|
-
end
|
7
|
-
|
8
|
-
def __json_transformation_commit
|
9
|
-
response.body = @__transformed_json.to_json if @__transformed_json
|
10
|
-
end
|
11
|
-
end
|
@@ -1,66 +0,0 @@
|
|
1
|
-
module Glib::Json::Ui
|
2
|
-
extend ActiveSupport::Concern
|
3
|
-
|
4
|
-
included do
|
5
|
-
rescue_from ActionController::UnknownFormat do |exception|
|
6
|
-
if json_ui_activated?
|
7
|
-
# Tell `__json_ui_start()` to avoid rendering this page while still retaining the `_render` param
|
8
|
-
# so that the page remains linking to other json_ui pages.
|
9
|
-
redirect_to url_for(format: nil, _skip_render: true)
|
10
|
-
else
|
11
|
-
raise exception
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
# Override
|
17
|
-
def form_authenticity_token
|
18
|
-
Rails.env.test? ? 'test_token' : super
|
19
|
-
end
|
20
|
-
|
21
|
-
# NOTE: Override default_url_options and call this method
|
22
|
-
def json_ui_url_options
|
23
|
-
options = {}
|
24
|
-
options[:_render] = params[:_render]
|
25
|
-
options[:_locale] = params[:_locale]
|
26
|
-
options[:format] = :json if request.format == :json
|
27
|
-
options
|
28
|
-
end
|
29
|
-
|
30
|
-
def json_ui_activated?
|
31
|
-
@__json_ui_activated
|
32
|
-
end
|
33
|
-
|
34
|
-
def __json_ui_start
|
35
|
-
@__json_ui_activated = false
|
36
|
-
@__json_ui_rendering = false
|
37
|
-
if params[:_render].present?
|
38
|
-
@__json_ui_activated = true
|
39
|
-
request.variant = :ui
|
40
|
-
|
41
|
-
if request.format.html? && params[:_skip_render] != 'true'
|
42
|
-
@__json_ui_rendering = true
|
43
|
-
request.format = 'json'
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def __json_ui_commit(options)
|
49
|
-
if @__json_ui_rendering
|
50
|
-
if (hash = json_transformation_start).is_a?(Hash)
|
51
|
-
case params[:_render]
|
52
|
-
when 'v1'
|
53
|
-
__json_ui_vue(hash, options)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|
58
|
-
|
59
|
-
private
|
60
|
-
|
61
|
-
def __json_ui_vue(hash, options)
|
62
|
-
renderer_path = options[:renderer_path]
|
63
|
-
@__json_ui_orig_page = response.body
|
64
|
-
response.body = render_to_string(template: renderer_path, layout: false, content_type: 'text/html', locals: { page: hash, options: options })
|
65
|
-
end
|
66
|
-
end
|
@@ -1,13 +0,0 @@
|
|
1
|
-
module Glib::Json::Validation
|
2
|
-
def __json_validate_perform
|
3
|
-
if Rails.env.development? && params[:_validate] == 'true'
|
4
|
-
if (hash = json_transformation_start).is_a?(Hash)
|
5
|
-
json_validate = JSONValidate.new(hash)
|
6
|
-
response_message = json_validate.valid?
|
7
|
-
hash[:_json] = {
|
8
|
-
validationErrors: response_message
|
9
|
-
}
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
module Glib
|
2
|
-
module DynamicTextsHelper
|
3
|
-
def dt(key, default_value = '', **args)
|
4
|
-
new_key = key
|
5
|
-
options = {
|
6
|
-
scope: args.fetch(:scope, 'itinerarybuilder'),
|
7
|
-
lang: args.fetch(:lang, 'en')
|
8
|
-
}
|
9
|
-
|
10
|
-
if key.starts_with?('.')
|
11
|
-
new_key = "#{controller_name}.#{action_name}#{key}"
|
12
|
-
end
|
13
|
-
|
14
|
-
content = Glib::Text.get_content(new_key, default_value, options: options)
|
15
|
-
content.gsub(/\{\{(\w+)\}\}/) { args.fetch($1.to_sym, "{{#{$1}}}") }
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
data/app/models/glib/text.rb
DELETED
@@ -1,36 +0,0 @@
|
|
1
|
-
module Glib
|
2
|
-
class Text < Glib::DynamicTextRecord
|
3
|
-
validates :scope, presence: true
|
4
|
-
validates :lang, presence: true
|
5
|
-
validates :key, presence: true, uniqueness: { scope: [:scope, :lang] }
|
6
|
-
validates :content, presence: true
|
7
|
-
|
8
|
-
after_save :update_to_redis
|
9
|
-
|
10
|
-
def self.get_content(key, default_value, options:)
|
11
|
-
scope_key = "#{options[:scope]}.#{options[:lang]}.#{key}"
|
12
|
-
|
13
|
-
unless content = $dt_redis.get(scope_key)
|
14
|
-
if text = find_by(scope: options[:scope], lang: options[:lang], key: key)
|
15
|
-
update_content(scope_key, text.content)
|
16
|
-
content = text.content
|
17
|
-
else
|
18
|
-
create(scope: options[:scope], lang: options[:lang], key: key, content: default_value)
|
19
|
-
update_content(scope_key, default_value)
|
20
|
-
content = default_value
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
content
|
25
|
-
end
|
26
|
-
|
27
|
-
private
|
28
|
-
def self.update_content(scope_key, content)
|
29
|
-
$dt_redis.set(scope_key, content)
|
30
|
-
end
|
31
|
-
|
32
|
-
def update_to_redis
|
33
|
-
Glib::Text.update_content("#{scope}.#{lang}.#{key}", content)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module Glib
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../../templates', __FILE__)
|
5
|
-
|
6
|
-
class_option :redis_env_key, type: :string, default: 'DT_REDIS_URL'
|
7
|
-
class_option :database_env_key, type: :string, default: 'DT_DATABASE_URL'
|
8
|
-
class_option :app_name, type: :string, default: Rails.application.class.parent_name
|
9
|
-
|
10
|
-
def copy_initializer
|
11
|
-
template '20191017062519_create_texts.rb', 'db/dynamic_text_migrate/20191017062519_create_texts.rb'
|
12
|
-
template '20191024063257_add_scope_to_texts.rb', 'db/dynamic_text_migrate/20191024063257_add_scope_to_texts.rb'
|
13
|
-
template '20191112095018_add_lang_to_texts.rb', 'db/dynamic_text_migrate/20191112095018_add_lang_to_texts.rb'
|
14
|
-
template 'dynamic_text.rb', 'config/initializers/dynamic_text.rb'
|
15
|
-
template 'database.yml', 'config/database.yml'
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# PostgreSQL. Versions 9.1 and up are supported.
|
2
|
-
#
|
3
|
-
# Install the pg driver:
|
4
|
-
# gem install pg
|
5
|
-
# On OS X with Homebrew:
|
6
|
-
# gem install pg -- --with-pg-config=/usr/local/bin/pg_config
|
7
|
-
# On OS X with MacPorts:
|
8
|
-
# gem install pg -- --with-pg-config=/opt/local/lib/postgresql84/bin/pg_config
|
9
|
-
# On Windows:
|
10
|
-
# gem install pg
|
11
|
-
# Choose the win32 build.
|
12
|
-
# Install PostgreSQL and put its /bin directory on your path.
|
13
|
-
#
|
14
|
-
# Configure Using Gemfile
|
15
|
-
# gem 'pg'
|
16
|
-
#
|
17
|
-
default: &default
|
18
|
-
adapter: postgresql
|
19
|
-
encoding: unicode
|
20
|
-
# For details on connection pooling, see Rails configuration guide
|
21
|
-
# http://guides.rubyonrails.org/configuring.html#database-pooling
|
22
|
-
pool: <%= "\<\%\= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } \%\>" %>
|
23
|
-
host: <%= "\<\%\= ENV.fetch(\"DATABASE_HOST\") {} \%\>" %>
|
24
|
-
username: <%= "\<\%\= ENV.fetch(\"DATABASE_USER\") {} \%\>" %>
|
25
|
-
password: <%= "\<\%\= ENV.fetch(\"DATABASE_PASSWORD\") {} \%\>" %>
|
26
|
-
|
27
|
-
development:
|
28
|
-
primary:
|
29
|
-
<<: *default
|
30
|
-
database: <%= "\<\%\= ENV.fetch(\"DATABASE_NAME\") { \"#{options[:app_name]}\" } + \"_development\" \%\>" %>
|
31
|
-
dynamic_text:
|
32
|
-
<<: *default
|
33
|
-
migrations_paths: db/dynamic_text_migrate
|
34
|
-
database: <%= "\<\%\= ENV.fetch(\"DT_DATABASE_NAME\") { \"DynamicText\" } + \"_development\" \%\>" %>
|
35
|
-
|
36
|
-
# The specified database role being used to connect to postgres.
|
37
|
-
# To create additional roles in postgres see `$ createuser --help`.
|
38
|
-
# When left blank, postgres will use the default role. This is
|
39
|
-
# the same name as the operating system user that initialized the database.
|
40
|
-
#username: ItineraryBuilder
|
41
|
-
|
42
|
-
# The password associated with the postgres role (username).
|
43
|
-
#password:
|
44
|
-
|
45
|
-
# Connect on a TCP socket. Omitted by default since the client uses a
|
46
|
-
# domain socket that doesn't need configuration. Windows does not have
|
47
|
-
# domain sockets, so uncomment these lines.
|
48
|
-
#host: localhost
|
49
|
-
|
50
|
-
# The TCP port the server listens on. Defaults to 5432.
|
51
|
-
# If your server runs on a different port number, change accordingly.
|
52
|
-
#port: 5432
|
53
|
-
|
54
|
-
# Schema search path. The server defaults to $user,public
|
55
|
-
#schema_search_path: myapp,sharedapp,public
|
56
|
-
|
57
|
-
# Minimum log levels, in increasing order:
|
58
|
-
# debug5, debug4, debug3, debug2, debug1,
|
59
|
-
# log, notice, warning, error, fatal, and panic
|
60
|
-
# Defaults to warning.
|
61
|
-
#min_messages: notice
|
62
|
-
|
63
|
-
# Warning: The database defined as "test" will be erased and
|
64
|
-
# re-generated from your development database when you run "rake".
|
65
|
-
# Do not set this db to the same as development or production.
|
66
|
-
test:
|
67
|
-
primary:
|
68
|
-
<<: *default
|
69
|
-
database: <%= "\<\%\= ENV.fetch(\"DATABASE_NAME\") { \"#{options[:app_name]}\" } + \"_test\" \%\>" %>
|
70
|
-
dynamic_text:
|
71
|
-
<<: *default
|
72
|
-
migrations_paths: db/dynamic_text_migrate
|
73
|
-
database: <%= "\<\%\= ENV.fetch(\"DT_DATABASE_NAME\") { \"DynamicText\" } + \"_test\" \%\>" %>
|
74
|
-
|
75
|
-
# As with config/secrets.yml, you never want to store sensitive information,
|
76
|
-
# like your database password, in your source code. If your source code is
|
77
|
-
# ever seen by anyone, they now have access to your database.
|
78
|
-
#
|
79
|
-
# Instead, provide the password as a unix environment variable when you boot
|
80
|
-
# the app. Read http://guides.rubyonrails.org/configuring.html#configuring-a-database
|
81
|
-
# for a full rundown on how to provide these environment variables in a
|
82
|
-
# production deployment.
|
83
|
-
#
|
84
|
-
# On Heroku and other platform providers, you may have a full connection URL
|
85
|
-
# available as an environment variable. For example:
|
86
|
-
#
|
87
|
-
# DATABASE_URL="postgres://myuser:mypass@localhost/somedatabase"
|
88
|
-
#
|
89
|
-
# You can use this database configuration with:
|
90
|
-
#
|
91
|
-
# production:
|
92
|
-
# url: <%= "\<\%\= ENV[\'DATABASE_URL\'] \%\>" %>
|
93
|
-
#
|
94
|
-
|
95
|
-
production_default: &production_default
|
96
|
-
adapter: postgresql
|
97
|
-
encoding: unicode
|
98
|
-
pool: <%= "\<\%\= ENV.fetch(\"RAILS_MAX_THREADS\") { 5 } \%\>" %>
|
99
|
-
|
100
|
-
production:
|
101
|
-
primary:
|
102
|
-
<<: *production_default
|
103
|
-
url: <%= "\<\%\= ENV[\"DATABASE_URL\"] \%\>" %>
|
104
|
-
dynamic_text:
|
105
|
-
<<: *production_default
|
106
|
-
migrations_paths: db/dynamic_text_migrate
|
107
|
-
url: <%= "\<\%\= ENV[\"#{options[:database_env_key]}\"] \%\>" %>
|