2016-02-12 23:52:43 +08:00
|
|
|
class ActivitiesController < ApplicationController
|
2017-01-12 21:47:15 +08:00
|
|
|
include ActivityHelper
|
|
|
|
|
2016-02-12 23:52:43 +08:00
|
|
|
def index
|
|
|
|
respond_to do |format|
|
2018-01-03 20:48:59 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
more_url: local_vars.fetch(:more_activities_url),
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'index.html.erb', locals: local_vars
|
|
|
|
)
|
2016-02-12 23:52:43 +08:00
|
|
|
}
|
2018-01-03 20:48:59 +08:00
|
|
|
end
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-01-03 20:48:59 +08:00
|
|
|
private
|
|
|
|
|
|
|
|
def local_vars
|
|
|
|
page = (params[:page] || 1).to_i
|
|
|
|
activities = current_user.last_activities
|
|
|
|
.page(page)
|
|
|
|
.per(Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT)
|
|
|
|
unless activities.last_page?
|
|
|
|
more_url = url_for(activities_url(format: :json, page: page + 1))
|
|
|
|
end
|
|
|
|
{
|
|
|
|
activities: activities,
|
|
|
|
more_activities_url: more_url,
|
|
|
|
page: page
|
|
|
|
}
|
2016-02-12 23:52:43 +08:00
|
|
|
end
|
|
|
|
end
|