mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-27 02:04:33 +08:00
5f78d83f9c
* fix dropdown apperance * Remove search and fix duplicate bug * Fix specs for new method
71 lines
1.9 KiB
Ruby
71 lines
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class SystemNotificationsController < ApplicationController
|
|
before_action :prepare_notifications, only: :index
|
|
|
|
def index
|
|
respond_to do |format|
|
|
format.json do
|
|
render json: {
|
|
more_url: @system_notifications.fetch(:more_notifications_url),
|
|
html: render_to_string(
|
|
partial: 'list.html.erb', locals: @system_notifications
|
|
)
|
|
}
|
|
end
|
|
format.html
|
|
end
|
|
end
|
|
|
|
def show
|
|
render json: current_user.system_notifications.modals
|
|
.find_by_id(params[:id]) || {}
|
|
end
|
|
|
|
# Update seen_at parameter for system notifications
|
|
def mark_as_seen
|
|
current_user.user_system_notifications.mark_as_seen
|
|
render json: { result: 'ok' }
|
|
rescue StandardError
|
|
render json: { result: 'failed' }
|
|
end
|
|
|
|
# Update read_at parameter for system notifications
|
|
def mark_as_read
|
|
current_user.user_system_notifications.mark_as_read(params[:id])
|
|
render json: { result: 'ok' }
|
|
rescue StandardError
|
|
render json: { result: 'failed' }
|
|
end
|
|
|
|
def unseen_counter
|
|
render json: {
|
|
notificationNmber: current_user.user_system_notifications.unseen.count
|
|
}
|
|
end
|
|
|
|
private
|
|
|
|
def prepare_notifications
|
|
page = (params[:page] || 1).to_i
|
|
query = params[:search_queue]
|
|
per_page = Constants::ACTIVITY_AND_NOTIF_SEARCH_LIMIT
|
|
notifications = SystemNotification.last_notifications(current_user, query)
|
|
.page(page)
|
|
.per(per_page)
|
|
|
|
unless notifications.blank? || notifications.last_page?
|
|
more_url = url_for(
|
|
system_notifications_url(
|
|
format: :json,
|
|
page: page + 1,
|
|
search_queue: query
|
|
)
|
|
)
|
|
end
|
|
@system_notifications = {
|
|
notifications: notifications,
|
|
more_notifications_url: more_url
|
|
}
|
|
end
|
|
end
|