scinote-web/app/controllers/user_notifications_controller.rb

72 lines
1.8 KiB
Ruby
Raw Normal View History

2016-09-29 20:49:58 +08:00
class UserNotificationsController < ApplicationController
layout 'main'
2016-10-03 20:40:15 +08:00
def index
@last_notification_id = params[:from].to_i || 0
@per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT
@notifications =
UserNotification.last_notifications(@current_user,
@last_notification_id,
@per_page + 1)
@more_notifications_url = ''
@overflown = @notifications.length > @per_page
@notifications =
UserNotification.last_notifications(@current_user,
@last_notification_id,
@per_page)
if @notifications.count > 0
@more_notifications_url = url_for(
controller: 'user_notifications',
action: 'index',
format: :json,
from: @notifications.last.id
)
end
respond_to do |format|
format.html
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')
}
end
end
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
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