glib-web 0.5.5

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.
Files changed (158) hide show
  1. checksums.yaml +7 -0
  2. data/app/controllers/concerns/glib/auth/policy.rb +148 -0
  3. data/app/controllers/concerns/glib/json/dynamic_text.rb +126 -0
  4. data/app/controllers/concerns/glib/json/libs.rb +144 -0
  5. data/app/controllers/concerns/glib/json/new_dynamic_text.rb +122 -0
  6. data/app/controllers/concerns/glib/json/transformation.rb +11 -0
  7. data/app/controllers/concerns/glib/json/traversal.rb +85 -0
  8. data/app/controllers/concerns/glib/json/ui.rb +70 -0
  9. data/app/controllers/concerns/glib/json/validation.rb +13 -0
  10. data/app/controllers/glib/home_controller.rb +16 -0
  11. data/app/helpers/glib/app_feature_support_helper.rb +16 -0
  12. data/app/helpers/glib/dynamic_images_helper.rb +52 -0
  13. data/app/helpers/glib/dynamic_texts_helper.rb +42 -0
  14. data/app/helpers/glib/forms_helper.rb +15 -0
  15. data/app/helpers/glib/json_ui/abstract_builder.rb +281 -0
  16. data/app/helpers/glib/json_ui/action_builder.rb +81 -0
  17. data/app/helpers/glib/json_ui/action_builder/dialogs.rb +58 -0
  18. data/app/helpers/glib/json_ui/action_builder/http.rb +19 -0
  19. data/app/helpers/glib/json_ui/action_builder/sheets.rb +15 -0
  20. data/app/helpers/glib/json_ui/action_builder/snackbars.rb +41 -0
  21. data/app/helpers/glib/json_ui/action_builder/windows.rb +25 -0
  22. data/app/helpers/glib/json_ui/dynamic_field_builders.rb +25 -0
  23. data/app/helpers/glib/json_ui/generic_builders.rb +28 -0
  24. data/app/helpers/glib/json_ui/list_builders.rb +87 -0
  25. data/app/helpers/glib/json_ui/menu_builder.rb +52 -0
  26. data/app/helpers/glib/json_ui/page_helper.rb +187 -0
  27. data/app/helpers/glib/json_ui/response_helper.rb +23 -0
  28. data/app/helpers/glib/json_ui/split_builders.rb +32 -0
  29. data/app/helpers/glib/json_ui/styling_helper.rb +25 -0
  30. data/app/helpers/glib/json_ui/table_builders.rb +74 -0
  31. data/app/helpers/glib/json_ui/view_builder.rb +185 -0
  32. data/app/helpers/glib/json_ui/view_builder/banners.rb +24 -0
  33. data/app/helpers/glib/json_ui/view_builder/charts.rb +33 -0
  34. data/app/helpers/glib/json_ui/view_builder/fields.rb +213 -0
  35. data/app/helpers/glib/json_ui/view_builder/panels.rb +219 -0
  36. data/app/models/glib/active_storage/attachment.rb +9 -0
  37. data/app/models/glib/active_storage/blob.rb +9 -0
  38. data/app/models/glib/dynamic_text_record.rb +9 -0
  39. data/app/models/glib/text.rb +96 -0
  40. data/app/policies/glib/application_policy.rb +164 -0
  41. data/app/validators/email_typo_validator.rb +38 -0
  42. data/app/validators/email_validator.rb +7 -0
  43. data/app/validators/url_validator.rb +20 -0
  44. data/app/views/app/views/json_ui/vue/renderer.html.erb +35 -0
  45. data/app/views/json_ui/garage/_nav_menu.json.jbuilder +71 -0
  46. data/app/views/json_ui/garage/actions/_dialogs.json.jbuilder +104 -0
  47. data/app/views/json_ui/garage/actions/_http.json.jbuilder +18 -0
  48. data/app/views/json_ui/garage/actions/_reload.json.jbuilder +17 -0
  49. data/app/views/json_ui/garage/actions/_sheets.json.jbuilder +19 -0
  50. data/app/views/json_ui/garage/actions/_snackbars.json.jbuilder +33 -0
  51. data/app/views/json_ui/garage/actions/_timeouts.json.jbuilder +18 -0
  52. data/app/views/json_ui/garage/actions/_windows.json.jbuilder +24 -0
  53. data/app/views/json_ui/garage/actions/dialogs_oauth_post.json.jbuilder +6 -0
  54. data/app/views/json_ui/garage/actions/index.json.jbuilder +23 -0
  55. data/app/views/json_ui/garage/forms/_alert_post_data.json.jbuilder +7 -0
  56. data/app/views/json_ui/garage/forms/basic.json.jbuilder +34 -0
  57. data/app/views/json_ui/garage/forms/basic_post.json.jbuilder +8 -0
  58. data/app/views/json_ui/garage/forms/checkboxes.json.jbuilder +44 -0
  59. data/app/views/json_ui/garage/forms/dynamic_group.json.jbuilder +41 -0
  60. data/app/views/json_ui/garage/forms/dynamic_select.json.jbuilder +25 -0
  61. data/app/views/json_ui/garage/forms/dynamic_select_data.json.jbuilder +38 -0
  62. data/app/views/json_ui/garage/forms/file_upload.json.jbuilder +58 -0
  63. data/app/views/json_ui/garage/forms/floating_submit.json.jbuilder +31 -0
  64. data/app/views/json_ui/garage/forms/generic_post.json.jbuilder +3 -0
  65. data/app/views/json_ui/garage/forms/get_request.json.jbuilder +28 -0
  66. data/app/views/json_ui/garage/forms/index.json.jbuilder +101 -0
  67. data/app/views/json_ui/garage/forms/pickers.json.jbuilder +46 -0
  68. data/app/views/json_ui/garage/forms/rich_text.json.jbuilder +40 -0
  69. data/app/views/json_ui/garage/forms/selects.json.jbuilder +70 -0
  70. data/app/views/json_ui/garage/forms/show_hide.json.jbuilder +88 -0
  71. data/app/views/json_ui/garage/forms/styled_boxes.json.jbuilder +32 -0
  72. data/app/views/json_ui/garage/forms/submission_flow.json.jbuilder +17 -0
  73. data/app/views/json_ui/garage/forms/submission_flow_post.json.jbuilder +24 -0
  74. data/app/views/json_ui/garage/forms/submission_indicator.json.jbuilder +63 -0
  75. data/app/views/json_ui/garage/forms/submission_indicator_post.json.jbuilder +25 -0
  76. data/app/views/json_ui/garage/forms/text_validation.json.jbuilder +22 -0
  77. data/app/views/json_ui/garage/home/blank.json.jbuilder +11 -0
  78. data/app/views/json_ui/garage/home/index.json.jbuilder +32 -0
  79. data/app/views/json_ui/garage/home/slow.json.jbuilder +11 -0
  80. data/app/views/json_ui/garage/lists/_infinite_scroll_section.json.jbuilder +20 -0
  81. data/app/views/json_ui/garage/lists/edit_actions.json.jbuilder +19 -0
  82. data/app/views/json_ui/garage/lists/fab.json.jbuilder +14 -0
  83. data/app/views/json_ui/garage/lists/index.json.jbuilder +23 -0
  84. data/app/views/json_ui/garage/lists/infinite_scroll.json.jbuilder +38 -0
  85. data/app/views/json_ui/garage/lists/templating.json.jbuilder +35 -0
  86. data/app/views/json_ui/garage/notifications/index.json.jbuilder +18 -0
  87. data/app/views/json_ui/garage/notifications/web_socket.json.jbuilder +60 -0
  88. data/app/views/json_ui/garage/pages/flat_centered.json.jbuilder +29 -0
  89. data/app/views/json_ui/garage/pages/full_width.json.jbuilder +29 -0
  90. data/app/views/json_ui/garage/pages/full_width_height.json.jbuilder +16 -0
  91. data/app/views/json_ui/garage/pages/index.json.jbuilder +47 -0
  92. data/app/views/json_ui/garage/pages/layout.json.jbuilder +19 -0
  93. data/app/views/json_ui/garage/pages/loading_indicator.json.jbuilder +10 -0
  94. data/app/views/json_ui/garage/pages/nav_buttons.json.jbuilder +21 -0
  95. data/app/views/json_ui/garage/pages/tab_bar.json.jbuilder +27 -0
  96. data/app/views/json_ui/garage/panels/_styled.json.jbuilder +78 -0
  97. data/app/views/json_ui/garage/panels/card.json.jbuilder +4 -0
  98. data/app/views/json_ui/garage/panels/carousel.json.jbuilder +16 -0
  99. data/app/views/json_ui/garage/panels/custom.json.jbuilder +17 -0
  100. data/app/views/json_ui/garage/panels/flow.json.jbuilder +49 -0
  101. data/app/views/json_ui/garage/panels/horizontal.json.jbuilder +91 -0
  102. data/app/views/json_ui/garage/panels/index.json.jbuilder +132 -0
  103. data/app/views/json_ui/garage/panels/outlined.json.jbuilder +4 -0
  104. data/app/views/json_ui/garage/panels/responsive.json.jbuilder +88 -0
  105. data/app/views/json_ui/garage/panels/split.json.jbuilder +183 -0
  106. data/app/views/json_ui/garage/panels/vertical.json.jbuilder +50 -0
  107. data/app/views/json_ui/garage/services/dynamic_text.json.jbuilder +13 -0
  108. data/app/views/json_ui/garage/services/image.json.jbuilder +47 -0
  109. data/app/views/json_ui/garage/services/index.json.jbuilder +17 -0
  110. data/app/views/json_ui/garage/tables/_autoload_section.json.jbuilder +13 -0
  111. data/app/views/json_ui/garage/tables/autoload_all.json.jbuilder +38 -0
  112. data/app/views/json_ui/garage/tables/autoload_as_needed.json.jbuilder +39 -0
  113. data/app/views/json_ui/garage/tables/export_import.json.jbuilder +29 -0
  114. data/app/views/json_ui/garage/tables/horizontal_scroll.json.jbuilder +26 -0
  115. data/app/views/json_ui/garage/tables/index.json.jbuilder +26 -0
  116. data/app/views/json_ui/garage/tables/layout.json.jbuilder +38 -0
  117. data/app/views/json_ui/garage/views/_chart_data.json.jbuilder +17 -0
  118. data/app/views/json_ui/garage/views/banners.json.jbuilder +51 -0
  119. data/app/views/json_ui/garage/views/calendar_data.json.jbuilder +30 -0
  120. data/app/views/json_ui/garage/views/carousels.json.jbuilder +37 -0
  121. data/app/views/json_ui/garage/views/charts.json.jbuilder +115 -0
  122. data/app/views/json_ui/garage/views/images.json.jbuilder +89 -0
  123. data/app/views/json_ui/garage/views/index.json.jbuilder +48 -0
  124. data/app/views/json_ui/garage/views/links.json.jbuilder +70 -0
  125. data/app/views/json_ui/garage/views/map_data.json.jbuilder +43 -0
  126. data/app/views/json_ui/garage/views/markdowns.json.jbuilder +41 -0
  127. data/app/views/json_ui/garage/views/misc.json.jbuilder +34 -0
  128. data/app/views/json_ui/garage/views/texts.json.jbuilder +41 -0
  129. data/app/views/layouts/json_ui/renderer.html.erb +32 -0
  130. data/config/routes.rb +8 -0
  131. data/lib/generators/glib/install_generator.rb +24 -0
  132. data/lib/generators/templates/20191017062519_create_texts.rb +12 -0
  133. data/lib/generators/templates/20191024063257_add_scope_to_texts.rb +7 -0
  134. data/lib/generators/templates/20191112095018_add_lang_to_texts.rb +7 -0
  135. data/lib/generators/templates/20191126071051_create_active_storage_tables.active_storage.rb +27 -0
  136. data/lib/generators/templates/database.yml +107 -0
  137. data/lib/generators/templates/dynamic_text.rb +2 -0
  138. data/lib/glib-web.rb +8 -0
  139. data/lib/glib/crypt.rb +1 -0
  140. data/lib/glib/crypt/utils.rb +26 -0
  141. data/lib/glib/dynamic_text.rb +1 -0
  142. data/lib/glib/dynamic_text/config.rb +21 -0
  143. data/lib/glib/engine.rb +7 -0
  144. data/lib/glib/json_crawler.rb +10 -0
  145. data/lib/glib/json_crawler/action_crawler.rb +20 -0
  146. data/lib/glib/json_crawler/action_crawlers/action_http.rb +14 -0
  147. data/lib/glib/json_crawler/action_crawlers/forms_submit.rb +48 -0
  148. data/lib/glib/json_crawler/action_crawlers/menu.rb +12 -0
  149. data/lib/glib/json_crawler/action_crawlers/nav_initiate.rb +15 -0
  150. data/lib/glib/json_crawler/action_crawlers/windows_open.rb +28 -0
  151. data/lib/glib/json_crawler/coverage.rb +20 -0
  152. data/lib/glib/json_crawler/http.rb +120 -0
  153. data/lib/glib/json_crawler/router.rb +86 -0
  154. data/lib/glib/test_helpers.rb +40 -0
  155. data/lib/glib/value.rb +7 -0
  156. data/lib/glib/version.rb +5 -0
  157. data/lib/tasks/db.rake +95 -0
  158. metadata +246 -0
@@ -0,0 +1,81 @@
1
+ module Glib
2
+ module JsonUi
3
+ class ActionBuilder < AbstractBuilder
4
+ def method_missing m, *args
5
+ add_singleton_element_v1 'action', m, *args
6
+ end
7
+
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
+
37
+ end
38
+
39
+ ### Action definitions
40
+
41
+ module Forms
42
+ class Submit < Action
43
+ end
44
+
45
+ end
46
+
47
+ # Consider deprecating this. See Data
48
+ module Auth
49
+ class SaveCsrfToken < Action
50
+ string :token
51
+ action :onSave
52
+ end
53
+
54
+ end
55
+
56
+ module Timeouts
57
+ class Set < Action
58
+ int :interval # Milliseconds
59
+ action :onTimeout
60
+ end
61
+
62
+ # FUTURE
63
+ class Clear < Action
64
+ end
65
+ end
66
+
67
+ # FUTURE
68
+ module Data
69
+ class SaveCsrfToken < Action
70
+ string :token
71
+ action :onSave
72
+ end
73
+
74
+ class Clear < Action
75
+ end
76
+ end
77
+
78
+ ###
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,58 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+ module Dialogs
3
+ class Alert < Action
4
+ string :message
5
+ action :onLoad
6
+ action :onClose
7
+ end
8
+
9
+ class Show < Action
10
+ string :body
11
+ action :onLoad
12
+ action :onClose
13
+ end
14
+
15
+ # Deprecated in favour of `sheets/select`
16
+ class Options < Action
17
+ string :message
18
+
19
+ def buttons(block)
20
+ json.buttons do
21
+ block.call page.menu_builder
22
+ end
23
+ end
24
+ end
25
+
26
+ class Show < Action
27
+ panels_builder :content, :body
28
+
29
+ # Future plan
30
+ # panels_builder :content, :body, :footer
31
+ end
32
+
33
+ class Open < Action
34
+ string :url, cache: true
35
+ end
36
+
37
+ class Close < Action
38
+ action :onClose
39
+ end
40
+
41
+ class Oauth < Action
42
+ hash :provider
43
+ action :onSuccess
44
+ string :providerParamName
45
+ string :callbackUrlParamName
46
+ end
47
+
48
+ # TODO: Consider switching to `notifications/alert`
49
+ class Notification < Action
50
+ string :title
51
+ string :message
52
+ string :tag
53
+ int :timeout
54
+ action :onClick
55
+ end
56
+
57
+ end
58
+ end
@@ -0,0 +1,19 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+ module Http
3
+ class Post < Action
4
+ string :url, cache: true
5
+ hash :formData
6
+ end
7
+
8
+ class Patch < Action
9
+ string :url, cache: true
10
+ hash :formData
11
+ end
12
+
13
+ class Delete < Action
14
+ string :url, cache: true
15
+ hash :formData
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,15 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+ module Sheets
3
+
4
+ class Select < Action
5
+ string :message
6
+
7
+ def buttons(block)
8
+ json.buttons do
9
+ block.call page.menu_builder
10
+ end
11
+ end
12
+ end
13
+
14
+ end
15
+ end
@@ -0,0 +1,41 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+
3
+ module Snackbars
4
+ class Alert < Action
5
+ string :message
6
+ # string :message_format
7
+ action :onClose
8
+
9
+ string :verticalPosition
10
+ string :horizontalPosition
11
+ singleton_array :styleClass, :styleClasses
12
+ end
13
+
14
+ # class Confirm < Action
15
+ # string :message
16
+ # action :onConfirm
17
+ # action :onCancel
18
+
19
+ # string :verticalPosition
20
+ # string :horizontalPosition
21
+ # singleton_array :styleClass, :styleClasses
22
+ # end
23
+
24
+ class Select < Action
25
+ string :message
26
+
27
+ string :verticalPosition
28
+ string :horizontalPosition
29
+ singleton_array :styleClass, :styleClasses
30
+
31
+ def buttons(block)
32
+ json.buttons do
33
+ block.call page.menu_builder
34
+ end
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,25 @@
1
+ class Glib::JsonUi::ActionBuilder
2
+ module Windows
3
+ class Close < Action
4
+ action :onClose
5
+ end
6
+
7
+ class CloseAll < Action
8
+ action :onClose
9
+ end
10
+
11
+ class Open < Action
12
+ string :url, cache: true
13
+ action :onOpen
14
+ end
15
+
16
+ class OpenWeb < Action
17
+ string :url
18
+ end
19
+
20
+ class Reload < Action
21
+ string :url, cache: true
22
+ action :onReload
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,25 @@
1
+ module Glib
2
+ module JsonUi
3
+ module DynamicFieldBuilders
4
+
5
+ class Group < AbstractBuilder
6
+ def initialize json, page, template
7
+ super json, page
8
+ @template = template
9
+ end
10
+
11
+ # string :titlePrefix
12
+ def titlePrefix(string)
13
+ json.titlePrefix string
14
+ end
15
+
16
+ def template(options = {})
17
+ # json.template do
18
+ page.vertical_content(options)
19
+ # end
20
+ end
21
+ end
22
+
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,28 @@
1
+ module Glib
2
+ module JsonUi
3
+ module GenericBuilders
4
+
5
+ class Content < AbstractBuilder
6
+ def initialize(json, page, template)
7
+ super json, page
8
+ @template = template
9
+ end
10
+
11
+ def definePanels(names)
12
+ names.each do |name|
13
+ define_singleton_method(name) do |options|
14
+ json.set!(name) { page.vertical_content(options) }
15
+ end
16
+ end
17
+ end
18
+
19
+ # def body(options = {})
20
+ # json.body do
21
+ # page.vertical_content(options)
22
+ # end
23
+ # end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,87 @@
1
+ module Glib
2
+ module JsonUi
3
+ module ListBuilders
4
+ class Template < AbstractBuilder
5
+ def method_missing(m, *args)
6
+ add_element_to_array 'template', m, *args
7
+ end
8
+
9
+ class AbstractTemplate < JsonUiElement
10
+ # hash :padding
11
+
12
+ def editButtons(block)
13
+ json.editButtons do
14
+ block.call page.menu_builder
15
+ end
16
+ end
17
+
18
+ def chips(block)
19
+ json.chips do
20
+ block.call page.menu_builder
21
+ end
22
+ end
23
+ end
24
+
25
+ class Thumbnail < AbstractTemplate
26
+ string :title
27
+ string :subtitle
28
+ string :subsubtitle
29
+ string :imageUrl
30
+ action :onClick
31
+ icon :icon
32
+ bool :avatar
33
+
34
+ # # NOTE: Experimental. Still deciding whether this needs to be a full blown panel or
35
+ # # an array of badges (with relevant properties, e.g. text, color, etc)
36
+ # views :accessoryViews
37
+ end
38
+
39
+ class Featured < Thumbnail
40
+ end
41
+
42
+ class Custom < Thumbnail
43
+ string :template
44
+
45
+ # TODO: Experimental
46
+ hash :extra
47
+
48
+ # TODO: Deprecate
49
+ hash :data
50
+ end
51
+ end
52
+
53
+ class Section < AbstractBuilder
54
+ def initialize(json, page, template)
55
+ super json, page
56
+ @template = template
57
+ end
58
+
59
+ def header(options = {})
60
+ json.header do
61
+ page.vertical_content(options)
62
+ end
63
+ end
64
+
65
+ def rows(options = {})
66
+ block = options[:builder]
67
+ json.rows do
68
+ if (objects = options[:objects])
69
+ objects.each_with_index do |object, index|
70
+ block&.call @template, object, index
71
+ end
72
+ else
73
+ block&.call @template
74
+ end
75
+ end
76
+ end
77
+
78
+ def footer(options = {})
79
+ json.footer do
80
+ page.vertical_content(options)
81
+ end
82
+ end
83
+ end
84
+
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,52 @@
1
+ module Glib
2
+ module JsonUi
3
+ class MenuBuilder < AbstractBuilder
4
+ def method_missing m, *args
5
+ add_element_to_array_v1 nil, m, *args
6
+ end
7
+
8
+ class MenuItem < JsonUiElement
9
+ end
10
+
11
+ class Button < MenuItem
12
+ string :text
13
+ icon :icon
14
+ action :onClick
15
+ bool :disabled
16
+ singleton_array :styleClass, :styleClasses
17
+
18
+ def childItems(block)
19
+ json.childItems do
20
+ block.call page.menu_builder
21
+ end
22
+ end
23
+
24
+ def created
25
+ json.type 'button'
26
+ end
27
+ end
28
+
29
+ class Divider < MenuItem
30
+ # Override
31
+ def created
32
+ json.type 'divider'
33
+ end
34
+ end
35
+
36
+ class Label < MenuItem
37
+ string :text
38
+ singleton_array :styleClass, :styleClasses
39
+
40
+ # Override
41
+ def created
42
+ json.type 'label'
43
+ end
44
+ end
45
+
46
+ class MenuLeftBottom < Button
47
+ icon :icon
48
+ array :buttons
49
+ end
50
+ end
51
+ end
52
+ end
@@ -0,0 +1,187 @@
1
+ module Glib
2
+ module JsonUi
3
+ module PageHelper
4
+ def json_ui_garage_url(options = {})
5
+ Glib::Web::Engine.routes.url_helpers.json_ui_garage_url(options.merge(
6
+ protocol: request.protocol,
7
+ host: request.host,
8
+ port: request.port,
9
+ _render: params[:_render], format: params[:format])
10
+ )
11
+ end
12
+
13
+ # TODO: Remove the block
14
+ def json_ui_page(json, &block)
15
+ @__json_ui_page ||= Page.new(json, self)
16
+ block&.call @__json_ui_page
17
+ @__json_ui_page
18
+ end
19
+
20
+ # # Use this only if you need to generate json independently from the current `json_ui_page`
21
+ # def json_ui_menu(&block)
22
+ # @__json_ui_menu_page ||= Page.new(Jbuilder.new, self)
23
+ # json = @__json_ui_menu_page.json
24
+ # json.nil!
25
+ # block&.call @__json_ui_menu_page.menu_builder
26
+ # json.attributes!
27
+ # end
28
+
29
+ # # Use this only if you need to generate json independently from the current `json_ui_page`
30
+ # def json_ui_panel(&block)
31
+ # @__json_ui_panel_page ||= Page.new(Jbuilder.new, self)
32
+ # json = @__json_ui_panel_page.json
33
+ # json.nil!
34
+ # block&.call @__json_ui_panel_page.view_builder
35
+ # json.attributes!
36
+ # end
37
+
38
+ def json_ui_section(json, &block)
39
+ @__json_ui_section ||= Page.new(json, self)
40
+ @__json_ui_section.list_section_builder
41
+ end
42
+
43
+ class Page
44
+ attr_reader :json, :context, :view_builder, :action_builder, :menu_builder
45
+ attr_reader :list_section_builder, :table_section_builder, :drawer_content_builder, :split_content_builder
46
+
47
+ # See Panels::Form
48
+ attr_accessor :current_form
49
+
50
+ def initialize(json, context)
51
+ @json = json
52
+ @context = context
53
+
54
+ @view_builder = ViewBuilder.new(json, self, true)
55
+ @action_builder = ActionBuilder.new(json, self)
56
+ @menu_builder = MenuBuilder.new(json, self)
57
+
58
+ @list_section_builder = ListBuilders::Section.new(json, self, ListBuilders::Template.new(json, self))
59
+ @drawer_content_builder = ListBuilders::Section.new(json, self, @menu_builder)
60
+ @table_section_builder = TableBuilders::Section.new(json, self, TableBuilders::Template.new(json, self))
61
+ @split_content_builder = SplitBuilders::Content.new(json, self, @view_builder)
62
+
63
+ # TODO: Deprecate
64
+ # For generic `body` builder. For others, use content_builder()
65
+ # @generic_content_builder = GenericBuilders::Content.new(json, self, @view_builder)
66
+ end
67
+
68
+ def content_builder(panelNames)
69
+ # NOTE: Can potentially be cached
70
+ builder = GenericBuilders::Content.new(json, self, @view_builder)
71
+ builder.definePanels(panelNames)
72
+ builder
73
+ end
74
+
75
+ def rightNavButtons
76
+ json.rightNavButtons do
77
+ yield @menu_builder
78
+ end
79
+ end
80
+
81
+ def template(template)
82
+ json.template template
83
+ end
84
+
85
+ def leftDrawer(options = {})
86
+ json.leftDrawer do
87
+ [:styleClasses].each do |name|
88
+ if (value = options.delete(name))
89
+ json.set! name, value
90
+ end
91
+ end
92
+ options[:content]&.call drawer_content_builder
93
+ end
94
+ end
95
+
96
+ def navBar(options = {})
97
+ json.navBar do
98
+ # json.leftItems do
99
+ # options[:leftItems]&.call @menu_builder
100
+ # end
101
+ # json.logoUrl "http://localhost:3000/assets/logo_dark-02d9b6a91fdbf22515da7b921d31367b70696214415f6789d2f90232e4a287b7.svg"
102
+ json.rightItems do
103
+ options[:rightItems]&.call @menu_builder
104
+ end
105
+ end
106
+ end
107
+
108
+ def header(options = {})
109
+ json.header do
110
+ vertical_content(options)
111
+ end
112
+ end
113
+
114
+ def footer(options = {})
115
+ json.footer do
116
+ vertical_content(options)
117
+ end
118
+ end
119
+
120
+ def body(options = {})
121
+ json.body do
122
+ vertical_content(options)
123
+ end
124
+ end
125
+
126
+ def list(options = {})
127
+ json.body do
128
+ json.childViews do
129
+ @view_builder.add_view('panels_list', options.reverse_merge(width: 'matchParent'))
130
+ end
131
+ end
132
+ end
133
+
134
+ def table(options = {})
135
+ json.body do
136
+ json.childViews do
137
+ @view_builder.add_view('panels_table', options.reverse_merge(width: 'matchParent'))
138
+ end
139
+ end
140
+ end
141
+
142
+ def scroll(options = {})
143
+ json.body do
144
+ json.childViews do
145
+ @view_builder.add_view('panels_scroll', options.reverse_merge(width: 'matchParent'))
146
+ end
147
+ end
148
+ end
149
+
150
+ def form(options = {})
151
+ scroll childViews: ->(scroll) do
152
+ @view_builder.add_view('panels_form', options.reverse_merge(width: 'matchParent'))
153
+ end
154
+ end
155
+
156
+ def data(options = {})
157
+ options[:content].call(ViewBuilder.new(json, self, false))
158
+ end
159
+
160
+ def vertical_content(options)
161
+ # TODO: try disabling this
162
+ # options = options.reverse_merge(width: 'matchParent')
163
+
164
+ [:padding, :backgroundColor, :width, :height].each do |name|
165
+ if (value = options.delete(name))
166
+ json.set! name, value
167
+ end
168
+ end
169
+ json.childViews do
170
+ if (childViews = options.delete(:childViews))
171
+ childViews.call @view_builder
172
+ end
173
+ end
174
+
175
+ raise "Invalid properties: #{options.keys}" if options.size > 0
176
+ end
177
+
178
+ def onLoad(options = {})
179
+ json.onLoad do
180
+ yield @action_builder
181
+ end
182
+ end
183
+
184
+ end
185
+ end
186
+ end
187
+ end