2016-09-29 20:49:58 +08:00
|
|
|
class UserNotificationsController < ApplicationController
|
2016-10-04 17:51:47 +08:00
|
|
|
layout 'main'
|
2016-10-03 20:40:15 +08:00
|
|
|
|
|
|
|
def index
|
2016-10-04 17:51:47 +08:00
|
|
|
@last_notification_id = params[:from].to_i || 0
|
2016-10-13 16:00:36 +08:00
|
|
|
@per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT
|
2016-10-04 17:51:47 +08:00
|
|
|
|
|
|
|
@notifications =
|
|
|
|
UserNotification.last_notifications(@current_user,
|
|
|
|
@last_notification_id,
|
|
|
|
@per_page + 1)
|
|
|
|
|
2016-10-04 20:16:18 +08:00
|
|
|
@more_notifications_url = ''
|
2016-10-04 17:51:47 +08:00
|
|
|
|
|
|
|
@overflown = @notifications.length > @per_page
|
|
|
|
|
2016-10-04 20:16:18 +08:00
|
|
|
@notifications =
|
|
|
|
UserNotification.last_notifications(@current_user,
|
|
|
|
@last_notification_id,
|
|
|
|
@per_page)
|
2016-10-04 17:51:47 +08:00
|
|
|
|
|
|
|
if @notifications.count > 0
|
|
|
|
@more_notifications_url = url_for(
|
|
|
|
controller: 'user_notifications',
|
|
|
|
action: 'index',
|
|
|
|
format: :json,
|
2016-10-04 20:16:18 +08:00
|
|
|
from: @notifications.last.id
|
|
|
|
)
|
2016-10-04 17:51:47 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
2016-10-04 20:16:18 +08:00
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
per_page: @per_page,
|
|
|
|
results_number: @notifications.length,
|
|
|
|
more_notifications_url: @more_notifications_url,
|
|
|
|
html: render_to_string(partial: 'list.html.erb')
|
2016-10-04 17:51:47 +08:00
|
|
|
}
|
2016-10-04 20:16:18 +08:00
|
|
|
end
|
2016-10-04 17:51:47 +08:00
|
|
|
end
|
2016-10-05 17:27:43 +08:00
|
|
|
UserNotification.seen_by_user(current_user)
|
2016-10-03 20:40:15 +08:00
|
|
|
end
|
|
|
|
|
2016-09-28 22:03:52 +08:00
|
|
|
def recent_notifications
|
2016-09-29 20:49:58 +08:00
|
|
|
@recent_notifications = UserNotification.recent_notifications(current_user)
|
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
html: render_to_string(
|
|
|
|
partial: 'recent_notifications.html.erb'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-10-04 02:31:00 +08:00
|
|
|
UserNotification.seen_by_user(current_user)
|
2016-09-29 20:49:58 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def unseen_notification
|
2016-10-03 14:20:23 +08:00
|
|
|
@number = UserNotification.unseen_notification_count(current_user)
|
2016-09-29 20:49:58 +08:00
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.json do
|
|
|
|
render json: {
|
|
|
|
notificationNmber: @number
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
2016-09-28 22:03:52 +08:00
|
|
|
end
|
|
|
|
end
|