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.



142
143
144
# File 'app/models/work_activity.rb', line 142

def initialize(work_activity)
  @work_activity = work_activity
end

Instance Method Details

#created_by_user_htmlObject



155
156
157
158
159
# File 'app/models/work_activity.rb', line 155

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



161
162
163
# File 'app/models/work_activity.rb', line 161

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

#created_updated_htmlObject



165
166
167
168
169
170
171
172
173
174
175
# File 'app/models/work_activity.rb', line 165

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



177
178
179
# File 'app/models/work_activity.rb', line 177

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

#to_htmlObject



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

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