glib-web 8.2.0 → 8.2.2

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 (31) hide show
  1. checksums.yaml +4 -4
  2. data/app/controllers/glib/glib_direct_uploads_controller.rb +6 -2
  3. data/app/helpers/glib/format_helper.rb +8 -12
  4. data/app/helpers/glib/json_ui/abstract_builder.rb +44 -47
  5. data/app/helpers/glib/json_ui/action_builder/popovers.rb +1 -1
  6. data/app/helpers/glib/json_ui/hash_schema.rb +182 -0
  7. data/app/helpers/glib/json_ui/list_builders.rb +2 -2
  8. data/app/helpers/glib/json_ui/menu_builder.rb +8 -3
  9. data/app/helpers/glib/json_ui/view_builder/charts.rb +14 -2
  10. data/app/helpers/glib/json_ui/view_builder/fields.rb +66 -17
  11. data/app/helpers/glib/json_ui/view_builder/panels.rb +17 -11
  12. data/app/helpers/glib/json_ui/view_builder.rb +26 -6
  13. data/app/models/glib/markdown.rb +172 -0
  14. data/app/views/json_ui/garage/actions/sheet_content.json.jbuilder +1 -1
  15. data/app/views/json_ui/garage/forms/_action_text_conversion.json.jbuilder +12 -0
  16. data/app/views/json_ui/garage/forms/action_text.json.jbuilder +23 -0
  17. data/app/views/json_ui/garage/forms/action_text_conversion.json.jbuilder +5 -0
  18. data/app/views/json_ui/garage/forms/action_text_mentions.json.jbuilder +4 -0
  19. data/app/views/json_ui/garage/forms/dialogs_form.json.jbuilder +10 -10
  20. data/app/views/json_ui/garage/forms/dirty_prompt.json.jbuilder +1 -1
  21. data/app/views/json_ui/garage/forms/dynamic_group.json.jbuilder +1 -1
  22. data/app/views/json_ui/garage/forms/rich_text.json.jbuilder +1 -1
  23. data/app/views/json_ui/garage/forms/show_hide.json.jbuilder +1 -1
  24. data/app/views/json_ui/garage/test_page/charts.json.jbuilder +4 -2
  25. data/app/views/json_ui/garage/test_page/fields_actionText.json.jbuilder +104 -1
  26. data/app/views/json_ui/garage/test_page/fields_richText.json.jbuilder +45 -1
  27. data/app/views/json_ui/garage/test_page/form_dirty_fields.json.jbuilder +1 -1
  28. data/app/views/json_ui/garage/test_page/form_hidden_panels.json.jbuilder +3 -22
  29. data/app/views/json_ui/garage/views/charts.json.jbuilder +4 -2
  30. data/lib/glib/all_helpers.rb +1 -0
  31. metadata +22 -8
@@ -430,8 +430,8 @@ class Glib::JsonUi::ViewBuilder
430
430
  # deprecated
431
431
  class Table < View
432
432
  hash :nextPage
433
- hash :export, required: [:label, :fileName]
434
- hash :import, required: [:submitUrl, :paramName]
433
+ hash :export, schema: schema_open(label!: :string, fileName!: :string)
434
+ hash :import, schema: schema_open(submitUrl!: :string, paramName!: :string)
435
435
  action :onScrollToTop
436
436
  action :onScrollToBottom
437
437
 
@@ -458,7 +458,7 @@ class Glib::JsonUi::ViewBuilder
458
458
  # retired bulkEdit2 and bulkEditSg -- see the component's header comment
459
459
  # for the full mapping).
460
460
  class BulkEdit3 < View
461
- hash :import, required: [:submitUrl, :paramName]
461
+ hash :import, schema: schema_open(submitUrl!: :string, paramName!: :string)
462
462
 
463
463
  # Override
464
464
  def created
@@ -906,7 +906,7 @@ class Glib::JsonUi::ViewBuilder
906
906
  # Configuration for drag-and-drop reordering support.
907
907
  # Enables users to reorder children by dragging them.
908
908
  # @example dragSupport: { onDrop: { action: 'http/post', url: reorder_path }, paramNameForFormData: 'order' }
909
- hash :dragSupport, optional: [:onDrop, :paramNameForFormData, :paramNameForNewIndex]
909
+ hash :dragSupport, schema: { onDrop: :hash, paramNameForFormData: :string, paramNameForNewIndex: :string }
910
910
  end
911
911
 
912
912
  # Flow layout panel that wraps children like text (left to right, then top to bottom).
@@ -948,35 +948,41 @@ class Glib::JsonUi::ViewBuilder
948
948
  #
949
949
  # @see app/views/json_ui/garage/panels/flow.json.jbuilder Garage examples
950
950
  class Flow < View
951
+ BREAKPOINT_SCHEMA = {
952
+ gap: { all: :number, x: :number, y: :number },
953
+ padding: { top: :number, right: :number, bottom: :number, left: :number, x: :number, y: :number, all: :number }
954
+ }.freeze
955
+
951
956
  # Padding applied to each child element wrapper.
952
957
  # Different from the panel's own padding - this creates gaps between items.
953
958
  # @example innerPadding: { x: 10, y: 10 }
954
959
  # @example innerPadding: { top: 5, right: 10, bottom: 5, left: 10 }
955
- hash :innerPadding, optional: [:top, :right, :bottom, :left, :x, :y]
960
+ # @example innerPadding: { all: 8 }
961
+ hash :innerPadding, schema: { top: :number, right: :number, bottom: :number, left: :number, x: :number, y: :number, all: :number }
956
962
 
957
963
  # Configuration for xxl breakpoint (> 2560px).
958
964
  # @example xxl: { gap: { all: 32 }, padding: { all: 48 } }
959
- hash :xxl, optional: [:gap, :padding]
965
+ hash :xxl, schema: BREAKPOINT_SCHEMA
960
966
 
961
967
  # Configuration for xl breakpoint (1904px - 2560px).
962
968
  # @example xl: { gap: { x: 24, y: 24 } }
963
- hash :xl, optional: [:gap, :padding]
969
+ hash :xl, schema: BREAKPOINT_SCHEMA
964
970
 
965
971
  # Configuration for lg breakpoint (1264px - 1904px).
966
972
  # @example lg: { gap: { all: 16 }, padding: { x: 30, y: 30 } }
967
- hash :lg, optional: [:gap, :padding]
973
+ hash :lg, schema: BREAKPOINT_SCHEMA
968
974
 
969
975
  # Configuration for md breakpoint (960px - 1264px).
970
976
  # @example md: { gap: { y: 8, x: 8 } }
971
- hash :md, optional: [:gap, :padding]
977
+ hash :md, schema: BREAKPOINT_SCHEMA
972
978
 
973
979
  # Configuration for sm breakpoint (600px - 960px).
974
980
  # @example sm: { gap: { y: 4, x: 6 }, padding: { all: 16 } }
975
- hash :sm, optional: [:gap, :padding]
981
+ hash :sm, schema: BREAKPOINT_SCHEMA
976
982
 
977
983
  # Configuration for xs breakpoint (< 600px).
978
984
  # @example xs: { gap: { y: 2, x: 2 }, padding: { left: 10, bottom: 8 } }
979
- hash :xs, optional: [:gap, :padding]
985
+ hash :xs, schema: BREAKPOINT_SCHEMA
980
986
 
981
987
  # Child components to arrange in flow layout.
982
988
  views :childViews
@@ -6,7 +6,13 @@ module Glib
6
6
 
7
7
  included do
8
8
  string :directUploadUrl
9
- hash :accepts, optional: [:fileType, :maxFileSize, :maxFileLength, :maxFileSizeErrorText, :maxFileLengthErrorText]
9
+ hash :accepts, schema: {
10
+ fileType: [:string, :array],
11
+ maxFileSize: [:number, :string],
12
+ maxFileLength: [:number, :string],
13
+ maxFileSizeErrorText: [:string, :hash],
14
+ maxFileLengthErrorText: [:string, :hash]
15
+ }
10
16
  enum :strategy, options: [:delegate, :dropUpload]
11
17
  string :storagePrefix
12
18
  hash :metadata
@@ -123,7 +129,7 @@ module Glib
123
129
  length :width
124
130
  length :height
125
131
  color :backgroundColor
126
- hash :padding, optional: [:top, :right, :bottom, :left, :x, :y, :all]
132
+ hash :padding, schema: { top: :number, right: :number, bottom: :number, left: :number, x: :number, y: :number, all: :number }
127
133
  singleton_array :styleClass, :styleClasses
128
134
 
129
135
  hash :showIf # Deprecated: use logics_set instead
@@ -134,10 +140,10 @@ module Glib
134
140
  bool :displayed
135
141
  bool :submitWhenNotDisplayed
136
142
 
137
- hash :analytics, optional: [:featured, :disabled]
143
+ hash :analytics, schema: { featured: :any, disabled: :bool }
138
144
  hash :dragData
139
145
 
140
- hash :tooltip, required: [:text], optional: [:placement, :position]
146
+ hash :tooltip, schema: { text!: :string, placement: :string, position: :string }
141
147
  action :onLoad
142
148
  action :onRerender
143
149
 
@@ -238,8 +244,22 @@ module Glib
238
244
  # An `ActionText::RichText` (a `has_rich_text` attribute), `ActionText::Content`, or the
239
245
  # HTML one of them rendered.
240
246
  def richText(rich_text)
241
- json.set! 'html', rich_text.to_s
247
+ json.set! 'html', ::ActionText::Content.with_renderer(html_renderer) { rich_text.to_s }
242
248
  end
249
+
250
+ private
251
+ # Action Text renders through the current controller by default. Here that is a
252
+ # namespaced JSON controller, so a content attachment (e.g. a mention whose record is
253
+ # gone) would be looked up as `glib/action_text/contents/_content.json` and raise.
254
+ # A host-level HTML renderer resolves partials the way an HTML page would.
255
+ def html_renderer
256
+ request = page.context.request
257
+ ::ApplicationController.renderer.new(
258
+ http_host: request.host_with_port,
259
+ https: request.ssl?,
260
+ script_name: request.script_name
261
+ )
262
+ end
243
263
  end
244
264
 
245
265
  class Label < AbstractText
@@ -269,7 +289,7 @@ module Glib
269
289
  string :base64Data
270
290
  action :onClick
271
291
  color :backgroundColor
272
- hash :initials, required: [:text], optional: [:color]
292
+ hash :initials, schema: { text!: :string, color: :string }
273
293
  end
274
294
 
275
295
  class Icon < View
@@ -0,0 +1,172 @@
1
+ require 'redcarpet'
2
+ require 'reverse_markdown'
3
+
4
+ module Glib
5
+ # Server-side Markdown <-> HTML conversion for `fields_actionText`, which only speaks HTML.
6
+ #
7
+ # @example Editing a Markdown column with fields_actionText
8
+ # form.fields_actionText name: 'post[body]', value: Glib::Markdown.to_html(post.body)
9
+ # # On submit:
10
+ # post.update!(body: Glib::Markdown.from_html(params.dig(:post, :body)))
11
+ module Markdown
12
+ EXTENSIONS = {
13
+ fenced_code_blocks: true,
14
+ tables: true,
15
+ strikethrough: true,
16
+ autolink: true,
17
+ no_intra_emphasis: true,
18
+ lax_spacing: true
19
+ }.freeze
20
+
21
+ INLINE_SYNTAX = /[\\`\[\]~]/
22
+
23
+ # Everything from_html can turn into Markdown. Other tags, <script> and <style> included, are
24
+ # dropped together with their text.
25
+ ALLOWED_TAGS = (
26
+ Rails::HTML::Sanitizer.best_supported_vendor.safe_list_sanitizer.allowed_tags.to_a +
27
+ %w[figure figcaption table thead tbody tr th td]
28
+ ).freeze
29
+ # No `title`: ReverseMarkdown writes it into the Markdown without escaping quotes.
30
+ ALLOWED_ATTRIBUTES = %w[href src alt].freeze
31
+
32
+ # ReverseMarkdown always fences code with one backtick or ```, so a backtick in the code ends
33
+ # the fence early and the rest is read as Markdown. These converters pick a fence longer than
34
+ # any backtick run in the code, as CommonMark specifies. They are registered under their own
35
+ # tag names so the host app's ReverseMarkdown keeps its stock `code` and `pre` converters.
36
+ module CodeFence
37
+ def fence_for(code, min_length:)
38
+ longest_run = code.scan(/`+/).map(&:length).max || 0
39
+ '`' * [min_length, longest_run + 1].max
40
+ end
41
+ end
42
+
43
+ class CodeSpanConverter < ReverseMarkdown::Converters::Base
44
+ include CodeFence
45
+
46
+ TAG = 'glib-markdown-code'.freeze
47
+
48
+ def convert(node, state = {})
49
+ code = node.text
50
+ fence = fence_for(code, min_length: 1)
51
+ # Without the padding, a backtick at either end would merge into the fence.
52
+ code = " #{code} " if code.start_with?('`') || code.end_with?('`')
53
+ preserve_literal("#{fence}#{code}#{fence}", state)
54
+ end
55
+ end
56
+
57
+ class CodeBlockConverter < ReverseMarkdown::Converters::Pre
58
+ include CodeFence
59
+
60
+ TAG = 'glib-markdown-pre'.freeze
61
+
62
+ def convert(node, state = {})
63
+ code = treat_children(node, state).strip
64
+ fence = fence_for(code, min_length: 3)
65
+ "\n#{preserve_literal("#{fence}\n#{code}\n#{fence}", state)}\n"
66
+ end
67
+ end
68
+
69
+ ReverseMarkdown::Converters.register CodeSpanConverter::TAG, CodeSpanConverter.new
70
+ ReverseMarkdown::Converters.register CodeBlockConverter::TAG, CodeBlockConverter.new
71
+
72
+ class << self
73
+ # `hard_wrap: true` turns every newline into a <br>, for chat-style input where people
74
+ # don't leave blank lines between paragraphs.
75
+ def to_html(markdown, hard_wrap: false)
76
+ return '' if markdown.blank?
77
+
78
+ # The output is often rendered as-is (an `html` view, a non-Trix field) rather than only
79
+ # through Action Text's sanitizer, so raw HTML and javascript: links are never emitted.
80
+ renderer = Redcarpet::Render::HTML.new(escape_html: true, safe_links_only: true, hard_wrap: hard_wrap)
81
+ # Redcarpet's default <del> for ~~strike~~ is what Trix uses too; Action Text's
82
+ # sanitizer strips <s>.
83
+ Redcarpet::Markdown.new(renderer, EXTENSIONS).render(markdown.to_s)
84
+ end
85
+
86
+ # `input` may be raw Trix HTML (as submitted by fields_actionText), an ActionText::Content
87
+ # or an ActionText::RichText. Attachments become Markdown too: image blobs as images,
88
+ # other blobs as links, and anything else (e.g. mentions) as its plain-text
89
+ # representation, so mention models should define `attachable_plain_text_representation`.
90
+ #
91
+ # `blob_url` turns a blob into the URL written into the Markdown. It defaults to
92
+ # `rails_blob_path`, which needs Active Storage's routes to be drawn.
93
+ def from_html(input, blob_url: nil)
94
+ content = action_text_content(input)
95
+ return '' if content.blank?
96
+
97
+ blob_url ||= ->(blob) { Rails.application.routes.url_helpers.rails_blob_path(blob, only_path: true) }
98
+ html = content.render_attachments { |attachment| attachment_html(attachment, blob_url) }.to_html
99
+ ReverseMarkdown.convert(markdown_ready_fragment(html), unknown_tags: :bypass, github_flavored: true).strip
100
+ end
101
+
102
+ private
103
+ # ReverseMarkdown only escapes `*` and `_`, and writes hrefs, srcs and alts verbatim. Without
104
+ # this, text that reads as Markdown (`[a](javascript:...)`, `# heading`, `1. item`) or a
105
+ # `)` in a URL would turn into different, attacker-chosen Markdown on the next to_html.
106
+ def markdown_ready_fragment(html)
107
+ sanitized = sanitizer.sanitize(html, tags: ALLOWED_TAGS, attributes: ALLOWED_ATTRIBUTES)
108
+ fragment = Nokogiri::HTML::DocumentFragment.parse(sanitized)
109
+
110
+ fragment.xpath('.//text()[not(ancestor::code or ancestor::pre)]').each do |node|
111
+ node.content = escape_text(node.content)
112
+ end
113
+ fragment.css('a[href]').each { |link| link['href'] = escape_url(link['href']) }
114
+ fragment.css('img').each do |image|
115
+ image['src'] = escape_url(image['src']) if image['src']
116
+ image['alt'] = image['alt'].gsub(INLINE_SYNTAX) { |char| "\\#{char}" } if image['alt']
117
+ end
118
+ fragment.xpath('.//code[not(ancestor::pre)]').each { |code| code.name = CodeSpanConverter::TAG }
119
+ fragment.css('pre').each { |pre| pre.name = CodeBlockConverter::TAG }
120
+
121
+ fragment
122
+ end
123
+
124
+ def sanitizer
125
+ @sanitizer ||= Rails::HTML::Sanitizer.best_supported_vendor.safe_list_sanitizer.new(prune: true)
126
+ end
127
+
128
+ # Over-escaping is harmless: Redcarpet renders `\#` mid-line as `#`. So every text node is
129
+ # treated as a possible line start rather than tracking where lines really begin.
130
+ def escape_text(text)
131
+ text
132
+ .gsub(INLINE_SYNTAX) { |char| "\\#{char}" }
133
+ .sub(/\A(\s*)([#>+=-])/) { "#{Regexp.last_match(1)}\\#{Regexp.last_match(2)}" }
134
+ .sub(/\A(\s*\d+)\./) { "#{Regexp.last_match(1)}\\." }
135
+ end
136
+
137
+ def escape_url(url)
138
+ url.gsub(/[\s()<>]/) { |char| ERB::Util.url_encode(char) }
139
+ end
140
+
141
+ def action_text_content(input)
142
+ case input
143
+ when ::ActionText::RichText then input.body || ::ActionText::Content.new('')
144
+ when ::ActionText::Content then input
145
+ else ::ActionText::Content.new(input.to_s)
146
+ end
147
+ end
148
+
149
+ def attachment_html(attachment, blob_url)
150
+ attachable = attachment.attachable
151
+
152
+ case attachable
153
+ when ::ActiveStorage::Blob
154
+ label = attachment.caption || attachable.filename.to_s
155
+ url = blob_url.call(attachable)
156
+ attachable.image? ? helpers.tag.img(src: url, alt: label) : helpers.link_to(label, url)
157
+ when ::ActionText::Attachables::RemoteImage
158
+ helpers.tag.img(src: attachable.url, alt: attachment.caption)
159
+ else
160
+ text = attachment.to_plain_text
161
+ # ContentAttachment returns its HTML fragment rather than a string.
162
+ text = text.text if text.respond_to?(:text)
163
+ ERB::Util.html_escape(text.to_s)
164
+ end
165
+ end
166
+
167
+ def helpers
168
+ ActionController::Base.helpers
169
+ end
170
+ end
171
+ end
172
+ end
@@ -6,7 +6,7 @@ page.body(
6
6
  body.panels_responsive(
7
7
  padding: { all: 16 },
8
8
  childViews: ->(res) do
9
- res.fields_richText value: "<p>#{DateTime.current.to_fs(:rfc822)}</p><p>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</p>"
9
+ res.fields_actionText value: "<div>#{DateTime.current.to_fs(:rfc822)}</div><div>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.</div>"
10
10
  res.spacer height: 8
11
11
  res.button(
12
12
  text: 'close',
@@ -0,0 +1,12 @@
1
+ markdown = glib_html_to_markdown(html)
2
+
3
+ view.panels_vertical id: 'action_text_conversion', width: 'matchParent', childViews: ->(panel) do
4
+ panel.h3 text: 'Output HTML (what the field submits)'
5
+ panel.markdown text: "```html\n#{html.strip}\n```"
6
+ panel.spacer height: 8
7
+ panel.h3 text: 'Output Markdown (converted on the server)'
8
+ panel.markdown text: "```markdown\n#{markdown}\n```"
9
+ panel.spacer height: 8
10
+ panel.h3 text: 'Markdown rendered'
11
+ panel.markdown text: markdown
12
+ end
@@ -20,6 +20,29 @@ page.form url: json_ui_garage_url(path: 'forms/action_text_preview'), method: 'p
20
20
  directUploadUrl: glib_direct_uploads_url,
21
21
  blobUrlGenerator: glib_blob_url_generators_url,
22
22
  accepts: { fileType: ['image', 'pdf'], maxFileSize: 5000 }
23
+
24
+ column.spacer height: 16
25
+ column.fields_actionText \
26
+ width: 'matchParent',
27
+ label: 'Comment (type @ to mention someone)',
28
+ name: 'post[comment]',
29
+ mentionList: User.all.map { |user| { sgid: user.attachable_sgid, value: user.full_name } }
30
+
31
+ column.spacer height: 16
32
+ column.fields_actionText \
33
+ width: 'matchParent',
34
+ label: 'Reply (mentions searched on the server)',
35
+ name: 'post[reply]',
36
+ mentionUrl: json_ui_garage_url(path: 'forms/action_text_mentions', format: 'json')
37
+
38
+ column.spacer height: 16
39
+ column.fields_actionText \
40
+ width: 'matchParent',
41
+ label: 'Chat-style: no toolbar',
42
+ name: 'post[chat]',
43
+ placeholder: 'Write a message',
44
+ hideToolbar: true,
45
+ mentionUrl: json_ui_garage_url(path: 'forms/action_text_mentions', format: 'json')
23
46
  end
24
47
 
25
48
  form.panels_column lg: { cols: 6 }, padding: { left: 10, right: 10 }, childViews: ->(column) do
@@ -0,0 +1,5 @@
1
+ json_ui_response json do |action|
2
+ action.components_replace targetId: 'action_text_conversion', newView: ->(view) do
3
+ render "#{@path_prefix}/forms/action_text_conversion", view: view, html: params.dig(:post, :body).to_s
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ term = User.sanitize_sql_like(params[:term].to_s)
2
+ users = User.where(User.arel_table[:full_name].matches("%#{term}%")).order(:full_name).limit(10)
3
+
4
+ json.items users.map { |user| { sgid: user.attachable_sgid, value: user.full_name } }
@@ -34,17 +34,17 @@ page.scroll childViews: ->(scroll) do
34
34
  end
35
35
  end
36
36
 
37
- form.fields_richText \
37
+ form.fields_actionText \
38
38
  name: 'user[description]',
39
- value: %(
40
- This note serves as a reminder regarding the checklist assigned to you. This checklist is crucial for ensuring the safety and well-being of all staff.
41
-
42
- Please review the checklist carefully and ensure that all necessary steps are taken to implement the required safety measures.
43
-
44
- Your attention to detail and proactive approach to safety are greatly appreciated. If you have any questions or require assistance, please don't hesitate to reach out.
45
-
46
- Thank you for your cooperation.
47
- )
39
+ value: <<~HTML
40
+ <div>This note serves as a reminder regarding the checklist assigned to you. This checklist is crucial for ensuring the safety and well-being of all staff.</div>
41
+ <div><br></div>
42
+ <div>Please review the checklist carefully and ensure that all necessary steps are taken to implement the required safety measures.</div>
43
+ <div><br></div>
44
+ <div>Your attention to detail and proactive approach to safety are greatly appreciated. If you have any questions or require assistance, please don't hesitate to reach out.</div>
45
+ <div><br></div>
46
+ <div>Thank you for your cooperation.</div>
47
+ HTML
48
48
 
49
49
  form.spacer height: 20
50
50
  form.button text: 'Submit', onClick: ->(action) { action.forms_submit }
@@ -55,7 +55,7 @@ page.form \
55
55
  form.fields_check name: 'user[check][]', checkValue: 'choice2', label: 'choice3', value: 'choice2'
56
56
 
57
57
  form.h3 text: 'Rich text'
58
- form.fields_richText name: 'user[richtext]', value: 'Lorem ipsum dumet...'
58
+ form.fields_actionText name: 'user[richtext]', value: '<div>Lorem ipsum dumet...</div>'
59
59
 
60
60
  form.spacer height: 24
61
61
  form.panels_split width: 'matchParent', content: ->(split) do
@@ -35,7 +35,7 @@ page.form url: json_ui_garage_url(path: 'forms/generic_post'), method: 'post', p
35
35
  template.spacer height: 10
36
36
  template.fields_hidden name: 'message[error]'
37
37
  template.fields_text width: 'matchParent', name: 'question', label: 'Question', placeholder: 'Question'
38
- template.fields_richText width: 'matchParent', name: 'description', label: 'Desc', placeholder: 'Desc'
38
+ template.fields_actionText width: 'matchParent', name: 'description', label: 'Desc', placeholder: 'Desc'
39
39
 
40
40
  template.panels_responsive id: 'responsive_{{entryIndex}}', childViews: ->(column) do
41
41
  column.panels_split width: 'matchParent', content: ->(split) do
@@ -47,7 +47,7 @@ page.form url: json_ui_garage_url(path: 'forms/basic_post'), method: 'post', pad
47
47
  label: 'Content',
48
48
  name: 'user[message]',
49
49
  # value: "<p>Test <img src='{{image1}}'</p>",
50
- # value: glib_format_markdown(initial_message),
50
+ # value: glib_markdown_to_html(initial_message),
51
51
  value: initial_message,
52
52
  mentionList: mention_list,
53
53
  imageUploader: {
@@ -437,7 +437,7 @@ page.form \
437
437
  id: 'panel2',
438
438
  width: 'matchParent',
439
439
  childViews: ->(res) do
440
- res.fields_richText name: 'user[loadIf_target4]', width: 'matchParent', value: 'Value 3'
440
+ res.fields_actionText name: 'user[loadIf_target4]', width: 'matchParent', value: '<div>Value 3</div>'
441
441
  res.spacer height: 4
442
442
  res.fields_radioGroup name: 'user[loadIf_target5]', width: 'matchParent', value: 'choice_1', childViews: ->(group) do
443
443
  group.fields_radio label: 'Choice 1', value: 'choice_1'
@@ -2,7 +2,6 @@ json.title 'Test Page (Charts)'
2
2
 
3
3
  default_plugins = {
4
4
  datalabels: {
5
- backgroundColor: 'skyblue',
6
5
  borderRadius: 4,
7
6
  color: 'white',
8
7
  font: {
@@ -12,6 +11,9 @@ default_plugins = {
12
11
  }
13
12
  }
14
13
 
14
+ custom_plugins = default_plugins.deep_dup
15
+ custom_plugins[:datalabels][:backgroundColor] = ['#1E5006', '#E36414']
16
+
15
17
  line_series_revenue = [
16
18
  -> do
17
19
  json.title 'Revenue'
@@ -158,7 +160,7 @@ page.body childViews: ->(body) do
158
160
  res.spacer height: 8
159
161
  res.charts_line(
160
162
  dataSeries: line_series_revenue,
161
- plugins: default_plugins,
163
+ plugins: custom_plugins,
162
164
  colors: ['#79AC78', '#3085C3'],
163
165
  legend: { display: false },
164
166
  formatYAxis: true
@@ -4,6 +4,17 @@ page = json_ui_page json
4
4
 
5
5
  render 'json_ui/garage/test_page/header', json: json, page: page
6
6
 
7
+ # User includes ActionText::Attachable, so `has_rich_text` resolves each submitted sgid back to
8
+ # its User. Users have no avatar column; a placeholder seeded by id stands in for one.
9
+ user_mentions = User.all.map do |user|
10
+ {
11
+ sgid: user.attachable_sgid,
12
+ value: user.full_name,
13
+ group: user.admin? ? 'Admins' : 'Members',
14
+ avatar: "https://picsum.photos/seed/user-#{user.id}/80/80"
15
+ }
16
+ end
17
+
7
18
  page.body(
8
19
  childViews: ->(body) do
9
20
  body.panels_responsive(
@@ -67,7 +78,34 @@ page.body(
67
78
  label: 'Locked',
68
79
  name: 'post[locked]',
69
80
  value: '<div>Cannot be edited.</div>',
70
- readOnly: true
81
+ readOnly: true,
82
+ mentionList: user_mentions
83
+ )
84
+
85
+ form.spacer height: 12
86
+ form.h2 text: 'Mentions'
87
+ form.spacer height: 8
88
+ form.fields_actionText(
89
+ id: 'action_text_mentions',
90
+ width: 'matchParent',
91
+ label: 'Comment',
92
+ name: 'post[comment]',
93
+ mentionList: user_mentions + [
94
+ # Not a record: checks that a name with markup is inserted as text.
95
+ { sgid: 'garage-markup', value: '<b>Grace</b>', text: 'Grace Hopper', group: 'Members' },
96
+ { value: 'everyone', text: 'Everyone', group: 'Members' }
97
+ ]
98
+ )
99
+
100
+ form.spacer height: 12
101
+ form.h2 text: 'Mentions from a search endpoint'
102
+ form.spacer height: 8
103
+ form.fields_actionText(
104
+ id: 'action_text_mention_search',
105
+ width: 'matchParent',
106
+ label: 'Reply',
107
+ name: 'post[reply]',
108
+ mentionUrl: json_ui_garage_url(path: 'forms/action_text_mentions', format: 'json')
71
109
  )
72
110
 
73
111
  form.spacer height: 12
@@ -81,6 +119,71 @@ page.body(
81
119
  res.panels_vertical id: 'preview', childViews: ->(vertical) do
82
120
  vertical.actionText richText: ActionText::Content.new('<div>Initial <strong>content</strong>.</div>')
83
121
  end
122
+
123
+ res.spacer height: 12
124
+ res.hr width: 'matchParent'
125
+ res.spacer height: 12
126
+
127
+ stored_markdown = <<~MARKDOWN
128
+ # Release notes
129
+ This is a **message** with *emphasis* and a [link](https://example.com).
130
+
131
+ - Bullet one
132
+ - Bullet two
133
+
134
+ > Quoted text
135
+ MARKDOWN
136
+
137
+ res.h2 text: 'Markdown and HTML output'
138
+ res.spacer height: 8
139
+ res.p text: "Replaces fields_richText's produce/accept. The field only speaks HTML, so the server converts: " \
140
+ 'Glib::Markdown.to_html turns stored Markdown into the value, and Glib::Markdown.from_html ' \
141
+ 'turns the submitted HTML (mentions and attachments included) back into Markdown.'
142
+ res.spacer height: 8
143
+ res.h3 text: 'Stored Markdown (input)'
144
+ res.markdown text: "```markdown\n#{stored_markdown.strip}\n```"
145
+ res.spacer height: 8
146
+ res.panels_form(
147
+ width: 'matchParent',
148
+ url: json_ui_garage_url(path: 'forms/action_text_conversion'),
149
+ method: 'post',
150
+ childViews: ->(form) do
151
+ form.fields_actionText(
152
+ id: 'action_text_markdown',
153
+ width: 'matchParent',
154
+ label: 'Value converted from Markdown on the server',
155
+ name: 'post[body]',
156
+ value: glib_markdown_to_html(stored_markdown)
157
+ )
158
+ form.spacer height: 8
159
+ form.fields_submit text: 'Convert output'
160
+ end
161
+ )
162
+ res.spacer height: 8
163
+ res.panels_vertical id: 'action_text_conversion', width: 'matchParent', childViews: ->(panel) do
164
+ panel.label text: 'Submit to see the HTML the field produces and its Markdown conversion.'
165
+ end
166
+
167
+ res.spacer height: 12
168
+ res.h2 text: 'Chat input'
169
+ res.spacer height: 8
170
+ res.label text: 'No toolbar, mentions, Enter sends and Shift+Enter adds a line.'
171
+ res.spacer height: 8
172
+ res.panels_form(
173
+ url: json_ui_garage_url(path: 'forms/generic_post'),
174
+ method: 'post',
175
+ childViews: ->(form) do
176
+ form.fields_actionText(
177
+ id: 'action_text_chat',
178
+ width: 'matchParent',
179
+ name: 'user[message]',
180
+ placeholder: 'Write a message',
181
+ hideToolbar: true,
182
+ submitOnEnter: true,
183
+ mentionList: user_mentions
184
+ )
185
+ end
186
+ )
84
187
  end
85
188
  )
86
189
  end