Module: Studio::Board::Reorderable

Extended by:
ActiveSupport::Concern
Defined in:
app/controllers/concerns/studio/board/reorderable.rb

Overview

Shared reorder action for board controllers. The three McRitchie Studio kanban controllers (tasks / news / content) each carried a BYTE-IDENTICAL reorder — guard the incoming id array, restamp the column with 100-gaps INSIDE rescue_and_log (so a failure lands in ErrorLog — backend write discipline), render { success: true }, and rescue to a 422. This concern is that action, neutral: the including controller declares its model, id column, and the incoming param, and the ranking rule itself is delegated to the model's Studio::Board::Rankable#reposition! (one place owns the 100-gap math). This is THE designated shared write action, so it owns the ErrorLog logging here rather than leaving each host to re-add it.

class TasksController < ApplicationController
include Studio::Board::Reorderable
board_reorderable model: Task, id_attr: :slug, param: :slugs
end

# Route it however the app names the endpoint:
post "tasks/reorder", to: "tasks#reorder"

The POST body the studio/board factory sends is { <param>: [...ids], zone: "<zone-key>" }; this action reads only <param> (the ordered id list) and ignores the advisory zone, so a kanban and a depth-chart board share it.

Instance Method Summary collapse

Instance Method Details

#reorderObject

POST — restamp a column from its DOM-ordered id list. Neutral param (slugs or ids), 100-gap, DESC by default. Mirrors the MS hand-rolled reorder exactly, INCLUDING its ErrorLog logging: the restamp runs inside rescue_and_log(target: nil) (Studio::ErrorHandling), which captures a failure to ErrorLog and RE-RAISES to the outer 422 net below — the "every write path logs" discipline, owned here since this is the one shared write action. respond_to? guards it so a host whose ApplicationController somehow lacks the concern still degrades to a bare restamp + 422 (no NoMethodError).



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'app/controllers/concerns/studio/board/reorderable.rb', line 57

def reorder
  model = self.class.board_reorder_model
  raise "board_reorderable model not configured" unless model

  param = self.class.board_reorder_param
  ids = params[param]
  return render(json: { error: "#{param} required" }, status: :unprocessable_entity) unless ids.is_a?(Array)

  if respond_to?(:rescue_and_log)
    rescue_and_log(target: nil) { board_reorder_apply(model, ids) }
  else
    board_reorder_apply(model, ids)
  end
  render json: { success: true }
rescue StandardError => e
  render json: { error: e.message }, status: :unprocessable_entity
end