Class: PandaCms::Admin::UserActivityComponent

Inherits:
ViewComponent::Base
  • Object
show all
Defined in:
app/components/panda_cms/admin/user_activity_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(whodunnit_to: nil, at: nil, user: nil) ⇒ UserActivityComponent

Returns a new instance of UserActivityComponent.

Parameters:

  • whodunnit_to (ActiveRecord::Base) (defaults to: nil)

    Model instance to which the user activity is related



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/panda_cms/admin/user_activity_component.rb', line 11

def initialize(whodunnit_to: nil, at: nil, user: nil)
  if whodunnit_to
    @model = whodunnit_to
    whodunnit_id = @model.versions&.last&.whodunnit
    if whodunnit_id
      @user = User.find(whodunnit_id)
      @time = @model.updated_at
    end
  elsif user.is_a?(::PandaCms::User) && at.is_a?(::ActiveSupport::TimeWithZone)
    @user = user
    @time = at
  end

  if !@time
    @user = nil
    @time = nil
  end
end

Instance Attribute Details

#modelObject

Returns the value of attribute model.



6
7
8
# File 'app/components/panda_cms/admin/user_activity_component.rb', line 6

def model
  @model
end

#timeObject

Returns the value of attribute time.



7
8
9
# File 'app/components/panda_cms/admin/user_activity_component.rb', line 7

def time
  @time
end

#userObject

Returns the value of attribute user.



8
9
10
# File 'app/components/panda_cms/admin/user_activity_component.rb', line 8

def user
  @user
end