Class: StimulusGridRails::HistoryController

Inherits:
BaseController show all
Defined in:
app/controllers/stimulus_grid_rails/history_controller.rb

Overview

Undo / redo — RAILS.md §16.

POST /grids/:resource/undo   → revert the user's last mutation
POST /grids/:resource/redo   → re-apply the last undone mutation

Each replays the prior/new value through grid.apply_cell!, so it goes through the same save → validation → cascade → auto-broadcast path as a normal edit. Scoped per current_user + resource. Audits whose row has since been deleted are skipped (and marked) rather than failing the request.

Constant Summary collapse

SCAN_LIMIT =
50

Instance Method Summary collapse

Instance Method Details

#redo_changeObject

‘redo` is a Ruby keyword, so the action is named redo_change.



22
23
24
25
# File 'app/controllers/stimulus_grid_rails/history_controller.rb', line 22

def redo_change
  step(Audit.redoable(params[:resource], current_grid_user&.id),
       value: :new_value, undone: false)
end

#undoObject



16
17
18
19
# File 'app/controllers/stimulus_grid_rails/history_controller.rb', line 16

def undo
  step(Audit.undoable(params[:resource], current_grid_user&.id),
       value: :prior_value, undone: true)
end