headmin 0.6.0 → 0.6.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 (51) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +6 -0
  3. data/Gemfile.lock +92 -90
  4. data/README.md +2 -2
  5. data/app/assets/javascripts/headmin/controllers/filter_controller.js +15 -3
  6. data/app/assets/javascripts/headmin/controllers/filter_row_controller.js +75 -47
  7. data/app/assets/javascripts/headmin/controllers/infinite_scroller_controller.js +30 -0
  8. data/app/assets/javascripts/headmin/controllers/media_controller.js +24 -8
  9. data/app/assets/javascripts/headmin/controllers/media_modal_controller.js +142 -105
  10. data/app/assets/javascripts/headmin/index.js +2 -0
  11. data/app/assets/javascripts/headmin.js +122 -19
  12. data/app/assets/stylesheets/headmin.css +1 -1
  13. data/app/controllers/headmin/media_controller.rb +11 -0
  14. data/app/helpers/headmin/form_helper.rb +0 -11
  15. data/app/models/concerns/headmin/attachment.rb +34 -0
  16. data/app/models/headmin/filter/association.rb +0 -12
  17. data/app/models/headmin/filter/association_count.rb +50 -0
  18. data/app/models/headmin/filter/association_count_view.rb +78 -0
  19. data/app/models/headmin/filter/base.rb +10 -0
  20. data/app/models/headmin/filter/date.rb +8 -1
  21. data/app/models/headmin/filter/date_view.rb +1 -1
  22. data/app/models/headmin/filter/number.rb +0 -12
  23. data/app/models/headmin/filter/operator_view.rb +3 -1
  24. data/app/models/headmin/form/media_view.rb +6 -2
  25. data/app/views/headmin/_filters.html.erb +3 -8
  26. data/app/views/headmin/_form.html.erb +1 -1
  27. data/app/views/headmin/_index.html.erb +1 -1
  28. data/app/views/headmin/filters/_association_count.html.erb +28 -0
  29. data/app/views/headmin/filters/_date.html.erb +1 -0
  30. data/app/views/headmin/forms/fields/_base.html.erb +1 -1
  31. data/app/views/headmin/layout/_content.html.erb +1 -1
  32. data/app/views/headmin/media/_media_item_modal.html.erb +26 -0
  33. data/app/views/headmin/media/_modal.html.erb +8 -3
  34. data/app/views/headmin/media/_thumbnail.html.erb +20 -0
  35. data/app/views/headmin/media/create.turbo_stream.erb +1 -1
  36. data/app/views/headmin/media/index.turbo_stream.erb +11 -0
  37. data/app/views/headmin/media/thumbnail.html.erb +3 -0
  38. data/app/views/headmin/nav/_item.html.erb +6 -1
  39. data/app/views/headmin/pagination/_infinite.html.erb +7 -0
  40. data/config/initializers/extend_active_storage_attachment.rb +3 -0
  41. data/config/locales/headmin/filters/en.yml +2 -0
  42. data/config/locales/headmin/filters/nl.yml +2 -0
  43. data/config/locales/headmin/media/en.yml +1 -0
  44. data/config/locales/headmin/media/nl.yml +1 -0
  45. data/config/locales/headmin/pagination/en.yml +2 -0
  46. data/config/locales/headmin/pagination/nl.yml +2 -0
  47. data/config/routes.rb +2 -1
  48. data/lib/headmin/version.rb +1 -1
  49. data/package.json +1 -1
  50. metadata +12 -3
  51. data/app/views/headmin/media/_item.html.erb +0 -16
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a0d9ff0c21ed70d23b6f58a61c4853028cc2580cdd23e7df89cdfce51d6c547e
4
- data.tar.gz: 2e0c0aeb8efc4294c2a01bd04c46949e97a9a9c7056e5d0caf99f75339ff02d7
3
+ metadata.gz: 4ec99ac85337bc096a16478a65e5434f37209281e861043a59f8cd4692197851
4
+ data.tar.gz: e3c9bf55658ce12c6d96ca0791ffa7e2dae14df3df9798e4ee21dc4b07b2f994
5
5
  SHA512:
6
- metadata.gz: f0712678aa575c3e982ec2359b9f1bb949b968ca8785ea482db63319b3fa843413a0e5744b31c8c7e917aafbd7db676fe2270d4e2e0b6ce419e90e2c82d06d5b
7
- data.tar.gz: a6965e77198490afc58e7825da2db8711a540159e6a0366c660f9c15c2f303fa19cfbef006540677efa6f8eb8bf9aee61bfde0d5a04c774d1393c5ac5cfda859
6
+ metadata.gz: c0eaf4ed9453bbc2cf383c82d050c708f7f8e7ba930c58fb9a0c2432ada5f4e928644b2d2e26ba331bd793bd4d58e5cca261f8e61ee091e987c90b62d6d096da
7
+ data.tar.gz: 249378b6c61d2d02b4349af48080fc9c53d8bba28fe41da0d7492c725502f2932384e3b9dfde718be1eca5f1cbc17c4d0ef884ec6dd21be804f0592be10bef7f
data/.gitignore CHANGED
@@ -25,3 +25,9 @@
25
25
  # Ingore editors
26
26
  /.idea
27
27
  /headmin.iml
28
+
29
+ # for a library or gem, you might want to ignore these files since the code is
30
+ # intended to run in multiple environments; otherwise, check them in:
31
+ Gemfile.lock
32
+ # .ruby-version
33
+ # .ruby-gemset
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- headmin (0.5.9)
4
+ headmin (0.6.1)
5
5
  closure_tree (~> 7.4)
6
6
  inline_svg (~> 1.7)
7
7
  redcarpet (~> 3.5)
@@ -10,67 +10,67 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- actioncable (7.0.4)
14
- actionpack (= 7.0.4)
15
- activesupport (= 7.0.4)
13
+ actioncable (7.0.4.1)
14
+ actionpack (= 7.0.4.1)
15
+ activesupport (= 7.0.4.1)
16
16
  nio4r (~> 2.0)
17
17
  websocket-driver (>= 0.6.1)
18
- actionmailbox (7.0.4)
19
- actionpack (= 7.0.4)
20
- activejob (= 7.0.4)
21
- activerecord (= 7.0.4)
22
- activestorage (= 7.0.4)
23
- activesupport (= 7.0.4)
18
+ actionmailbox (7.0.4.1)
19
+ actionpack (= 7.0.4.1)
20
+ activejob (= 7.0.4.1)
21
+ activerecord (= 7.0.4.1)
22
+ activestorage (= 7.0.4.1)
23
+ activesupport (= 7.0.4.1)
24
24
  mail (>= 2.7.1)
25
25
  net-imap
26
26
  net-pop
27
27
  net-smtp
28
- actionmailer (7.0.4)
29
- actionpack (= 7.0.4)
30
- actionview (= 7.0.4)
31
- activejob (= 7.0.4)
32
- activesupport (= 7.0.4)
28
+ actionmailer (7.0.4.1)
29
+ actionpack (= 7.0.4.1)
30
+ actionview (= 7.0.4.1)
31
+ activejob (= 7.0.4.1)
32
+ activesupport (= 7.0.4.1)
33
33
  mail (~> 2.5, >= 2.5.4)
34
34
  net-imap
35
35
  net-pop
36
36
  net-smtp
37
37
  rails-dom-testing (~> 2.0)
38
- actionpack (7.0.4)
39
- actionview (= 7.0.4)
40
- activesupport (= 7.0.4)
38
+ actionpack (7.0.4.1)
39
+ actionview (= 7.0.4.1)
40
+ activesupport (= 7.0.4.1)
41
41
  rack (~> 2.0, >= 2.2.0)
42
42
  rack-test (>= 0.6.3)
43
43
  rails-dom-testing (~> 2.0)
44
44
  rails-html-sanitizer (~> 1.0, >= 1.2.0)
45
- actiontext (7.0.4)
46
- actionpack (= 7.0.4)
47
- activerecord (= 7.0.4)
48
- activestorage (= 7.0.4)
49
- activesupport (= 7.0.4)
45
+ actiontext (7.0.4.1)
46
+ actionpack (= 7.0.4.1)
47
+ activerecord (= 7.0.4.1)
48
+ activestorage (= 7.0.4.1)
49
+ activesupport (= 7.0.4.1)
50
50
  globalid (>= 0.6.0)
51
51
  nokogiri (>= 1.8.5)
52
- actionview (7.0.4)
53
- activesupport (= 7.0.4)
52
+ actionview (7.0.4.1)
53
+ activesupport (= 7.0.4.1)
54
54
  builder (~> 3.1)
55
55
  erubi (~> 1.4)
56
56
  rails-dom-testing (~> 2.0)
57
57
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
58
- activejob (7.0.4)
59
- activesupport (= 7.0.4)
58
+ activejob (7.0.4.1)
59
+ activesupport (= 7.0.4.1)
60
60
  globalid (>= 0.3.6)
61
- activemodel (7.0.4)
62
- activesupport (= 7.0.4)
63
- activerecord (7.0.4)
64
- activemodel (= 7.0.4)
65
- activesupport (= 7.0.4)
66
- activestorage (7.0.4)
67
- actionpack (= 7.0.4)
68
- activejob (= 7.0.4)
69
- activerecord (= 7.0.4)
70
- activesupport (= 7.0.4)
61
+ activemodel (7.0.4.1)
62
+ activesupport (= 7.0.4.1)
63
+ activerecord (7.0.4.1)
64
+ activemodel (= 7.0.4.1)
65
+ activesupport (= 7.0.4.1)
66
+ activestorage (7.0.4.1)
67
+ actionpack (= 7.0.4.1)
68
+ activejob (= 7.0.4.1)
69
+ activerecord (= 7.0.4.1)
70
+ activesupport (= 7.0.4.1)
71
71
  marcel (~> 1.0)
72
72
  mini_mime (>= 1.1.0)
73
- activesupport (7.0.4)
73
+ activesupport (7.0.4.1)
74
74
  concurrent-ruby (~> 1.0, >= 1.0.2)
75
75
  i18n (>= 1.6, < 2)
76
76
  minitest (>= 5.1)
@@ -96,9 +96,10 @@ GEM
96
96
  closure_tree (7.4.0)
97
97
  activerecord (>= 4.2.10)
98
98
  with_advisory_lock (>= 4.0.0)
99
- concurrent-ruby (1.1.10)
99
+ concurrent-ruby (1.2.0)
100
100
  crass (1.0.6)
101
- debug (1.7.0)
101
+ date (3.3.3)
102
+ debug (1.7.1)
102
103
  irb (>= 1.5.0)
103
104
  reline (>= 0.3.1)
104
105
  devise (4.8.1)
@@ -109,9 +110,9 @@ GEM
109
110
  warden (~> 1.2.3)
110
111
  enumerize (2.5.0)
111
112
  activesupport (>= 3.2)
112
- erubi (1.11.0)
113
+ erubi (1.12.0)
113
114
  ffi (1.15.5)
114
- globalid (1.0.0)
115
+ globalid (1.0.1)
115
116
  activesupport (>= 5.0)
116
117
  hotwire-rails (0.1.3)
117
118
  rails (>= 6.0.0)
@@ -128,8 +129,8 @@ GEM
128
129
  inline_svg (1.8.0)
129
130
  activesupport (>= 3.0)
130
131
  nokogiri (>= 1.6)
131
- io-console (0.5.11)
132
- irb (1.5.1)
132
+ io-console (0.6.0)
133
+ irb (1.6.2)
133
134
  reline (>= 0.3.0)
134
135
  json (2.6.3)
135
136
  kaminari (1.2.2)
@@ -145,10 +146,10 @@ GEM
145
146
  kaminari-core (= 1.2.2)
146
147
  kaminari-core (1.2.2)
147
148
  language_server-protocol (3.17.0.2)
148
- loofah (2.19.0)
149
+ loofah (2.19.1)
149
150
  crass (~> 1.0.2)
150
151
  nokogiri (>= 1.5.9)
151
- mail (2.8.0)
152
+ mail (2.8.0.1)
152
153
  mini_mime (>= 0.1.1)
153
154
  net-imap
154
155
  net-pop
@@ -156,60 +157,61 @@ GEM
156
157
  marcel (1.0.2)
157
158
  matrix (0.4.2)
158
159
  method_source (1.0.0)
159
- mini_magick (4.11.0)
160
+ mini_magick (4.12.0)
160
161
  mini_mime (1.1.2)
161
- minitest (5.16.3)
162
+ minitest (5.17.0)
162
163
  minitest-spec-rails (6.2.0)
163
164
  minitest (>= 5.0)
164
165
  railties (>= 4.1)
165
- net-imap (0.3.1)
166
+ net-imap (0.3.4)
167
+ date
166
168
  net-protocol
167
169
  net-pop (0.1.2)
168
170
  net-protocol
169
- net-protocol (0.2.0)
171
+ net-protocol (0.2.1)
170
172
  timeout
171
173
  net-smtp (0.3.3)
172
174
  net-protocol
173
175
  nio4r (2.5.8)
174
- nokogiri (1.13.9-arm64-darwin)
176
+ nokogiri (1.14.0-arm64-darwin)
175
177
  racc (~> 1.4)
176
- nokogiri (1.13.9-x86_64-darwin)
178
+ nokogiri (1.14.0-x86_64-darwin)
177
179
  racc (~> 1.4)
178
- nokogiri (1.13.9-x86_64-linux)
180
+ nokogiri (1.14.0-x86_64-linux)
179
181
  racc (~> 1.4)
180
182
  orm_adapter (0.5.0)
181
183
  parallel (1.22.1)
182
- parser (3.1.3.0)
184
+ parser (3.2.0.0)
183
185
  ast (~> 2.4.1)
184
- public_suffix (5.0.0)
186
+ public_suffix (5.0.1)
185
187
  puma (5.6.5)
186
188
  nio4r (~> 2.0)
187
- racc (1.6.1)
188
- rack (2.2.4)
189
+ racc (1.6.2)
190
+ rack (2.2.6.2)
189
191
  rack-test (2.0.2)
190
192
  rack (>= 1.3)
191
- rails (7.0.4)
192
- actioncable (= 7.0.4)
193
- actionmailbox (= 7.0.4)
194
- actionmailer (= 7.0.4)
195
- actionpack (= 7.0.4)
196
- actiontext (= 7.0.4)
197
- actionview (= 7.0.4)
198
- activejob (= 7.0.4)
199
- activemodel (= 7.0.4)
200
- activerecord (= 7.0.4)
201
- activestorage (= 7.0.4)
202
- activesupport (= 7.0.4)
193
+ rails (7.0.4.1)
194
+ actioncable (= 7.0.4.1)
195
+ actionmailbox (= 7.0.4.1)
196
+ actionmailer (= 7.0.4.1)
197
+ actionpack (= 7.0.4.1)
198
+ actiontext (= 7.0.4.1)
199
+ actionview (= 7.0.4.1)
200
+ activejob (= 7.0.4.1)
201
+ activemodel (= 7.0.4.1)
202
+ activerecord (= 7.0.4.1)
203
+ activestorage (= 7.0.4.1)
204
+ activesupport (= 7.0.4.1)
203
205
  bundler (>= 1.15.0)
204
- railties (= 7.0.4)
206
+ railties (= 7.0.4.1)
205
207
  rails-dom-testing (2.0.3)
206
208
  activesupport (>= 4.2.0)
207
209
  nokogiri (>= 1.6)
208
- rails-html-sanitizer (1.4.3)
209
- loofah (~> 2.3)
210
- railties (7.0.4)
211
- actionpack (= 7.0.4)
212
- activesupport (= 7.0.4)
210
+ rails-html-sanitizer (1.5.0)
211
+ loofah (~> 2.19, >= 2.19.1)
212
+ railties (7.0.4.1)
213
+ actionpack (= 7.0.4.1)
214
+ activesupport (= 7.0.4.1)
213
215
  method_source
214
216
  rake (>= 12.2)
215
217
  thor (~> 1.0)
@@ -217,8 +219,8 @@ GEM
217
219
  rainbow (3.1.1)
218
220
  rake (13.0.6)
219
221
  redcarpet (3.5.1)
220
- regexp_parser (2.6.1)
221
- reline (0.3.1)
222
+ regexp_parser (2.6.2)
223
+ reline (0.3.2)
222
224
  io-console (~> 0.5)
223
225
  responders (3.0.1)
224
226
  actionpack (>= 5.0)
@@ -229,19 +231,19 @@ GEM
229
231
  actionpack (>= 5.2, < 7.1)
230
232
  activesupport (>= 5.2, < 7.1)
231
233
  addressable (~> 2.7)
232
- rubocop (1.39.0)
234
+ rubocop (1.42.0)
233
235
  json (~> 2.3)
234
236
  parallel (~> 1.10)
235
237
  parser (>= 3.1.2.1)
236
238
  rainbow (>= 2.2.2, < 4.0)
237
239
  regexp_parser (>= 1.8, < 3.0)
238
240
  rexml (>= 3.2.5, < 4.0)
239
- rubocop-ast (>= 1.23.0, < 2.0)
241
+ rubocop-ast (>= 1.24.1, < 2.0)
240
242
  ruby-progressbar (~> 1.7)
241
243
  unicode-display_width (>= 1.4.0, < 3.0)
242
- rubocop-ast (1.24.0)
244
+ rubocop-ast (1.24.1)
243
245
  parser (>= 3.1.1.0)
244
- rubocop-performance (1.15.1)
246
+ rubocop-performance (1.15.2)
245
247
  rubocop (>= 1.7.0, < 2.0)
246
248
  rubocop-ast (>= 0.4.0)
247
249
  ruby-progressbar (1.11.0)
@@ -255,20 +257,20 @@ GEM
255
257
  sprockets (> 3.0)
256
258
  sprockets-rails
257
259
  tilt
258
- sprockets (4.1.1)
260
+ sprockets (4.2.0)
259
261
  concurrent-ruby (~> 1.0)
260
- rack (> 1, < 3)
262
+ rack (>= 2.2.4, < 4)
261
263
  sprockets-rails (3.4.2)
262
264
  actionpack (>= 5.2)
263
265
  activesupport (>= 5.2)
264
266
  sprockets (>= 3.0.0)
265
- sqlite3 (1.5.4-arm64-darwin)
266
- sqlite3 (1.5.4-x86_64-darwin)
267
- sqlite3 (1.5.4-x86_64-linux)
268
- standard (1.19.1)
267
+ sqlite3 (1.6.0-arm64-darwin)
268
+ sqlite3 (1.6.0-x86_64-darwin)
269
+ sqlite3 (1.6.0-x86_64-linux)
270
+ standard (1.22.1)
269
271
  language_server-protocol (~> 3.17.0.2)
270
- rubocop (= 1.39.0)
271
- rubocop-performance (= 1.15.1)
272
+ rubocop (= 1.42.0)
273
+ rubocop-performance (= 1.15.2)
272
274
  stimulus-rails (1.2.1)
273
275
  railties (>= 6.0.0)
274
276
  thor (1.2.1)
@@ -280,7 +282,7 @@ GEM
280
282
  railties (>= 6.0.0)
281
283
  tzinfo (2.0.5)
282
284
  concurrent-ruby (~> 1.0)
283
- unicode-display_width (2.3.0)
285
+ unicode-display_width (2.4.2)
284
286
  warden (1.2.9)
285
287
  rack (>= 2.0.9)
286
288
  websocket-driver (0.7.5)
data/README.md CHANGED
@@ -128,8 +128,8 @@ $ bundle
128
128
  # Update the version number, push commits and tag the release
129
129
  $ gem bump -v {patch,minor,major,...} --push --tag
130
130
 
131
- # Release to Rubygems
132
- $ gem release
131
+ # Release to Rubygems and create a Github release tag
132
+ $ gem release --github
133
133
  ```
134
134
 
135
135
  Update the node package
@@ -15,8 +15,6 @@ export default class extends Controller {
15
15
  // This allows calling controller methods from the element in other controllers
16
16
  connect () {
17
17
  this.element.controller = this
18
-
19
- this.updateHiddenValue()
20
18
  }
21
19
 
22
20
  toggle (event) {
@@ -89,7 +87,21 @@ export default class extends Controller {
89
87
  for (const row of this.rowTargets) {
90
88
  const conditional = row.previousElementSibling ? row.previousElementSibling.querySelector('[data-filter-target="conditional"]').value : null
91
89
  const operator = row.querySelector('[data-filter-target="operator"]').value
92
- const value = row.querySelector('[data-filter-target="value"]').value
90
+ let values = Array.from(row.querySelectorAll('[data-filter-target="value"]'))
91
+
92
+ // Only the visible elements are of interest
93
+ values = values.filter((element) => {
94
+ return element.style.display;
95
+ })
96
+
97
+ // Grab the value of each visible element
98
+ values = values.map((element) => {
99
+ return element.value
100
+ })
101
+
102
+ // Concatenate array to a string
103
+ const value = values.join(",")
104
+
93
105
  string += `${conditional || ''}${operator}:${value}`
94
106
  }
95
107
 
@@ -1,50 +1,78 @@
1
- import { Controller } from '@hotwired/stimulus'
1
+ import {Controller} from '@hotwired/stimulus'
2
2
 
3
3
  export default class extends Controller {
4
- static get targets () {
5
- return ['original', 'operator', 'null']
6
- }
7
-
8
- connect () {
9
- this.operatorTarget.addEventListener('change', () => this.handleOperatorChange())
10
- this.handleOperatorChange()
11
- }
12
-
13
- handleOperatorChange () {
14
- if (this.operatorTarget.value === 'is_null' || this.operatorTarget.value === 'is_not_null') {
15
- this.toggleNullInput()
16
- } else {
17
- this.toggleOriginalInput()
18
- }
19
- }
20
-
21
- toggleNullInput () {
22
- this.hideOriginal()
23
- this.showNull()
24
- }
25
-
26
- toggleOriginalInput () {
27
- this.showOriginal()
28
- this.hideNull()
29
- }
30
-
31
- hideOriginal () {
32
- this.originalTarget.style.display = 'none'
33
- this.originalTarget.setAttribute('data-filter-target', 'value_original')
34
- }
35
-
36
- showOriginal () {
37
- this.originalTarget.style.display = 'block'
38
- this.originalTarget.setAttribute('data-filter-target', 'value')
39
- }
40
-
41
- hideNull () {
42
- this.nullTarget.style.display = 'none'
43
- this.nullTarget.setAttribute('data-filter-target', 'value_null')
44
- }
45
-
46
- showNull () {
47
- this.nullTarget.style.display = 'block'
48
- this.nullTarget.setAttribute('data-filter-target', 'value')
49
- }
4
+ static get targets() {
5
+ return ['original', 'operator', 'null']
6
+ }
7
+
8
+ connect() {
9
+ this.operatorTarget.addEventListener('change', () => this.handleOperatorChange())
10
+ this.handleOperatorChange()
11
+ }
12
+
13
+ handleOperatorChange() {
14
+ if (this.operatorTarget.value === 'is_null' || this.operatorTarget.value === 'is_not_null') {
15
+ this.toggleNullInput()
16
+ } else if (this.operatorTarget.value === 'between' || this.operatorTarget.value === 'not_between') {
17
+ this.toggleSecondaryInput()
18
+ } else {
19
+ this.toggleOriginalInput()
20
+ }
21
+ }
22
+
23
+ toggleNullInput() {
24
+ this.hideOriginal()
25
+ this.hideSecondary()
26
+ this.showNull()
27
+ }
28
+
29
+ toggleOriginalInput() {
30
+ this.showOriginal()
31
+ this.hideSecondary()
32
+ this.hideNull()
33
+ }
34
+
35
+ toggleSecondaryInput() {
36
+ this.showSecondary()
37
+ this.hideOriginal()
38
+ this.hideNull()
39
+ }
40
+
41
+ hideOriginal() {
42
+ this.originalTarget.style.display = 'none'
43
+ this.originalTarget.setAttribute('data-filter-target', 'value_original')
44
+ }
45
+
46
+ showOriginal() {
47
+ this.originalTarget.style.display = 'block'
48
+ this.originalTarget.setAttribute('data-filter-target', 'value')
49
+ }
50
+
51
+ hideSecondary() {
52
+ for (const [index, value] of this.originalTargets.entries()) {
53
+ if (index != 0) {
54
+ value.style.display = 'none'
55
+ value.setAttribute('data-filter-target', 'value_original')
56
+ }
57
+ }
58
+ }
59
+
60
+ showSecondary() {
61
+ for (const [index, value] of this.originalTargets.entries()) {
62
+ if (index != 0) {
63
+ value.style.display = 'block'
64
+ value.setAttribute('data-filter-target', 'value')
65
+ }
66
+ }
67
+ }
68
+
69
+ hideNull() {
70
+ this.nullTarget.style.display = 'none'
71
+ this.nullTarget.setAttribute('data-filter-target', 'value_null')
72
+ }
73
+
74
+ showNull() {
75
+ this.nullTarget.style.display = 'block'
76
+ this.nullTarget.setAttribute('data-filter-target', 'value')
77
+ }
50
78
  }
@@ -0,0 +1,30 @@
1
+ /* global fetch, Event */
2
+ import { Controller } from '@hotwired/stimulus'
3
+
4
+ export default class extends Controller {
5
+ connect() {
6
+ this.clickWhenInViewport()
7
+
8
+ document.querySelector(".modal-body").addEventListener("scroll", () => {
9
+ this.clickWhenInViewport()
10
+ })
11
+ }
12
+
13
+ clickWhenInViewport() {
14
+ if (!this.isLoading() && this.isInViewport()) {
15
+ this.element.setAttribute("clicked", 1)
16
+ this.element.click()
17
+ }
18
+ }
19
+
20
+ isLoading() {
21
+ return this.element.hasAttribute("clicked")
22
+ }
23
+
24
+ isInViewport() {
25
+ const rect = this.element.getBoundingClientRect()
26
+
27
+ return rect.top >= 0 && rect.left >= 0 && rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && rect.right <= (window.innerWidth || document.documentElement.clientWidth);
28
+ }
29
+
30
+ }
@@ -66,10 +66,10 @@ export default class extends Controller {
66
66
 
67
67
  selectItems (items) {
68
68
  // Destroy all deselected items
69
- this.removeAllItems()
69
+ this.removeAllDeselectedItems(items)
70
70
 
71
- // Add all selected items
72
- this.addItems(items)
71
+ // Add all new selected items
72
+ this.addNewItems(items)
73
73
 
74
74
  this.postProcess()
75
75
  }
@@ -129,8 +129,16 @@ export default class extends Controller {
129
129
  })
130
130
  }
131
131
 
132
- addItems (items) {
133
- items.forEach((item) => this.addItem(item))
132
+ addNewItems (items) {
133
+ const itemTargetIds = this.itemTargets.map((i) => { return parseInt(i.querySelectorAll("input")[1].value)})
134
+ items.forEach((item) => {
135
+ if (itemTargetIds.includes(item.blobId)) {
136
+ // Do not add this item (as it is already present)
137
+ return
138
+ }
139
+
140
+ this.addItem(item)
141
+ })
134
142
  }
135
143
 
136
144
  addItem (item) {
@@ -192,12 +200,20 @@ export default class extends Controller {
192
200
  return template.innerHTML.replace(regex, randomNumber)
193
201
  }
194
202
 
195
- removeAllItems () {
196
- this.removeItems(this.itemTargets)
203
+ removeAllDeselectedItems (items) {
204
+ this.removeDeselectedItems(items, this.itemTargets)
197
205
  }
198
206
 
199
- removeItems (items) {
207
+ removeDeselectedItems (elements, items) {
208
+ const returnedBlobIds = elements.map((e) => { return e.blobId})
209
+
200
210
  items.forEach((item) => {
211
+ const blobId = parseInt(item.querySelectorAll("input")[1].value)
212
+ if (returnedBlobIds.includes(blobId)) {
213
+ // Do not delete this one
214
+ return;
215
+ }
216
+
201
217
  this.removeItem(item)
202
218
  })
203
219
  }