activeadmin_dynamic_fields 0.5.2 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 64bede8d2c37bae18d72078be390d20e182035f02496f797a30acf02bf025329
4
- data.tar.gz: 5629d5a20bc6e9f36f1873127971d01cbaf979159fac4e81c62b7e60f4eb5c7c
3
+ metadata.gz: c205fcaf09eb8f64858be70e3edad674abbf894ee2f65c2c236258bb8f43af86
4
+ data.tar.gz: 488ce2f3f4ed09165839398014614b198e23d830df8c2fcbb63b4dd1547eba0d
5
5
  SHA512:
6
- metadata.gz: f9e4f26043ed9970de78044eda0ab671b005b92b612efcc6912604cefb46078dcac839f75f004982e501bd079167caf58ecf35be7a68cbdf2968a7e98fd9907a
7
- data.tar.gz: 62888b36a03b0945c7fb7e9defae7ea429570158c6cc70b2e171ccf5de65bd85301838ff88c864ba5faad1cfc5f6e1d32e00541f18a8ee3f77d369151fb75198
6
+ metadata.gz: 371d705fc20dc6e2062b54bd81a480979c70e8473727579da8282a06581f7826c80a50f71a3202e695f01b5cd272e3d3e564f626304db35d8ad4e9aa19af8a45
7
+ data.tar.gz: 48d1c6a52aa51b417eb1f55cc61fad9287d263c922b224f08b40492517edf9b0af35af5b49089eaa330f347d1466cf5d90700d77bfb482369942c29705a3af33
data/README.md CHANGED
@@ -1,8 +1,10 @@
1
- # ActiveAdmin Dynamic Fields [![Gem Version](https://badge.fury.io/rb/activeadmin_dynamic_fields.svg)](https://badge.fury.io/rb/activeadmin_dynamic_fields) [![CircleCI](https://circleci.com/gh/blocknotes/activeadmin_dynamic_fields.svg?style=svg)](https://circleci.com/gh/blocknotes/activeadmin_dynamic_fields)
1
+ # ActiveAdmin Dynamic Fields
2
+ [![gem version](https://badge.fury.io/rb/activeadmin_dynamic_fields.svg)](https://badge.fury.io/rb/activeadmin_dynamic_fields) [![gem downloads](https://badgen.net/rubygems/dt/activeadmin_dynamic_fields)](https://rubygems.org/gems/activeadmin_dynamic_fields) [![linters](https://github.com/blocknotes/activeadmin_dynamic_fields/actions/workflows/linters.yml/badge.svg)](https://github.com/blocknotes/activeadmin_dynamic_fields/actions/workflows/linters.yml) [![specs](https://github.com/blocknotes/activeadmin_dynamic_fields/actions/workflows/specs.yml/badge.svg)](https://github.com/blocknotes/activeadmin_dynamic_fields/actions/workflows/specs.yml)
2
3
 
3
4
  An Active Admin plugin to add dynamic behaviors to some fields.
4
5
 
5
6
  Features:
7
+
6
8
  - set conditional checks on fields
7
9
  - trigger actions on target elements
8
10
  - inline field editing
@@ -10,32 +12,53 @@ Features:
10
12
 
11
13
  The easiest way to show how this plugin works is looking the examples [below](#examples).
12
14
 
15
+ Please :star: if you like it.
16
+
13
17
  ## Install
14
- - Add to your Gemfile: `gem 'activeadmin_dynamic_fields'`
15
- - Execute bundle
16
- - Add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
18
+
19
+ First, add the gem to your ActiveAdmin project: `gem 'activeadmin_dynamic_fields'` (and execute `bundle`)
20
+
21
+ If you installed Active Admin **without Webpacker** support:
22
+ - add at the end of your ActiveAdmin javascripts (_app/assets/javascripts/active_admin.js_):
17
23
 
18
24
  ```js
19
25
  //= require activeadmin/dynamic_fields
20
26
  ```
21
27
 
28
+ Otherwise **with Webpacker**:
29
+
30
+ - Execute in your project root:
31
+
32
+ ```sh
33
+ yarn add blocknotes/activeadmin_dynamic_fields
34
+ ```
35
+
36
+ - Add to your *app/javascript/packs/active_admin.js*:
37
+
38
+ ```js
39
+ require('activeadmin_dynamic_fields')
40
+ ```
41
+
22
42
  ## Options
43
+
23
44
  Options are passed to fields using *input_html* parameter as *data* attributes.
24
45
 
25
46
  Conditions:
47
+
26
48
  - **data-if**: check a condition, values:
27
49
  + **checked**: check if a checkbox is checked (ex. `"data-if": "checked"`)
28
- + **not_checked**: check if a checkbox is not checked
50
+ + **not_checked**: check if a checkbox is not checked (equivalent to `"data-if": "!checked"`)
29
51
  + **blank**: check if a field is blank
30
52
  + **not_blank**: check if a field is not blank
31
53
  + **changed**: check if the value of an input is changed (dirty)
32
- - **data-eq**: check if a field has a specific value (ex. `"data-eq": "42"`)
33
- - **data-not**: check if a field has not a specific value
54
+ - **data-eq**: check if a field has a specific value (ex. `"data-eq": "42"` or `"data-eq": "!5"`)
55
+ - **data-not**: check if a field has not a specific value (equivalent to `"data-eq": "!something"`)
34
56
  - **data-match**: check if a field match a regexp
35
57
  - **data-mismatch**: check if a field doesn't match a regexp (ex. `"data-mismatch": "^\d+$"`)
36
58
  - **data-function**: check the return value of a custom function (ex. `"data-function": "my_check"`)
37
59
 
38
60
  Actions:
61
+
39
62
  - **data-then**: action to trigger (alias **data-action**), values:
40
63
  + **hide**: hides elements (ex. `"data-then": "hide", "data-target": ".errors"`)
41
64
  + **slide**: hides elements (using sliding)
@@ -49,6 +72,7 @@ Actions:
49
72
  - **data-args**: arguments passed to the callback function
50
73
 
51
74
  Targets:
75
+
52
76
  - **data-target**: target css selector (from parent fieldset, look for the closest match)
53
77
  - **data-gtarget**: target css selector globally
54
78
 
@@ -57,6 +81,7 @@ A check condition or a custom check function are required. A trigger action is r
57
81
  ## Examples
58
82
 
59
83
  ### Dynamic fields examples
84
+
60
85
  - A checkbox that hides other fields if is checked (ex. model *Article*):
61
86
 
62
87
  ```rb
@@ -128,6 +153,7 @@ function on_change_category(el) {
128
153
  ```
129
154
 
130
155
  ### Inline editing examples
156
+
131
157
  - Prepare a custom member action to save data, an *update* helper function is available (third parameter is optional, allow to filter using strong parameters):
132
158
 
133
159
  ```rb
@@ -165,6 +191,7 @@ end
165
191
  ```
166
192
 
167
193
  ### Dialog example
194
+
168
195
  Example with 2 models: *Author* and *Article*
169
196
 
170
197
  Prepare the content dialog - in Active Admin Author config:
@@ -208,13 +235,16 @@ end
208
235
  The link url is loaded via AJAX before opening the dialog.
209
236
 
210
237
  ## Do you like it? Star it!
238
+
211
239
  If you use this component just star it. A developer is more motivated to improve a project when there is some interest. My other [Active Admin components](https://github.com/blocknotes?utf8=✓&tab=repositories&q=activeadmin&type=source).
212
240
 
213
241
  Or consider offering me a coffee, it's a small thing but it is greatly appreciated: [about me](https://www.blocknot.es/about-me).
214
242
 
215
243
  ## Contributors
244
+
216
245
  - [Mattia Roccoberton](http://blocknot.es): author
217
246
  - The good guys that opened issues and pull requests from time to time
218
247
 
219
248
  ## License
249
+
220
250
  The gem is available as open-source under the terms of the [MIT](LICENSE.txt).
@@ -39,8 +39,8 @@
39
39
  match: (el, regexp) => regexp.test(el.val()),
40
40
  mismatch: (el, regexp) => !regexp.test(el.val()),
41
41
  not: (el, value) => el.val() != value,
42
- not_blank: el => el.val().trim(),
43
- not_checked: el => !el.is(':checked')
42
+ not_blank: el => !CONDITIONS.blank(el),
43
+ not_checked: el => !CONDITIONS.checked(el)
44
44
  }
45
45
 
46
46
  const REVERSE_ACTIONS = {
@@ -53,6 +53,8 @@
53
53
  slide: el => el.slideDown()
54
54
  }
55
55
 
56
+ const REGEXP_NOT = /^!\s*/
57
+
56
58
  class Field {
57
59
  constructor(el) {
58
60
  this.el = el
@@ -91,20 +93,29 @@
91
93
  }
92
94
 
93
95
  evaluateCondition() {
94
- let value = CONDITIONS[this.el.data('if')?.trim()]
95
- if (value) return { condition: value }
96
-
97
- value = this.el.data('eq')
98
- if (value) return { condition: CONDITIONS['eq'], condition_arg: value }
99
-
100
- value = this.el.data('not')
101
- if (value) return { condition: CONDITIONS['not'], condition_arg: value }
102
-
103
- value = this.el.data('match')
104
- if (value) return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
105
-
106
- value = this.el.data('mismatch')
107
- if (value) return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
96
+ let value
97
+ if (value = this.el.data('if')) {
98
+ if (REGEXP_NOT.test(value)) value = 'not_' + value.replace(REGEXP_NOT, '')
99
+ return { condition: CONDITIONS[value] }
100
+ }
101
+ if (value = this.el.data('eq')) {
102
+ if (REGEXP_NOT.test(value)) {
103
+ return { condition: CONDITIONS['not'], condition_arg: value.replace(REGEXP_NOT, '') }
104
+ }
105
+ return { condition: CONDITIONS['eq'], condition_arg: value }
106
+ }
107
+ if (value = this.el.data('not')) {
108
+ if (REGEXP_NOT.test(value)) {
109
+ return { condition: CONDITIONS['eq'], condition_arg: value.replace(REGEXP_NOT, '') }
110
+ }
111
+ return { condition: CONDITIONS['not'], condition_arg: value }
112
+ }
113
+ if (value = this.el.data('match')) {
114
+ return { condition: CONDITIONS['match'], condition_arg: new RegExp(value) }
115
+ }
116
+ if (value = this.el.data('mismatch')) {
117
+ return { condition: CONDITIONS['mismatch'], condition_arg: new RegExp(value) }
118
+ }
108
119
 
109
120
  this.custom_function = this.el.data('function')
110
121
  if (this.custom_function) {
@@ -2,6 +2,6 @@
2
2
 
3
3
  module ActiveAdmin
4
4
  module DynamicFields
5
- VERSION = '0.5.2'
5
+ VERSION = '0.7.0'
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activeadmin_dynamic_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mattia Roccoberton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-14 00:00:00.000000000 Z
11
+ date: 2022-03-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activeadmin
@@ -25,105 +25,7 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: activestorage
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - "~>"
32
- - !ruby/object:Gem::Version
33
- version: '6.0'
34
- type: :development
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - "~>"
39
- - !ruby/object:Gem::Version
40
- version: '6.0'
41
- - !ruby/object:Gem::Dependency
42
- name: capybara
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - "~>"
46
- - !ruby/object:Gem::Version
47
- version: '3.33'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - "~>"
53
- - !ruby/object:Gem::Version
54
- version: '3.33'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: '0.13'
62
- type: :development
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: '0.13'
69
- - !ruby/object:Gem::Dependency
70
- name: puma
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '4.3'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '4.3'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec_junit_formatter
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '0.4'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '0.4'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec-rails
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '4.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '4.0'
111
- - !ruby/object:Gem::Dependency
112
- name: rubocop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - "~>"
116
- - !ruby/object:Gem::Version
117
- version: '0.90'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - "~>"
123
- - !ruby/object:Gem::Version
124
- version: '0.90'
125
- - !ruby/object:Gem::Dependency
126
- name: sassc
28
+ name: appraisal
127
29
  requirement: !ruby/object:Gem::Requirement
128
30
  requirements:
129
31
  - - "~>"
@@ -136,48 +38,6 @@ dependencies:
136
38
  - - "~>"
137
39
  - !ruby/object:Gem::Version
138
40
  version: '2.4'
139
- - !ruby/object:Gem::Dependency
140
- name: selenium-webdriver
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - "~>"
144
- - !ruby/object:Gem::Version
145
- version: '3.142'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - "~>"
151
- - !ruby/object:Gem::Version
152
- version: '3.142'
153
- - !ruby/object:Gem::Dependency
154
- name: sprockets-rails
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - "~>"
158
- - !ruby/object:Gem::Version
159
- version: '3.2'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - "~>"
165
- - !ruby/object:Gem::Version
166
- version: '3.2'
167
- - !ruby/object:Gem::Dependency
168
- name: sqlite3
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - "~>"
172
- - !ruby/object:Gem::Version
173
- version: '1.4'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - "~>"
179
- - !ruby/object:Gem::Version
180
- version: '1.4'
181
41
  description: An Active Admin plugin to add dynamic behaviors to fields
182
42
  email: mat@blocknot.es
183
43
  executables: []
@@ -195,7 +55,10 @@ files:
195
55
  homepage: https://github.com/blocknotes/activeadmin_dynamic_fields
196
56
  licenses:
197
57
  - MIT
198
- metadata: {}
58
+ metadata:
59
+ homepage_uri: https://github.com/blocknotes/activeadmin_dynamic_fields
60
+ source_code_uri: https://github.com/blocknotes/activeadmin_dynamic_fields
61
+ rubygems_mfa_required: 'true'
199
62
  post_install_message:
200
63
  rdoc_options: []
201
64
  require_paths:
@@ -211,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
74
  - !ruby/object:Gem::Version
212
75
  version: '0'
213
76
  requirements: []
214
- rubygems_version: 3.1.4
77
+ rubygems_version: 3.1.6
215
78
  signing_key:
216
79
  specification_version: 4
217
80
  summary: Dynamic fields for ActiveAdmin