glib-web 4.35.2 → 4.36.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f641f7071417ce8d17c9485a2a1484faf3896768668d2e8213fe1683a1aa90fb
4
- data.tar.gz: e55f947ea933f5b318411fb0d22e349799f26fac9b5945689aa965151994df03
3
+ metadata.gz: 94b3768dec74f3a05c32ffd19612d151afce3829643e070f173899d02627e72f
4
+ data.tar.gz: e7f8124643269e1634a979683210b93a7ca613fd1cf975a0ff20419a3f08f9f2
5
5
  SHA512:
6
- metadata.gz: 0d5edeb473e656e26a481849654819dec6c0050ad8bc362a2d18567b8cb6ecf455ca8c7db4ca63a8f42f3be3ec982f2ec78c2f4c10cf786a38978bca2752b819
7
- data.tar.gz: a33efa4e3074fa2c56cc259ce5ab1255772138d9535d39b1abdbfc092a1121fbc29b2c6463729a0d8015119a3a952d53f33f4392ddacfc1c934b2f5c05b036fc
6
+ metadata.gz: 91cf7697395548ce7d8ee306269688c1166ed9e9d1ca0778a5d2d2dfd72d26dab277a3d22069a1d4ef31727511816854bd12de8ef984629069b4413f295095c5
7
+ data.tar.gz: 4b655db49df2bfba84b0c524d02e41fdaadcacfb687418f7d3651c24712c9c7a55ed1b5bf4a1951b3107264a5db09b348b892293efaee7212c06d05b9b36408e
@@ -14,7 +14,7 @@ module Glib::Json::Ui
14
14
  end
15
15
 
16
16
  # Override
17
- def form_authenticity_token(*args)
17
+ def form_authenticity_token(**args)
18
18
  Rails.env.test? ? 'test_token' : super
19
19
  end
20
20
 
@@ -7,7 +7,7 @@ module Glib
7
7
  button: I18n.t('glib.accepts.max_file_size_error.button', default: nil) || 'Dismiss'
8
8
  }
9
9
  default_max_length_error = {
10
- body: I18n.t('glib.accepts.max_file_length_error.body', default: nil) || 'Files exceed the maximum limit per upload',
10
+ body: I18n.t('glib.accepts.max_file_length_error.body', default: nil) || 'Files exceed the maximum limit',
11
11
  button: I18n.t('glib.accepts.max_file_length_error.button', default: nil) || 'Dismiss'
12
12
  }
13
13
 
@@ -0,0 +1,22 @@
1
+ class MutuallyExclusiveWithValidator < ActiveModel::EachValidator
2
+ include ActiveSupport::Inflector
3
+
4
+ def validate_each(record, attribute, _value)
5
+ other_attribute = options[:with]
6
+
7
+ validate_mutual_exclusivity(record, attribute, other_attribute)
8
+ validate_mutual_exclusivity(record, other_attribute, attribute)
9
+ end
10
+
11
+ private
12
+ def validate_mutual_exclusivity(record, attribute, other_attribute)
13
+ attribute_value = record.send(attribute)
14
+ other_attribute_value = record.send(other_attribute)
15
+
16
+ if attribute_value.present? && other_attribute_value.present?
17
+ record.errors.add(attribute, :present, **options)
18
+ elsif attribute_value.nil? && other_attribute_value.nil?
19
+ record.errors.add(attribute, :blank, **options)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,22 @@
1
+ class PresenceOnlyIfValidator < ActiveModel::EachValidator
2
+ include ActiveSupport::Inflector
3
+
4
+ def validate_each(record, attribute, _value)
5
+ condition = options[:with]
6
+
7
+ if condition.is_a?(Symbol)
8
+ evaluate_condition(record, attribute, ->(record) { record.send(condition) })
9
+ elsif condition.respond_to?(:call)
10
+ evaluate_condition(record, attribute, condition)
11
+ else
12
+ raise 'Invalid option'
13
+ end
14
+ end
15
+
16
+ private
17
+ def evaluate_condition(record, attribute, condition)
18
+ if condition.call(record) && record.send(attribute).nil?
19
+ record.errors.add(attribute, :blank, **options)
20
+ end
21
+ end
22
+ end
@@ -46,7 +46,15 @@ page.form options.merge(childViews: ->(form) do
46
46
  name: 'user[multi][]',
47
47
  id: 'upload_1',
48
48
  width: 360,
49
- accepts: { fileType: 'image', maxFileSize: 10 },
49
+ accepts: {
50
+ fileType: 'image',
51
+ maxFileSize: 10,
52
+ maxFileLength: 2,
53
+ maxFileLengthErrorText: {
54
+ body: 'try with a smaller number of files',
55
+ button: 'OK'
56
+ }
57
+ },
50
58
  directUploadUrl: glib_direct_uploads_url,
51
59
  uploadTitle: 'Files uploaded:',
52
60
  storagePrefix: 'glib',
@@ -70,7 +78,10 @@ page.form options.merge(childViews: ->(form) do
70
78
  name: 'user[multi2][]',
71
79
  id: 'upload_2',
72
80
  width: 360,
73
- accepts: { fileType: 'image', maxFileSize: 5000 },
81
+ accepts: {
82
+ fileType: 'image',
83
+ maxFileSize: 5000
84
+ },
74
85
  directUploadUrl: glib_direct_uploads_url,
75
86
  uploadTitle: 'Files uploaded:',
76
87
  onFinishUpload: ->(action) { action.forms_submit }
@@ -89,7 +100,7 @@ page.form options.merge(childViews: ->(form) do
89
100
  form.fields_multiUpload \
90
101
  name: 'user[multi3][]',
91
102
  width: 360,
92
- accepts: { fileType: 'image', maxFileSize: 100 },
103
+ accepts: { fileType: 'image', maxFileSize: 100, maxFileLength: 2 },
93
104
  uploadTitle: 'Files uploaded:',
94
105
  onFinishUpload: ->(action) { action.forms_submit }
95
106
 
@@ -73,17 +73,27 @@ page.body childViews: ->(body) do
73
73
 
74
74
  validation = { required: { message: 'Required' } }
75
75
  options = ['option1', 'option2', 'option3', 'option4'].map { |option| { 'text'=> option.humanize, 'value' => option } }
76
+ options_with_icon = options.map.with_index do |option, index|
77
+ obj = option.dup
78
+ obj['icon'] = { name: "filter_#{index + 1}" }
79
+ obj
80
+ end
81
+ options_with_image = options.map.with_index do |option, index|
82
+ obj = option.dup
83
+ obj['imageUrl'] = 'https://flagsapi.com/ID/flat/24.png'
84
+ obj
85
+ end
76
86
 
77
87
  form.fields_date width: 'matchParent', name: 'user[date]', id: 'date', value: Date.new(2024, 7, 24), validation: validation
78
88
  form.hr width: 'matchParent'
79
89
  form.fields_select clearable: true, multiple: true, width: 'matchParent', name: 'user[select][]', id: 'select', options: options, value: ['option1', 'option2'], validation: validation
80
90
  form.hr width: 'matchParent'
81
91
  form.panels_flow innerPadding: { bottom: 0 }, width: 'matchParent', id: 'select1', childViews: ->(flow) do
82
- form.fields_select clearable: true, width: 'matchParent', name: 'user[select1]', options: options, value: 'option1'
92
+ form.fields_select clearable: true, width: 'matchParent', name: 'user[select1]', options: options_with_icon, value: 'option1'
83
93
  form.hr width: 'matchParent'
84
94
  end
85
95
  form.panels_horizontal id: 'select2', width: 'matchParent', childViews: ->(hori) do
86
- form.fields_select clearable: true, width: 'matchParent', name: 'user[select2]', options: options, value: 'option2'
96
+ form.fields_select clearable: true, width: 'matchParent', name: 'user[select2]', options: options_with_image, value: 'option2'
87
97
  form.hr width: 'matchParent'
88
98
  end
89
99
  form.panels_split id: 'select3', width: 'matchParent', content: ->(split) do
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: 4.35.2
4
+ version: 4.36.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ''
@@ -217,6 +217,8 @@ files:
217
217
  - app/policies/glib/application_policy.rb
218
218
  - app/validators/email_typo_validator.rb
219
219
  - app/validators/email_validator.rb
220
+ - app/validators/mutually_exclusive_with_validator.rb
221
+ - app/validators/presence_only_if_validator.rb
220
222
  - app/validators/url_validator.rb
221
223
  - app/views/json_ui/garage/_nav_menu.json.jbuilder
222
224
  - app/views/json_ui/garage/actions/_commands.json.jbuilder