rails_admin_next 3.0.2 → 4.0.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.
Files changed (60) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -0
  3. data/README.md +25 -7
  4. data/app/assets/stylesheets/rails_admin/skin.css +240 -7
  5. data/app/assets/stylesheets/rails_admin/tokens.css +4 -0
  6. data/app/controllers/rails_admin_next/bulk_deletions_controller.rb +27 -0
  7. data/app/controllers/rails_admin_next/main_controller.rb +34 -5
  8. data/app/helpers/rails_admin_next/application_helper.rb +17 -2
  9. data/app/helpers/rails_admin_next/main_helper.rb +64 -0
  10. data/app/jobs/rails_admin_next/bulk_delete_job.rb +65 -0
  11. data/app/views/layouts/rails_admin_next/_head.html.erb +14 -6
  12. data/app/views/layouts/rails_admin_next/content.html.erb +1 -0
  13. data/app/views/rails_admin_next/bulk_deletions/_banner.html.erb +30 -0
  14. data/app/views/rails_admin_next/main/_batch.html.erb +9 -0
  15. data/app/views/rails_admin_next/main/_history_row.html.erb +32 -0
  16. data/app/views/rails_admin_next/main/_list_row.html.erb +19 -0
  17. data/app/views/rails_admin_next/main/_next_batch.html.erb +21 -0
  18. data/app/views/rails_admin_next/main/_selection_bar.html.erb +30 -0
  19. data/app/views/rails_admin_next/main/bulk_delete.html.erb +26 -6
  20. data/app/views/rails_admin_next/main/export.html.erb +1 -0
  21. data/app/views/rails_admin_next/main/history.html.erb +5 -36
  22. data/app/views/rails_admin_next/main/index.html.erb +28 -57
  23. data/config/importmap.rails_admin.rb +7 -2
  24. data/config/locales/rails_admin_next.en.yml +37 -4
  25. data/config/routes.rb +2 -0
  26. data/docs/UPGRADING.md +195 -2
  27. data/docs/security.md +18 -8
  28. data/docs/upstream-parity.md +1 -1
  29. data/lib/rails_admin_next/adapters/active_record.rb +7 -0
  30. data/lib/rails_admin_next/bulk_deletion/progress.rb +70 -0
  31. data/lib/rails_admin_next/bulk_deletion.rb +99 -0
  32. data/lib/rails_admin_next/config/actions/base.rb +7 -0
  33. data/lib/rails_admin_next/config/actions/bulk_delete.rb +94 -31
  34. data/lib/rails_admin_next/config/actions/export.rb +4 -0
  35. data/lib/rails_admin_next/config/actions/history_index.rb +1 -1
  36. data/lib/rails_admin_next/config/actions/history_show.rb +1 -1
  37. data/lib/rails_admin_next/config/actions/index.rb +6 -1
  38. data/lib/rails_admin_next/config/fields/types/action_text.rb +11 -0
  39. data/lib/rails_admin_next/config/sections/list.rb +1 -2
  40. data/lib/rails_admin_next/engine.rb +1 -0
  41. data/lib/rails_admin_next/extensions/paper_trail/auditing_adapter.rb +8 -3
  42. data/lib/rails_admin_next/support/action_text_editor.rb +36 -0
  43. data/lib/rails_admin_next/support/paginated_collection.rb +4 -5
  44. data/lib/rails_admin_next/version.rb +4 -5
  45. data/lib/rails_admin_next.rb +3 -0
  46. data/skills/rails-admin-next/SKILL.md +3 -3
  47. data/src/rails_admin/controllers/alert_controller.js +3 -1
  48. data/src/rails_admin/controllers/bulk_progress_controller.js +53 -0
  49. data/src/rails_admin/controllers/bulk_selection_controller.js +151 -0
  50. data/src/rails_admin/controllers/dropdown_controller.js +7 -5
  51. data/src/rails_admin/controllers/filtering_multiselect_controller.js +4 -0
  52. data/src/rails_admin/controllers/filtering_select_controller.js +4 -0
  53. data/src/rails_admin/controllers/index.js +6 -0
  54. data/src/rails_admin/controllers/infinite_scroll_controller.js +79 -0
  55. data/src/rails_admin/controllers/modal_controller.js +3 -1
  56. data/src/rails_admin/controllers/nested_form_controller.js +3 -2
  57. data/src/rails_admin/controllers/sidescroll_controller.js +41 -10
  58. data/src/rails_admin/interactions.js +4 -12
  59. metadata +24 -5
  60. data/app/views/rails_admin_next/main/_pagination.html.erb +0 -54
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 50219c685864a241e7cca2ff03fbd7c0d8e7c3c9a1f49e65bb19b73f15924525
4
- data.tar.gz: 37808fdd9c7012a71cd5e6973102dc0b3baf2c2fb7778a4c2eb0421ca4df585a
3
+ metadata.gz: 15f1f39d2087993d1ef84025a544e0f188426b452d38ad2ccbbeb96c4d4b1c90
4
+ data.tar.gz: 579d223caa8d59d273f1fdfea9a61bd5412014f90e208b48e90987192260b4d9
5
5
  SHA512:
6
- metadata.gz: 9a85fc8b87439b96f6910ec47d197d35d889dd4da565138982e25db0f039b7cbcef93178b98dae160f29ee8c701f7d3d58c827f85dc8b7172b8107536ac62f2b
7
- data.tar.gz: d6b0b230e6ee33e864b9242fcff419197cc52e24220a007b0743585388ec96261c8bdb22b3384e2e79338d445cca4d26d4a4e7dd53f36ad48e1778a8179790ff
6
+ metadata.gz: 73a140a179b5856b9260bea95711e4ccbfc72aee5e279f4580444982439e418cdd5afc72b0397a52c3176729e893b83d009a4d49f56dce5da4203a1c0d84e6ae
7
+ data.tar.gz: 1b35ab200fe3bb2265cf1d78904d7c8e8d11725c1b97d6ea94174627699da6c1a391e175614ea97624aa089e11b253ddeff009520017e06e49a6523882de5475
data/Gemfile CHANGED
@@ -18,6 +18,9 @@ group :test do
18
18
  gem "factory_bot"
19
19
  gem "generator_spec"
20
20
  gem "image_processing"
21
+ # Only the Lexxy CI leg loads it. Lexxy replaces rich_text_area app-wide, so the whole suite
22
+ # runs on that leg, and the gem stays out of the gemspec: hosts bring their own editor.
23
+ gem "lexxy" if ENV["CI_ACTION_TEXT_EDITOR"] == "lexxy"
21
24
  gem "pundit"
22
25
  # Pinned within 0.10: Gemfile.lock is not committed here, so CI resolves fresh on every run
23
26
  # and no Dependabot PR stages a release first, and the discovery spec drives Hyperdrive's
data/README.md CHANGED
@@ -6,9 +6,9 @@
6
6
 
7
7
  **Rails ~> 8.1 · ActiveRecord · importmap + Propshaft · Turbo + Stimulus · zero build step**
8
8
 
9
- [![Build](https://github.com/6temes/rails_admin_next/actions/workflows/test.yml/badge.svg)](https://github.com/6temes/rails_admin_next/actions/workflows/test.yml)
9
+ [![Build](https://github.com/6temes/rails_admin_next/actions/workflows/ci.yml/badge.svg)](https://github.com/6temes/rails_admin_next/actions/workflows/ci.yml)
10
10
  [![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md)
11
- [![Ruby](https://img.shields.io/badge/Ruby-4.0.9%2B-CC342D.svg)](https://www.ruby-lang.org)
11
+ [![Ruby](https://img.shields.io/badge/Ruby-4.0.10%2B-CC342D.svg)](https://www.ruby-lang.org)
12
12
  [![Rails](https://img.shields.io/badge/Rails-8.1-CC0000.svg)](https://rubyonrails.org)
13
13
 
14
14
  [Why RailsAdminNext?](#why-railsadminnext) ◆ [Quick Start](#quick-start) ◆ [Installation](#installation) ◆ [Architecture](#architecture) ◆ [Security](#security) ◆ [Upgrading](#upgrading-from-railsadmin)
@@ -32,7 +32,7 @@ multi-bundler, jQuery-era machinery. RailsAdminNext keeps the admin and drops th
32
32
  - **⚡ Zero build step** — browser-native ESM over **importmap + Propshaft**; no Webpack/Vite/Sprockets, no `yarn build`, no generated pins.
33
33
  - **🧩 Turbo + Stimulus** — the jQuery / jQuery-UI / Bootstrap-JS / `@rails/ujs` stack is gone, replaced by engine-shipped Stimulus controllers; styling is hand-maintained vanilla CSS.
34
34
  - **🔒 Hardened & CDN-free** — a documented CSRF / clickjacking / mass-assignment / CSP posture ([SECURITY.md](SECURITY.md)) and **zero external CDN**, default or opt-in — every asset is self-hosted off a gem.
35
- - **🎯 One modern target** — Ruby ≥ 4.0.9, Rails ~> 8.1, ActiveRecord only, latest Chrome + Safari. No Mongoid, no multi-bundler / multi-Rails matrix, no legacy-browser CSS.
35
+ - **🎯 One modern target** — Ruby ≥ 4.0.10, Rails ~> 8.1, ActiveRecord only, latest Chrome + Safari. No Mongoid, no multi-bundler / multi-Rails matrix, no legacy-browser CSS.
36
36
  - **↩️ Familiar** — `RailsAdminNext.config`, per-model `rails_admin_next do … end` blocks, and Pundit authorization all work as before; upgrading from RailsAdmin is a mechanical rename.
37
37
 
38
38
  ## Quick Start
@@ -50,11 +50,11 @@ bin/rails s # then open http://localhost:3000/admin
50
50
 
51
51
  That's the whole setup — no `yarn add`, no asset build, no generated pins. The engine ships its own importmap and CSS.
52
52
 
53
- > **Prerequisites:** Ruby ≥ 4.0.9 · Rails ~> 8.1 · ActiveRecord · a [Propshaft][propshaft] + [importmap-rails][importmap] host (both are pulled in as dependencies). See [Installation](#installation) for the full walkthrough.
53
+ > **Prerequisites:** Ruby ≥ 4.0.10 · Rails ~> 8.1 · ActiveRecord · a [Propshaft][propshaft] + [importmap-rails][importmap] host (both are pulled in as dependencies). See [Installation](#installation) for the full walkthrough.
54
54
 
55
55
  ## Requirements
56
56
 
57
- - Ruby >= 4.0.9
57
+ - Ruby >= 4.0.10
58
58
  - Rails ~> 8.1
59
59
  - ActiveRecord (Mongoid is not supported)
60
60
  - [Propshaft][propshaft] and [importmap-rails][importmap] (both are pulled in as
@@ -111,7 +111,7 @@ always match the installed version.
111
111
  - Search and filtering
112
112
  - Export data to CSV / JSON / XML
113
113
  - File uploads (ActiveStorage)
114
- - Rich text fields (ActionText / Trix)
114
+ - Rich text fields (ActionText), in the host's editor: Trix or Lexxy
115
115
  - Authentication (via [Devise][devise] or any other scheme)
116
116
  - Authorization (via [Pundit][pundit], [ActionPolicy][action_policy] or a custom adapter)
117
117
  - User action history (via [PaperTrail][papertrail])
@@ -145,6 +145,22 @@ end
145
145
 
146
146
  This is also where you wire up [Devise][devise], [Pundit][pundit], and [PaperTrail][papertrail].
147
147
 
148
+ Ticking every loaded row of a list offers "Select all N matching", which hands "Export found" and
149
+ bulk delete the whole filtered set. A bulk delete larger than `background_threshold` (500 by
150
+ default) runs as background jobs on your ActiveJob adapter, with a progress banner kept in
151
+ `Rails.cache`:
152
+
153
+ ```ruby
154
+ config.actions do
155
+ bulk_delete do
156
+ background_threshold 1_000 # Float::INFINITY keeps every delete in the request
157
+ authorization_limit 20_000 # with Pundit or ActionPolicy, larger sets are refused (default 10,000)
158
+ end
159
+ end
160
+ ```
161
+
162
+ A custom bulk action accepts every matching record with `register_instance_option(:all_matching?) { true }`.
163
+
148
164
  Every admin page ends with a small "Made in Tokyo with ❤️ and 🤖" footer. To hide it:
149
165
 
150
166
  ```ruby
@@ -215,7 +231,7 @@ Compared to RailsAdmin, the following were intentionally removed:
215
231
  - **Webpack, Webpacker, Vite, and Sprockets** — importmap + Propshaft only.
216
232
  - **jQuery, jQuery-UI, Bootstrap's JS, and `@rails/ujs`** — replaced by Stimulus controllers.
217
233
  - **Standalone WYSIWYG/code editors** (`bootstrap-wysihtml5`, `froala`, CKEditor, CodeMirror,
218
- SimpleMDE) — they loaded from a CDN; use ActionText/Trix rich text (self-hosted) or a plain
234
+ SimpleMDE) — they loaded from a CDN; use ActionText rich text (Trix or Lexxy, self-hosted) or a plain
219
235
  `:text` textarea instead.
220
236
  - **Drag-to-reorder for multiple uploads** (it relied on jQuery-UI sortable).
221
237
  - **flatpickr** — date/time fields use native HTML5 inputs (`type="date"`/`datetime-local`/`time`);
@@ -265,6 +281,8 @@ RailsAdminNext.config do |config|
265
281
  end
266
282
  ```
267
283
 
284
+ A Lexxy rich-text editor follows the scheme and the `--ra-*` tokens. Trix stays light.
285
+
268
286
  **Note for operators:** after upgrading, the admin renders dark for anyone whose OS prefers
269
287
  dark. Pin `config.color_scheme = :light` to keep the old always-light rendering; if
270
288
  something looks wrong in dark mode, please
@@ -103,7 +103,7 @@
103
103
 
104
104
  /* === Admin skin: layout and navbar ====================================== */
105
105
  body.rails_admin {
106
- padding-top: 3.275rem;
106
+ padding-top: var(--ra-navbar-height);
107
107
  .navbar .edit_user_root_link {
108
108
  position: relative;
109
109
  img {
@@ -431,15 +431,18 @@ body.rails_admin #filters_box {
431
431
  }
432
432
  }
433
433
  body.rails_admin .dashboard-statistics {
434
- overflow-x: auto;
435
- overscroll-behavior: contain;
434
+ overflow: auto hidden;
435
+ overscroll-behavior-x: contain;
436
436
  }
437
437
  body.rails_admin #sidescroll {
438
438
  margin-bottom: 20px;
439
- overflow-x: auto;
439
+ /* overflow-x: auto alone computes overflow-y to auto as well, and with a
440
+ pixel of sub-pixel overflow the wrapper becomes a vertical scroller that
441
+ swallows wheel scrolling meant for the page. */
442
+ overflow: auto hidden;
440
443
  /* Horizontal wheel/trackpad scrolls stop at the table edge instead of
441
444
  chaining into a browser back/forward navigation gesture. */
442
- overscroll-behavior: contain;
445
+ overscroll-behavior-x: contain;
443
446
  .table {
444
447
  margin-bottom: 0;
445
448
  }
@@ -459,6 +462,163 @@ body.rails_admin #sidescroll {
459
462
  body.rails_admin .pagination .page-item {
460
463
  white-space: nowrap;
461
464
  }
465
+ body.rails_admin .bulk-deletion-banner label {
466
+ display: block;
467
+ margin-bottom: 0.25rem;
468
+ }
469
+ body.rails_admin .bulk-deletion-banner progress {
470
+ width: 100%;
471
+ accent-color: var(--ra-primary);
472
+ }
473
+ /* Pinned under the navbar while any row is ticked. It sits outside #sidescroll
474
+ so a wide table scrolls sideways under it. */
475
+ body.rails_admin .selection-bar {
476
+ display: none;
477
+ position: sticky;
478
+ top: var(--ra-navbar-height);
479
+ z-index: 4;
480
+ flex-wrap: wrap;
481
+ align-items: center;
482
+ gap: 0.25rem 1rem;
483
+ min-height: var(--ra-selection-bar-height);
484
+ margin-bottom: 0.5rem;
485
+ padding: 0.25rem 0.75rem;
486
+ background-color: var(--ra-body-bg);
487
+ border-bottom: 1px solid var(--ra-border-color);
488
+ .selection-count,
489
+ .selection-menu {
490
+ white-space: nowrap;
491
+ }
492
+ .selection-offer,
493
+ .selection-clear {
494
+ padding: 0;
495
+ }
496
+ .selection-offer,
497
+ .selection-all-matching,
498
+ .selection-offer-short {
499
+ display: none;
500
+ }
501
+ .selection-menu {
502
+ margin-inline-start: auto;
503
+ }
504
+ }
505
+ /* On a phone Clear selection wraps onto a second line, so the bar is taller.
506
+ The count wraps beside the menu toggle rather than pushing it off the first
507
+ line. While the offer shows, or every match is selected, Clear selection
508
+ joins the toggle in place of the count and the short offer or the
509
+ all-matching text takes the second line, so neither state grows the bar. */
510
+ @media (max-width: 575.98px) {
511
+ :root {
512
+ --ra-selection-bar-height: 4.5rem;
513
+ }
514
+ body.rails_admin .selection-bar {
515
+ .selection-count {
516
+ flex: 1 1 0;
517
+ min-width: 0;
518
+ white-space: normal;
519
+ }
520
+ .selection-offer,
521
+ .selection-clear,
522
+ .selection-all-matching {
523
+ order: 1;
524
+ }
525
+ .selection-offer,
526
+ .selection-all-matching {
527
+ flex-basis: 100%;
528
+ text-align: start;
529
+ }
530
+ .selection-offer-full {
531
+ display: none;
532
+ }
533
+ .selection-offer-short {
534
+ display: inline;
535
+ }
536
+ }
537
+ body.rails_admin
538
+ #bulk_form:has(fieldset.all-matching:enabled)
539
+ .selection-clear {
540
+ order: 0;
541
+ }
542
+ /* The offer already says every loaded row is ticked, and the line has no
543
+ room for that count beside Clear selection and the toggle. */
544
+ body.rails_admin
545
+ #bulk_form:has(fieldset.all-matching:disabled):has(
546
+ .list-batch > .list-batch-status
547
+ ):not(:has(input[name="bulk_ids[]"]:not(:checked))) {
548
+ .selection-count {
549
+ display: none;
550
+ }
551
+ .selection-clear {
552
+ order: 0;
553
+ }
554
+ }
555
+ }
556
+ body.rails_admin
557
+ #bulk_form:has(input[name="bulk_ids[]"]:checked)
558
+ .selection-bar {
559
+ display: flex;
560
+ }
561
+ /* Every loaded row is ticked while a batch has yet to load, so more records
562
+ match than the ticks cover: offer them all. */
563
+ body.rails_admin
564
+ #bulk_form:has(fieldset.all-matching:disabled):has(
565
+ .list-batch > .list-batch-status
566
+ ):not(:has(input[name="bulk_ids[]"]:not(:checked)))
567
+ .selection-offer {
568
+ display: inline-block;
569
+ }
570
+ /* Every match is selected: the bar says so, and bulk actions that cannot act
571
+ on the whole set leave the menu. Hiding them is presentation only; the
572
+ server refuses an all-matching submit to an action that has not opted in. */
573
+ body.rails_admin #bulk_form:has(fieldset.all-matching:enabled) {
574
+ .selection-count {
575
+ display: none;
576
+ }
577
+ .selection-all-matching {
578
+ display: inline;
579
+ }
580
+ #bulk_menu li:has(> .bulk-link:not([data-all-matching])) {
581
+ display: none;
582
+ }
583
+ }
584
+ html:has(body.rails_admin #bulk_form input[name="bulk_ids[]"]:checked) {
585
+ scroll-padding-top: calc(
586
+ var(--ra-navbar-height) + var(--ra-selection-bar-height) + 0.5rem
587
+ );
588
+ }
589
+ /* The next-batch frame under an infinite-scroll list: its link while idle,
590
+ the loading text while Turbo marks the frame busy, and the error beside the
591
+ link (relabelled Retry) once a load failed. The error is a live region, so
592
+ it stays displayed and is empty until a load fails. Child combinators keep
593
+ a loaded frame's state from reaching the frame nested inside it. */
594
+ body.rails_admin .list-batch {
595
+ display: block;
596
+ }
597
+ body.rails_admin .list-batch-status,
598
+ body.rails_admin .list-end {
599
+ display: flex;
600
+ align-items: center;
601
+ justify-content: center;
602
+ margin: 0 0 1rem;
603
+ color: var(--ra-gray-600);
604
+ }
605
+ body.rails_admin .list-batch-loading {
606
+ display: none;
607
+ }
608
+ body.rails_admin .list-batch-error {
609
+ color: var(--ra-danger);
610
+ &:not(:empty) {
611
+ margin-inline-end: 0.75rem;
612
+ }
613
+ }
614
+ body.rails_admin .list-batch[busy] > .list-batch-status {
615
+ > .list-batch-loading {
616
+ display: inline;
617
+ }
618
+ > .list-batch-link {
619
+ display: none;
620
+ }
621
+ }
462
622
 
463
623
  /* === Admin skin: footer ================================================= */
464
624
  body.rails_admin .admin-footer {
@@ -475,14 +635,14 @@ body.rails_admin .admin-footer {
475
635
  body.rails_admin .admin-main {
476
636
  display: flex;
477
637
  flex-direction: column;
478
- min-height: calc(100dvh - 3.275rem);
638
+ min-height: calc(100dvh - var(--ra-navbar-height));
479
639
  }
480
640
  body.rails_admin .admin-main > .admin-footer {
481
641
  margin-top: auto;
482
642
  }
483
643
  body.rails_admin .sidebar.btn-toggle-nav {
484
644
  position: fixed;
485
- top: 3.275rem;
645
+ top: var(--ra-navbar-height);
486
646
  bottom: 0;
487
647
  overflow-y: auto;
488
648
  /* Sidebar scrolling stops at its own ends instead of chaining to the
@@ -492,3 +652,76 @@ body.rails_admin .admin-footer {
492
652
  scrollbar-gutter: stable;
493
653
  }
494
654
  }
655
+
656
+ /* === Rich text: Lexxy theme ============================================= */
657
+ /* Lexxy styles itself entirely through --lexxy-* variables, declared light-only
658
+ and unlayered on :root, where no layered rule can override them. Declaring
659
+ them on body instead wins by inheritance and reaches the modal <dialog> too.
660
+ The variables Lexxy derives with var() are restated here because they
661
+ resolve on :root, so body would otherwise inherit their light values. A host
662
+ overrides one with an unlayered rule on body.rails_admin. */
663
+ body.rails_admin {
664
+ --lexxy-color-ink: var(--ra-body-color);
665
+ --lexxy-color-ink-medium: var(--ra-gray-700);
666
+ --lexxy-color-ink-light: var(--ra-gray-600);
667
+ --lexxy-color-ink-lighter: var(--ra-gray-300);
668
+ --lexxy-color-ink-lightest: var(--ra-surface-muted);
669
+ /* Text on ink and accent fills (floating table controls, dialog buttons). */
670
+ --lexxy-color-ink-inverted: var(--ra-body-bg);
671
+
672
+ --lexxy-color-accent-dark: var(--ra-primary);
673
+ --lexxy-color-accent-medium: color-mix(
674
+ in oklch,
675
+ var(--ra-primary) 60%,
676
+ var(--ra-body-bg)
677
+ );
678
+ --lexxy-color-accent-light: color-mix(
679
+ in oklch,
680
+ var(--ra-primary) 30%,
681
+ var(--ra-body-bg)
682
+ );
683
+ --lexxy-color-accent-lightest: color-mix(
684
+ in oklch,
685
+ var(--ra-primary) 18%,
686
+ var(--ra-body-bg)
687
+ );
688
+
689
+ --lexxy-color-red: var(--ra-danger);
690
+ --lexxy-color-green: var(--ra-success);
691
+ --lexxy-color-blue: var(--ra-primary);
692
+
693
+ --lexxy-color-code-token-att: light-dark(#d73a49, #f97583);
694
+ --lexxy-color-code-token-comment: light-dark(#6a737d, #8b949e);
695
+ --lexxy-color-code-token-function: light-dark(#6f42c1, #d2a8ff);
696
+ --lexxy-color-code-token-operator: light-dark(#d73a49, #f97583);
697
+ --lexxy-color-code-token-property: light-dark(#005cc5, #79c0ff);
698
+ --lexxy-color-code-token-punctuation: light-dark(#24292e, #c9d1d9);
699
+ --lexxy-color-code-token-selector: light-dark(#22863a, #7ee787);
700
+ --lexxy-color-code-token-variable: light-dark(#e36209, #ffa657);
701
+
702
+ --lexxy-color-canvas: var(--lexxy-color-ink-inverted);
703
+ --lexxy-color-text: var(--lexxy-color-ink);
704
+ --lexxy-color-text-subtle: var(--lexxy-color-ink-medium);
705
+ --lexxy-color-link: var(--ra-link-color);
706
+ --lexxy-color-selected: var(--lexxy-color-accent-lightest);
707
+ --lexxy-color-selected-hover: var(--lexxy-color-accent-light);
708
+ --lexxy-color-selected-dark: var(--lexxy-color-blue);
709
+ --lexxy-color-selected-50: color-mix(
710
+ in oklch,
711
+ var(--lexxy-color-selected-dark) 50%,
712
+ transparent
713
+ );
714
+ --lexxy-color-code-bg: var(--lexxy-color-ink-lightest);
715
+
716
+ --lexxy-color-table-header-bg: var(--lexxy-color-ink-lightest);
717
+ --lexxy-color-table-cell-border: var(--lexxy-color-ink-lighter);
718
+ --lexxy-color-table-cell-selected: var(--lexxy-color-selected);
719
+ --lexxy-color-table-cell-selected-border: var(--lexxy-color-selected-dark);
720
+ --lexxy-color-table-cell-selected-bg: var(--lexxy-color-accent-lightest);
721
+ --lexxy-color-table-cell-add: var(--lexxy-color-selected-50);
722
+ --lexxy-color-table-cell-toggle: var(--lexxy-color-accent-lightest);
723
+
724
+ --lexxy-font-base: var(--ra-font-sans-serif);
725
+ --lexxy-font-mono: var(--ra-font-monospace);
726
+ --lexxy-focus-ring-color: var(--lexxy-color-accent-dark);
727
+ }
@@ -228,6 +228,10 @@
228
228
  --ra-body-font-size: 0.85rem;
229
229
  --ra-body-font-weight: 400;
230
230
  --ra-body-line-height: 1.5;
231
+
232
+ --ra-navbar-height: 3.275rem;
233
+ /* The selection bar's height; a focused row scrolls clear of it. */
234
+ --ra-selection-bar-height: 3rem;
231
235
  }
232
236
 
233
237
  /*
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RailsAdminNext
4
+ # Answers the progress banner's polls. Session membership is the access rule: there is no
5
+ # record to authorize against, so a host's verify_authorized check is told so.
6
+ class BulkDeletionsController < ApplicationController
7
+ def show
8
+ skip_host_authorization_checks
9
+ # A poll every two seconds must neither rewrite the session cookie nor keep a timed-out
10
+ # session alive.
11
+ request.session_options[:skip] = true
12
+
13
+ if Array(session[BulkDeletion::Progress::SESSION_KEY]).include?(params[:id])
14
+ render partial: "banner", locals: {id: params[:id], summary: BulkDeletion::Progress.summary(params[:id])}
15
+ else
16
+ render html: helpers.turbo_frame_tag(helpers.bulk_deletion_frame_id(params[:id]), class: "bulk-deletion")
17
+ end
18
+ end
19
+
20
+ private
21
+
22
+ # Pundit's and ActionPolicy's after_action verifications, which a host parent controller may run.
23
+ def skip_host_authorization_checks
24
+ %i[skip_authorization skip_policy_scope skip_verify_authorized! skip_verify_authorized_scoped!].each { send(it) if respond_to?(it, true) }
25
+ end
26
+ end
27
+ end
@@ -10,14 +10,22 @@ module RailsAdminNext
10
10
 
11
11
  before_action :check_for_cancel
12
12
 
13
- helper_method :list_scopes
13
+ helper_method :list_scope, :list_scopes
14
14
 
15
15
  def bulk_action
16
16
  get_model
17
- process(params[:bulk_action]) if params[:bulk_action].in?(RailsAdminNext::Config::Actions.all(:bulkable, controller: self, abstract_model: @abstract_model).collect(&:route_fragment))
17
+ action = RailsAdminNext::Config::Actions.all(:bulkable, controller: self, abstract_model: @abstract_model).detect { it.route_fragment == params[:bulk_action] }
18
+ return unless action
19
+
20
+ if params[:all_matching].present?
21
+ return redirect_to(back_or_index, notice: I18n.t("admin.flash.noaction")) unless action.all_matching?
22
+
23
+ params.delete(:bulk_ids)
24
+ end
25
+ process(params[:bulk_action])
18
26
  end
19
27
 
20
- def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = nil, pagination = !(params[:all] || params[:bulk_ids]))
28
+ def list_entries(model_config = @model_config, auth_scope_key = :index, additional_scope = nil, pagination = !(params[:all] || params[:bulk_ids] || all_matching?))
21
29
  scope = model_config.scope
22
30
  auth_scope = authorization_scope(auth_scope_key, model_config.abstract_model)
23
31
  scope = scope.merge(auth_scope) if auth_scope
@@ -192,7 +200,8 @@ module RailsAdminNext
192
200
  end
193
201
 
194
202
  def check_for_cancel
195
- cancelling = params[:_continue] || (params[:bulk_action] && !params[:bulk_ids])
203
+ # @action is not set yet, so the flag alone decides; bulk_action refuses it for an action that has not opted in.
204
+ cancelling = params[:_continue] || (params[:bulk_action] && !params[:bulk_ids] && params[:all_matching].blank?)
196
205
  return unless cancelling
197
206
 
198
207
  redirect_to(back_or_index, notice: I18n.t("admin.flash.noaction"))
@@ -208,10 +217,30 @@ module RailsAdminNext
208
217
  options = options.merge(get_sort_hash(model_config))
209
218
  options = options.merge(query: params[:query]) if params[:query].present?
210
219
  options = options.merge(filters: params[:f]) if params[:f].present?
211
- options = options.merge(bulk_ids: params[:bulk_ids]) if params[:bulk_ids]
220
+ options = options.merge(bulk_ids: params[:bulk_ids]) if params[:bulk_ids] && !all_matching?
212
221
  model_config.abstract_model.all(options, scope)
213
222
  end
214
223
 
224
+ def render_history
225
+ if batch_request?(@history)
226
+ render partial: "rails_admin_next/main/batch", layout: false,
227
+ locals: {collection: @history, row_partial: "history_row", row_locals: {}, url_proc: helpers.method(:history_batch_url)}
228
+ else
229
+ render @action.template_name
230
+ end
231
+ end
232
+
233
+ # A request from a list's own next-batch frame, answered with the batch's rows alone. A host
234
+ # frame wrapping the list gets the whole page.
235
+ def batch_request?(collection)
236
+ request.headers["Turbo-Frame"].to_s.start_with?("list_batch_") && collection.respond_to?(:full_page?)
237
+ end
238
+
239
+ # The relation is always rebuilt from the filter params, so the flag never trusts a client-side count or ids.
240
+ def all_matching?
241
+ params[:all_matching].present? && @action.all_matching?
242
+ end
243
+
215
244
  def list_scopes
216
245
  @_list_scopes ||= @model_config.list.with(controller: self, view: view_context, object: @abstract_model.model.new).scopes
217
246
  end
@@ -165,7 +165,7 @@ module RailsAdminNext
165
165
  li_class = ["nav-item", "icon", "#{action.key}_#{parent}_link"]
166
166
  .concat(action.enabled? ? [] : ["disabled"])
167
167
  content_tag(:li, {class: li_class}.merge(only_icon ? {title: wording, rel: "tooltip"} : {})) do
168
- label = rails_admin_icon(action.link_icon) + " " + content_tag(:span, wording, (only_icon ? {style: "display:none"} : {}))
168
+ label = rails_admin_icon(action.link_icon) + " " + content_tag(:span, wording, (only_icon ? {hidden: true} : {}))
169
169
  if action.enabled? || !only_icon
170
170
  href =
171
171
  if action.enabled?
@@ -181,6 +181,21 @@ module RailsAdminNext
181
181
  end.join(" ").html_safe
182
182
  end
183
183
 
184
+ def bulk_deletion_frame_id(id) = "bulk_deletion_#{id}"
185
+
186
+ # One banner per background delete the reader started. An id leaves the session once a
187
+ # full page has shown its final result, so polls alone never drop a banner unseen.
188
+ def bulk_deletion_banners
189
+ key = RailsAdminNext::BulkDeletion::Progress::SESSION_KEY
190
+ ids = session[key]
191
+ return if ids.blank?
192
+
193
+ banners = ids.map { [it, RailsAdminNext::BulkDeletion::Progress.summary(it)] }
194
+ running = banners.reject { it.last.terminal? }.map(&:first)
195
+ session[key] = running.presence if running != ids
196
+ safe_join(banners.map { |id, summary| render("rails_admin_next/bulk_deletions/banner", id:, summary:) })
197
+ end
198
+
184
199
  def bulk_menu(abstract_model = @abstract_model)
185
200
  actions = actions(:bulkable, abstract_model)
186
201
  return "" if actions.empty?
@@ -190,7 +205,7 @@ module RailsAdminNext
190
205
  content_tag(:ul, id: "bulk_menu", class: "dropdown-menu dropdown-menu-end", role: "menu", popover: "auto") do
191
206
  actions.collect do |action|
192
207
  content_tag :li, role: "none" do
193
- link_to wording_for(:bulk_link, action, abstract_model), "#", class: "dropdown-item bulk-link", role: "menuitem", tabindex: "-1", data: {action: action.action_name}
208
+ link_to wording_for(:bulk_link, action, abstract_model), "#", class: "dropdown-item bulk-link", role: "menuitem", tabindex: "-1", data: {bulk_action: action.action_name, all_matching: (true if action.all_matching?)}
194
209
  end
195
210
  end.join.html_safe
196
211
  end
@@ -2,6 +2,13 @@
2
2
 
3
3
  module RailsAdminNext
4
4
  module MainHelper
5
+ FILTER_OPERATOR_LABELS = {
6
+ "_blank" => "is_blank", "_not_null" => "is_present", "_null" => "is_blank", "_present" => "is_present",
7
+ "ends_with" => "ends_with", "false" => "false", "is" => "is_exactly", "last_week" => "last_week", "like" => "contains",
8
+ "not_like" => "does_not_contain", "starts_with" => "starts_with", "this_week" => "this_week",
9
+ "today" => "today", "true" => "true", "yesterday" => "yesterday"
10
+ }.freeze
11
+
5
12
  def rails_admin_form_for(*args, &)
6
13
  options = args.extract_options!.reverse_merge(builder: RailsAdminNext::FormBuilder)
7
14
  (options[:html] ||= {})[:novalidate] ||= !RailsAdminNext::Config.browser_validations
@@ -21,6 +28,63 @@ module RailsAdminNext
21
28
  "danger" # > 1/3 of max
22
29
  end
23
30
 
31
+ # The query string alone: a list rendered by a form submission must not carry the form's
32
+ # fields into the URLs it builds, which the next-batch frame requests on its own.
33
+ def list_params
34
+ @_list_params ||= request.query_parameters.except("utf8", "bulk_export").with_indifferent_access.tap do |list_params|
35
+ list_params.delete(:query) if list_params[:query].blank?
36
+ list_params.delete(:sort_reverse) unless list_params[:sort_reverse] == "true"
37
+ list_params.delete(:sort) if list_params[:sort] == @model_config.list.sort_by.to_s
38
+ end
39
+ end
40
+
41
+ def list_batch_url(page)
42
+ index_path(list_params.except(:page).merge(page:))
43
+ end
44
+
45
+ # From request.params, not list_params: a bulk confirmation receives the filter in the posted body.
46
+ def list_filter_hidden_fields
47
+ safe_join(URI.decode_www_form(request.params.slice("query", "f", "sort", "sort_reverse").to_query).map { |name, value| hidden_field_tag name, value, id: nil })
48
+ end
49
+
50
+ def scope_label(scope)
51
+ I18n.t("admin.scopes.#{@abstract_model.to_param}.#{scope}", default: I18n.t("admin.scopes.#{scope}", default: scope.to_s.titleize))
52
+ end
53
+
54
+ # What selects an all-matching bulk delete: the search query, each filter as field, operator
55
+ # and value, and the scope tab, or the whole model when nothing narrows the list.
56
+ def bulk_delete_filter_summary
57
+ items = []
58
+ items << t("admin.form.bulk_delete_query", query: params[:query]) if params[:query].present?
59
+ (filters_from_params || {}).each do |name, filters|
60
+ label = filterable_fields.find { it.name.to_s == name }.label
61
+ filters.each_value do |filter|
62
+ next if filter["disabled"].present? || filter["o"] == "_discard"
63
+
64
+ operator, values = filter["o"], Array(filter["v"]).compact_blank
65
+ # Boolean and enum filters post their operator token as the value, as the statement builder reads it.
66
+ operator, values = values.first, [] if operator.blank? && values.one? && FILTER_OPERATOR_LABELS.key?(values.first)
67
+ operator_label = operator.presence && operator != "default" && t("admin.js.#{FILTER_OPERATOR_LABELS.fetch(operator, operator)}", default: operator.humanize)
68
+ items << [label, operator_label, values.join(" – ")].compact_blank.join(" ")
69
+ end
70
+ end
71
+ # The scope the list applied, which is the first tab when the request names none.
72
+ items << t("admin.form.bulk_delete_scope", tab: scope_label(list_scope)) if list_scope
73
+ return tag.p(t("admin.form.bulk_delete_everything", model_label: @model_config.label)) if items.empty?
74
+
75
+ tag.p(t("admin.form.bulk_delete_matching", model_label_plural: @model_config.label_plural)) + tag.ul(safe_join(items.map { tag.li(it) }))
76
+ end
77
+
78
+ # Built from the request path rather than url_for, which reads routing options such as
79
+ # script_name out of a symbolized query hash.
80
+ def history_batch_url(page)
81
+ "#{request.path}?#{request.query_parameters.except("page").merge("page" => page).to_query}"
82
+ end
83
+
84
+ def list_properties
85
+ @_list_properties ||= @model_config.list.with(controller:, view: self, object: @abstract_model.model.new).fields_for_table
86
+ end
87
+
24
88
  def filterable_fields
25
89
  @filterable_fields ||= @model_config.list.fields.select(&:filterable?)
26
90
  end