Class: Eventsimple::EntitiesController

Inherits:
ApplicationController show all
Defined in:
app/controllers/eventsimple/entities_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#event_class_names, #event_classes

Instance Method Details

#showObject

rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'app/controllers/eventsimple/entities_controller.rb', line 4

def show
  @model_name = params[:model_name]
  @model_class = event_classes.find { |d| d.name == @model_name }
  @aggregate_id = params[:id]
  @event_id = params[:e] || -1
  @tab_id = (params[:t] == 'event') ? 'event' : 'entity'

  filter_columns = @model_class._filter_attributes
  params_filters = params.permit(filters: {})[:filters] || {}
  @filters = filter_columns.to_h { |column| [column, params_filters[column]] }

  primary_key = @model_class.event_class._aggregate_id
  @entity = @model_class.find_by!(primary_key => @aggregate_id)
  @entity_event_history = @entity.events.reverse

  @selected_event = @entity_event_history.find { |e|
    e.id == @event_id.to_i
  } || @entity_event_history.first

  previous_index = @entity_event_history.find_index { |e| e.id == @selected_event.id } + 1
  @previous_event = @entity_event_history[previous_index]

  @entity_changes = changes
rescue StandardError => e
  @error_message = e.message
  render html: '', layout: true
end