elaine_crud 0.1.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 (55) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +3 -0
  3. data/LICENSE +21 -0
  4. data/README.md +225 -0
  5. data/Rakefile +9 -0
  6. data/TODO.md +496 -0
  7. data/app/controllers/elaine_crud/base_controller.rb +228 -0
  8. data/app/helpers/elaine_crud/base_helper.rb +787 -0
  9. data/app/helpers/elaine_crud/search_helper.rb +132 -0
  10. data/app/javascript/controllers/dropdown_controller.js +18 -0
  11. data/app/views/elaine_crud/base/_edit_row.html.erb +60 -0
  12. data/app/views/elaine_crud/base/_export_button.html.erb +88 -0
  13. data/app/views/elaine_crud/base/_foreign_key_select_refresh.html.erb +52 -0
  14. data/app/views/elaine_crud/base/_form.html.erb +45 -0
  15. data/app/views/elaine_crud/base/_form_fields.html.erb +45 -0
  16. data/app/views/elaine_crud/base/_index_table.html.erb +58 -0
  17. data/app/views/elaine_crud/base/_modal.html.erb +71 -0
  18. data/app/views/elaine_crud/base/_pagination.html.erb +110 -0
  19. data/app/views/elaine_crud/base/_per_page_selector.html.erb +30 -0
  20. data/app/views/elaine_crud/base/_search_bar.html.erb +75 -0
  21. data/app/views/elaine_crud/base/_show_details.html.erb +29 -0
  22. data/app/views/elaine_crud/base/_view_row.html.erb +96 -0
  23. data/app/views/elaine_crud/base/edit.html.erb +51 -0
  24. data/app/views/elaine_crud/base/index.html.erb +74 -0
  25. data/app/views/elaine_crud/base/new.html.erb +12 -0
  26. data/app/views/elaine_crud/base/new_modal.html.erb +37 -0
  27. data/app/views/elaine_crud/base/not_found.html.erb +49 -0
  28. data/app/views/elaine_crud/base/show.html.erb +32 -0
  29. data/docs/ARCHITECTURE.md +410 -0
  30. data/docs/CSS_GRID_LAYOUT.md +126 -0
  31. data/docs/DEMO.md +693 -0
  32. data/docs/DSL_EXAMPLES.md +313 -0
  33. data/docs/FOREIGN_KEY_EXAMPLE.rb +100 -0
  34. data/docs/FOREIGN_KEY_SUPPORT.md +197 -0
  35. data/docs/HAS_MANY_IMPLEMENTATION.md +154 -0
  36. data/docs/LAYOUT_EXAMPLES.md +301 -0
  37. data/docs/TROUBLESHOOTING.md +170 -0
  38. data/elaine_crud.gemspec +46 -0
  39. data/lib/elaine_crud/dsl_methods.rb +348 -0
  40. data/lib/elaine_crud/engine.rb +37 -0
  41. data/lib/elaine_crud/export_handling.rb +164 -0
  42. data/lib/elaine_crud/field_configuration.rb +422 -0
  43. data/lib/elaine_crud/field_configuration_methods.rb +152 -0
  44. data/lib/elaine_crud/layout_calculation.rb +55 -0
  45. data/lib/elaine_crud/parameter_handling.rb +48 -0
  46. data/lib/elaine_crud/record_fetching.rb +150 -0
  47. data/lib/elaine_crud/relationship_handling.rb +220 -0
  48. data/lib/elaine_crud/routing.rb +33 -0
  49. data/lib/elaine_crud/search_and_filtering.rb +285 -0
  50. data/lib/elaine_crud/sorting_concern.rb +65 -0
  51. data/lib/elaine_crud/version.rb +5 -0
  52. data/lib/elaine_crud.rb +25 -0
  53. data/lib/tasks/demo.rake +111 -0
  54. data/lib/tasks/spec.rake +26 -0
  55. metadata +264 -0
data/TODO.md ADDED
@@ -0,0 +1,496 @@
1
+ # ElaineCrud TODO
2
+
3
+ This document tracks planned features and enhancements for ElaineCrud.
4
+
5
+ ## Current Status
6
+
7
+ ### โœ… Completed Features
8
+
9
+ 1. **Core CRUD Functionality**
10
+ - Basic CRUD actions (index, show, new, create, edit, update, destroy)
11
+ - Standard RESTful routing
12
+ - Strong parameters support
13
+ - TailwindCSS styling
14
+
15
+ 2. **Sorting**
16
+ - Clickable column headers
17
+ - Ascending/descending sort
18
+ - URL parameter persistence (`?sort=name&direction=asc`)
19
+ - Visual indicators (โ†‘โ†“) for sort direction
20
+
21
+ 3. **Pagination**
22
+ - Kaminari integration
23
+ - Per-page selection (10, 25, 50, 100)
24
+ - URL parameter support (`?page=2&per_page=25`)
25
+ - Page navigation with context preservation
26
+
27
+ 4. **Field Configuration DSL**
28
+ - `field` DSL for customizing field behavior
29
+ - Custom titles and descriptions
30
+ - `display_as` callbacks for custom rendering
31
+ - `edit_as` callbacks for custom form fields
32
+ - Dropdown options support
33
+ - Readonly fields
34
+ - Default values
35
+
36
+ 5. **Foreign Key Support (belongs_to)**
37
+ - Automatic detection via ActiveRecord reflections
38
+ - Auto-configured dropdowns in forms
39
+ - Smart display field detection
40
+ - Custom display callbacks
41
+ - Scoped options
42
+ - Null option placeholders
43
+ - N+1 query prevention with automatic includes
44
+
45
+ 6. **has_many Relationship Support**
46
+ - Automatic detection and configuration
47
+ - Display with counts and previews (e.g., "5 items: Item 1, Item 2...")
48
+ - Clickable links to filtered views (`/items?parent_id=4`)
49
+ - Parent context preservation in forms
50
+ - Readonly in edit forms
51
+ - N+1 query prevention
52
+ - Context-aware breadcrumbs
53
+ - Auto-population of parent relationship when creating from filtered view
54
+
55
+ 7. **has_one Relationship Support**
56
+ - Automatic detection and configuration
57
+ - Display related record's display field
58
+ - Shows "โ€”" placeholder for nil relationships
59
+ - Readonly in edit forms
60
+ - N+1 query prevention with automatic includes
61
+ - Smart display field selection
62
+
63
+ 8. **Turbo Frame Support**
64
+ - Inline editing without full page reload
65
+ - Edit and cancel actions via Turbo Frames
66
+ - Seamless UX with partial updates
67
+ - Fallback to full page navigation when disabled
68
+
69
+ 9. **CSS Grid Layout System**
70
+ - Responsive grid-based table layout
71
+ - Custom column width configuration
72
+ - `calculate_layout_header` override for custom sizing
73
+ - Handles varying content sizes gracefully
74
+
75
+ 10. **Integration Testing**
76
+ - RSpec integration tests for all major features
77
+ - Test coverage for CRUD operations
78
+ - Relationship testing
79
+ - Layout and UI testing
80
+
81
+ 11. **has_and_belongs_to_many (HABTM) Support**
82
+ - Minimal infrastructure approach for maximum flexibility
83
+ - Automatic detection via ActiveRecord reflections
84
+ - Minimal default display (comma-separated list)
85
+ - Checkbox form rendering with scrollable container
86
+ - Automatic parameter permitting for `*_ids` arrays
87
+ - N+1 query prevention with automatic includes
88
+ - Application-level customization via `display_as` callbacks
89
+ - Generic implementation (works for any HABTM: Students โ†” Courses, Users โ†” Roles, etc.)
90
+ - Fixed empty checkbox submission with hidden field pattern
91
+ - All variable naming is generic (no use-case specific hardcoding)
92
+
93
+ 12. **Search and Filtering**
94
+ - Global text search across searchable columns
95
+ - Per-column filtering (dropdown filters, date ranges)
96
+ - URL parameter support (`?q=search`, `?filter[status]=active`)
97
+ - Clear filters functionality
98
+ - Search persistence across pagination and sorting
99
+ - Configurable via DSL (`searchable: true/false`, `filterable: true/false`)
100
+ - Smart filtering for belongs_to relationships (dropdown of related records)
101
+ - Search result count display
102
+ - Empty state handling with "Clear search" action
103
+ - Works seamlessly with existing sorting and pagination
104
+
105
+ 13. **Validation Error Display**
106
+ - Inline field-level error messages in forms
107
+ - Red border highlighting for invalid fields
108
+ - Form data preservation on validation failure
109
+ - Error display in inline edit mode (Turbo Frames)
110
+ - Proper error handling for create/update actions
111
+ - Validation errors shown with proper styling
112
+
113
+ 14. **Custom View Partials for Extensibility**
114
+ - `_index_table.html.erb` - Reusable table component
115
+ - `_show_details.html.erb` - Reusable detail display component
116
+ - Support for `show_actions: false` parameter to hide action buttons
117
+ - Demonstrates ElaineCrud's composability for custom views
118
+ - Example implementation in test app (libraries show page with computed stats and sub-tables)
119
+
120
+ 15. **Row-level Turbo Frame Architecture**
121
+ - Simplified from column-level to row-level frames
122
+ - More efficient DOM updates
123
+ - Better code organization
124
+ - Turbo Frame wraps entire row with `class="contents"` for CSS Grid compatibility
125
+
126
+ 16. **Delete Functionality Improvements**
127
+ - Changed from `link_to` to `button_to` for proper DELETE requests
128
+ - JavaScript confirmation dialogs (`onsubmit="return confirm(...)"`)
129
+ - Form-based deletion with `data: { turbo: false }` to force full page reload
130
+ - HTTP 303 See Other redirects after POST/PATCH/DELETE to prevent method preservation
131
+ - No "Content missing" errors on successful deletion
132
+
133
+ 17. **Custom 404 Error Pages**
134
+ - Beautiful, branded 404 page for missing records
135
+ - Shows model name, resource ID, and helpful context
136
+ - Action buttons: "View All [Models]", "Create New [Model]", "Go Back"
137
+ - Consistent with ElaineCrud's design language (top-left layout, not centered)
138
+ - Proper HTTP 404 status code
139
+ - JSON response support for API requests
140
+
141
+ 18. **Code Quality Improvements**
142
+ - Removed legacy inline editing mode (dead code)
143
+ - Simplified index view by using reusable `_index_table` partial
144
+ - Fixed array mutation bug in `calculate_layout_header`
145
+ - Comprehensive test coverage (82 examples, 0 failures)
146
+
147
+ ---
148
+
149
+ ## ๐Ÿšง Planned Features
150
+
151
+ ### High Priority
152
+
153
+ ---
154
+
155
+ ### Medium Priority
156
+
157
+ #### 1. Bulk Actions
158
+ **Description**: Enable operations on multiple records at once
159
+
160
+ **Features**:
161
+ - Checkbox selection for records
162
+ - "Select All" / "Select None" options
163
+ - Bulk delete with confirmation
164
+ - Bulk status/field updates
165
+ - Custom bulk actions via DSL
166
+ - Progress feedback for long operations
167
+
168
+ **Benefits**:
169
+ - Common admin interface pattern
170
+ - Efficiency for managing many records
171
+ - Reduces repetitive actions
172
+
173
+ **Implementation Notes**:
174
+ - Add checkboxes to index view
175
+ - JavaScript for selection handling
176
+ - Bulk action dropdown/buttons
177
+ - Confirmation dialogs
178
+ - Consider using Turbo Streams for updates
179
+
180
+ ---
181
+
182
+ #### 2. Advanced Column Configuration
183
+ **Description**: Enhance column display and customization options
184
+
185
+ **Features**:
186
+ - Column visibility toggles (show/hide)
187
+ - Column reordering (drag & drop or preferences)
188
+ - Sticky columns for horizontal scrolling
189
+ - Column grouping/categories
190
+ - Per-user column preferences (requires user model)
191
+ - Export column configuration
192
+
193
+ **Benefits**:
194
+ - Handle tables with many columns
195
+ - Customizable views for different users/roles
196
+ - Better UX for wide tables
197
+
198
+ ---
199
+
200
+ ### Low Priority
201
+
202
+ #### 3. Export Functionality
203
+ **Description**: Export records to various formats
204
+
205
+ **Features**:
206
+ - Export to CSV, JSON, Excel (XLSX)
207
+ - Respects current filters, search, and sorting
208
+ - Configurable column selection for export
209
+ - Background job support for large exports
210
+ - Email delivery for large files
211
+
212
+ **Benefits**:
213
+ - Data portability
214
+ - Reporting and analysis
215
+ - Integration with external tools
216
+
217
+ **Implementation Notes**:
218
+ - CSV: Built-in Ruby CSV library
219
+ - Excel: Use `caxlsx` or `spreadsheet` gem
220
+ - JSON: Built-in Rails support
221
+ - Consider streaming for large datasets
222
+ - Add export buttons to index view
223
+
224
+ ---
225
+
226
+ #### 4. Import Functionality
227
+ **Description**: Bulk import records from files
228
+
229
+ **Features**:
230
+ - CSV/Excel file upload
231
+ - Column mapping interface
232
+ - Validation and error reporting
233
+ - Preview before import
234
+ - Progress tracking
235
+ - Rollback on errors (transaction support)
236
+
237
+ **Benefits**:
238
+ - Bulk data loading
239
+ - Migration from other systems
240
+ - Seed data management
241
+
242
+ ---
243
+
244
+ #### 5. Polymorphic Association Support
245
+ **Description**: Support for polymorphic relationships
246
+
247
+ **Features**:
248
+ - Detect polymorphic belongs_to relationships
249
+ - Type + ID field handling in forms
250
+ - Display polymorphic associations correctly
251
+ - Filter by polymorphic type
252
+
253
+ **Benefits**:
254
+ - Flexible data models (comments, attachments, etc.)
255
+ - Completes association support
256
+ - Common Rails pattern
257
+
258
+ **Complexity**: High - requires special UI handling
259
+
260
+ ---
261
+
262
+ #### 6. Nested Forms for has_many
263
+ **Description**: Edit child records inline when editing parent
264
+
265
+ **Features**:
266
+ - Add/remove child records in parent form
267
+ - Inline editing of child attributes
268
+ - Nested validation handling
269
+ - Dynamic field addition with JavaScript
270
+ - Support for accepts_nested_attributes_for
271
+
272
+ **Benefits**:
273
+ - Edit related records without navigation
274
+ - Better UX for tightly coupled data
275
+ - Common pattern (e.g., invoice with line items)
276
+
277
+ **Complexity**: High - requires significant form logic
278
+
279
+ ---
280
+
281
+ #### 7. Action Permissions/Authorization
282
+ **Description**: Integrate with authorization frameworks
283
+
284
+ **Features**:
285
+ - Conditional action visibility (hide Edit if not authorized)
286
+ - Integration with Pundit, CanCanCan, or similar
287
+ - Per-action authorization checks
288
+ - Graceful handling of unauthorized access
289
+ - Role-based action visibility
290
+
291
+ **Benefits**:
292
+ - Security enforcement
293
+ - Production-ready admin interfaces
294
+ - Multi-user/role support
295
+
296
+ ---
297
+
298
+ #### 8. Audit Trail/Activity Log
299
+ **Description**: Track changes to records
300
+
301
+ **Features**:
302
+ - Automatic change logging
303
+ - "Who changed what and when" tracking
304
+ - Integration with PaperTrail or Audited gems
305
+ - View change history in UI
306
+ - Diff view for changes
307
+ - Restore previous versions
308
+
309
+ **Benefits**:
310
+ - Compliance and accountability
311
+ - Debugging data issues
312
+ - Undo functionality
313
+
314
+ ---
315
+
316
+ #### 9. Custom Actions
317
+ **Description**: Add custom actions beyond CRUD
318
+
319
+ **Features**:
320
+ - Define custom member actions (e.g., "publish", "archive")
321
+ - Define custom collection actions (e.g., "import", "export")
322
+ - Automatic route generation
323
+ - Button rendering in UI
324
+ - Confirmation dialogs
325
+ - Custom action forms/modals
326
+
327
+ **Benefits**:
328
+ - Extend beyond basic CRUD
329
+ - Domain-specific operations
330
+ - Flexible admin interfaces
331
+
332
+ **Example**:
333
+ ```ruby
334
+ class PostsController < ElaineCrud::BaseController
335
+ model Post
336
+
337
+ custom_action :publish,
338
+ on: :member,
339
+ method: :post,
340
+ confirm: "Are you sure you want to publish this post?"
341
+
342
+ def publish
343
+ @record.update(published: true)
344
+ redirect_to posts_path, notice: "Post published"
345
+ end
346
+ end
347
+ ```
348
+
349
+ ---
350
+
351
+ #### 10. Dashboard/Stats Views
352
+ **Description**: Summary views with statistics and charts
353
+
354
+ **Features**:
355
+ - Configurable dashboard with widgets
356
+ - Count aggregations (total records, by status, etc.)
357
+ - Charts and graphs (using Chart.js or similar)
358
+ - Date range filtering
359
+ - Export stats
360
+
361
+ **Benefits**:
362
+ - Overview of data at a glance
363
+ - Business intelligence
364
+ - Common admin interface pattern
365
+
366
+ ---
367
+
368
+ #### 11. Dark Mode Support
369
+ **Description**: Toggle between light and dark themes
370
+
371
+ **Features**:
372
+ - Dark mode CSS theme
373
+ - User preference persistence
374
+ - Toggle button in UI
375
+ - Respects system preferences
376
+ - All views compatible with dark mode
377
+
378
+ **Benefits**:
379
+ - Modern UI feature
380
+ - Accessibility and comfort
381
+ - User preference support
382
+
383
+ ---
384
+
385
+ #### 12. Mobile Responsive Improvements
386
+ **Description**: Enhance mobile experience
387
+
388
+ **Features**:
389
+ - Card-based mobile layout (instead of table)
390
+ - Touch-friendly buttons and interactions
391
+ - Mobile-optimized forms
392
+ - Responsive navigation
393
+ - Swipe gestures
394
+
395
+ **Benefits**:
396
+ - Better mobile experience
397
+ - Accessibility
398
+ - Modern web standards
399
+
400
+ ---
401
+
402
+ ## ๐Ÿ“ Documentation Improvements
403
+
404
+ - [ ] Add comprehensive API documentation
405
+ - [ ] Create video tutorials
406
+ - [ ] Add more real-world examples
407
+ - [ ] Document testing strategies
408
+ - [ ] Create migration guide from other admin gems
409
+ - [ ] Add performance tuning guide
410
+ - [ ] Document accessibility features
411
+
412
+ ---
413
+
414
+ ## ๐Ÿงช Testing Improvements
415
+
416
+ - [ ] Increase test coverage to 95%+
417
+ - [ ] Add performance benchmarks
418
+ - [ ] Browser compatibility testing
419
+ - [ ] Accessibility testing (WCAG compliance)
420
+ - [ ] Load testing for large datasets
421
+ - [ ] Security testing
422
+
423
+ ---
424
+
425
+ ## ๐Ÿ”ง Technical Debt
426
+
427
+ - [ ] Refactor BaseHelper (getting large)
428
+ - [ ] Extract layout calculation to separate concern
429
+ - [ ] Improve error handling throughout
430
+ - [ ] Add deprecation warnings for future breaking changes
431
+ - [ ] Review and optimize database queries
432
+ - [ ] Add instrumentation/logging for debugging
433
+
434
+ ---
435
+
436
+ ## ๐Ÿ’ก Ideas for Future Exploration
437
+
438
+ - GraphQL API support
439
+ - WebSocket support for real-time updates
440
+ - Multi-tenancy support
441
+ - Internationalization (i18n)
442
+ - API documentation generation (OpenAPI/Swagger)
443
+ - Form builder/designer UI
444
+ - Workflow/state machine support
445
+ - Scheduled actions (cron-like)
446
+ - Notification system integration
447
+ - File upload support with ActiveStorage
448
+ - Rich text editor integration (ActionText/Trix)
449
+ - Map/location field support
450
+ - Calendar/scheduling views
451
+
452
+ ---
453
+
454
+ ## Priority Matrix
455
+
456
+ **Do First** (High Impact, Low Effort):
457
+ 1. ~~Search/Filtering~~ โœ… **COMPLETED**
458
+ 2. ~~Validation Error Display~~ โœ… **COMPLETED**
459
+
460
+ **Schedule** (High Impact, High Effort):
461
+ 1. Bulk Actions
462
+ 2. Advanced Column Configuration
463
+
464
+ **Consider** (Low Impact, Low Effort):
465
+ 1. Export Functionality
466
+ 2. Dark Mode Support
467
+
468
+ **Defer** (Low Impact, High Effort):
469
+ 1. Nested Forms
470
+ 2. Audit Trail
471
+ 3. Dashboard Views
472
+
473
+ ---
474
+
475
+ ## Contributing
476
+
477
+ Interested in implementing any of these features?
478
+
479
+ 1. Pick a feature from the list
480
+ 2. Create an issue to discuss the approach
481
+ 3. Fork the repository
482
+ 4. Implement the feature with tests
483
+ 5. Update documentation
484
+ 6. Submit a pull request
485
+
486
+ See [ARCHITECTURE.md](docs/ARCHITECTURE.md) for technical details.
487
+
488
+ ---
489
+
490
+ ## Questions?
491
+
492
+ - What features would be most valuable to your use case?
493
+ - What's missing from this list?
494
+ - What should be prioritized differently?
495
+
496
+ Open an issue to discuss!