2014-02-01 00:26:58 +00:00
|
|
|
class UserPagePresenter
|
2014-02-01 00:16:28 +00:00
|
|
|
|
|
|
|
PER_PAGE = 15
|
|
|
|
|
2014-07-05 12:59:42 +00:00
|
|
|
attr_reader :user, :current_user, :policy, :page, :per_page
|
2014-02-01 00:16:28 +00:00
|
|
|
|
|
|
|
def self.build(user, current_user, page = nil, per_page = nil)
|
2014-07-05 12:59:42 +00:00
|
|
|
policy = Pundit.policy(current_user, user)
|
|
|
|
new(user.decorate, current_user, policy, page || 1, per_page || PER_PAGE)
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
2014-07-05 12:59:42 +00:00
|
|
|
def initialize(user, current_user, policy, page, per_page)
|
2014-02-01 00:16:28 +00:00
|
|
|
@user = user
|
|
|
|
@current_user = current_user
|
2014-07-05 12:59:42 +00:00
|
|
|
@policy = policy
|
2014-02-01 00:16:28 +00:00
|
|
|
@page = page
|
|
|
|
@per_page = per_page
|
|
|
|
end
|
|
|
|
|
|
|
|
def title
|
2014-10-17 12:11:43 +00:00
|
|
|
"#{user.display_name}'s profile".html_safe
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def user_full_name
|
|
|
|
user.full_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_joined_at
|
|
|
|
user.joined_at
|
|
|
|
end
|
|
|
|
|
|
|
|
def user_avatar_image_tag
|
|
|
|
user.avatar_image_tag
|
|
|
|
end
|
|
|
|
|
|
|
|
def show_settings?
|
2014-07-05 12:59:42 +00:00
|
|
|
policy.update?
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def asciicast_count_text(h)
|
2014-10-17 12:11:43 +00:00
|
|
|
if current_users_profile?
|
2015-04-26 13:30:42 +00:00
|
|
|
count = user.asciicast_count
|
|
|
|
if count > 0
|
|
|
|
count = h.pluralize(count, 'asciicast')
|
2014-10-17 12:11:43 +00:00
|
|
|
"You have recorded #{count}"
|
|
|
|
else
|
2014-10-17 15:28:22 +00:00
|
|
|
"Record your first asciicast"
|
2014-10-17 12:11:43 +00:00
|
|
|
end
|
|
|
|
else
|
2015-04-26 13:30:42 +00:00
|
|
|
count = user.public_asciicast_count
|
|
|
|
if count > 0
|
2015-05-10 19:15:43 +00:00
|
|
|
count = h.pluralize(count, 'public asciicast')
|
2014-10-17 12:11:43 +00:00
|
|
|
"#{count} by #{user.display_name}"
|
|
|
|
else
|
2015-05-11 13:43:03 +00:00
|
|
|
"#{user.display_name} has no public asciicasts"
|
2014-10-17 12:11:43 +00:00
|
|
|
end
|
|
|
|
end
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
2014-02-12 19:51:01 +00:00
|
|
|
def user_username
|
|
|
|
user.username
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def asciicasts
|
|
|
|
@asciicasts ||= get_asciicasts
|
|
|
|
end
|
|
|
|
|
|
|
|
def current_users_profile?
|
|
|
|
current_user && current_user == user
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def get_asciicasts
|
2015-04-26 13:30:42 +00:00
|
|
|
asciicasts = user.paged_asciicasts(page, per_page, current_users_profile?)
|
|
|
|
PaginatingDecorator.new(asciicasts)
|
2014-02-01 00:16:28 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|