Class: Fosm::Admin::AppsController

Inherits:
BaseController show all
Defined in:
app/controllers/fosm/admin/apps_controller.rb

Instance Method Summary collapse

Methods inherited from Fosm::ApplicationController

use_host_routes!

Instance Method Details

#indexObject



4
5
6
# File 'app/controllers/fosm/admin/apps_controller.rb', line 4

def index
  redirect_to fosm.admin_root_path
end

#showObject



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'app/controllers/fosm/admin/apps_controller.rb', line 8

def show
  @slug = params[:slug]
  @model_class = Fosm::Registry.find(@slug)
  return render plain: "FOSM app '#{@slug}' not found", status: :not_found unless @model_class

  @lifecycle = @model_class.fosm_lifecycle
  @diagram_data = @lifecycle.to_diagram_data

  @state_counts = @lifecycle.state_names.index_with { |s| @model_class.where(state: s).count }
  @recent_transitions = Fosm::TransitionLog.for_app(@model_class).recent.limit(20)
  @total = @model_class.count

  # Stuck records: in a non-terminal state, no transition in 7 days
  non_terminal_states = @lifecycle.states.reject(&:terminal?).map { |s| s.name.to_s }
  # Load record_ids as array and cast to match the model's PK type (record_id
  # is stored as varchar in transition_logs but the model PK may be bigint).
  pk_type = @model_class.columns_hash[@model_class.primary_key]&.&.type
  stuck_ids = Fosm::TransitionLog.for_app(@model_class)
                                  .where("created_at < ?", 7.days.ago)
                                  .distinct
                                  .pluck(:record_id)
  stuck_ids = stuck_ids.map(&:to_i) if pk_type == :integer
  @stuck_count = @model_class.where(state: non_terminal_states).where.not(id: stuck_ids).count
end