Class: WorkActivity::Renderer

Inherits:
Object
  • Object
show all
Defined in:
app/models/work_activity.rb

Direct Known Subclasses

BaseMessage, FileChanges, MetadataChanges, Migration

Constant Summary collapse

UNKNOWN_USER =
"Unknown user outside the system"
DATE_TIME_FORMAT =
"%B %d, %Y %H:%M"
DATE_FORMAT =
"%B %d, %Y"
SORTABLE_DATE_TIME_FORMAT =
"%Y-%m-%d %H:%M"

Instance Method Summary collapse

Constructor Details

#initialize(work_activity) ⇒ Renderer

Returns a new instance of Renderer.



116
117
118
# File 'app/models/work_activity.rb', line 116

def initialize(work_activity)
  @work_activity = work_activity
end

Instance Method Details

#created_by_user_htmlObject



129
130
131
132
133
# File 'app/models/work_activity.rb', line 129

def created_by_user_html
  return UNKNOWN_USER unless @work_activity.created_by_user

  "#{@work_activity.created_by_user.given_name_safe} (@#{@work_activity.created_by_user.uid})"
end

#created_sortable_htmlObject



135
136
137
# File 'app/models/work_activity.rb', line 135

def created_sortable_html
  @work_activity.created_at.time.strftime(SORTABLE_DATE_TIME_FORMAT)
end

#created_updated_htmlObject



139
140
141
142
143
144
145
146
147
148
149
# File 'app/models/work_activity.rb', line 139

def created_updated_html
  created = @work_activity.created_at.time.strftime(DATE_TIME_FORMAT)
  updated = @work_activity.updated_at.time.strftime(DATE_TIME_FORMAT)
  created_date = @work_activity.created_at.time.strftime(DATE_FORMAT)
  updated_date = @work_activity.updated_at.time.strftime(DATE_FORMAT)
  if created_date == updated_date
    created
  else
    "#{created} (backdated event created #{updated})"
  end
end

#title_htmlObject



151
152
153
# File 'app/models/work_activity.rb', line 151

def title_html
  "<span class='activity-history-title'>#{created_updated_html} by #{created_by_user_html}</span>"
end

#to_htmlObject



125
126
127
# File 'app/models/work_activity.rb', line 125

def to_html
  title_html + "<span class='message-html'>#{body_html.chomp}</span>"
end