Mailboxer notification pagination

This commit is contained in:
Devin Howard 2016-12-11 17:29:48 -05:00
parent 88e98c7342
commit 0960159265
9 changed files with 28 additions and 18 deletions

View file

@ -38,7 +38,9 @@ class AccessController < ApplicationController
# who we then send an email to
user = User.find(user_id)
mail = MapMailer.invite_to_edit_email(@map, current_user, user)
user.notify(mail.subject, 'invite to edit', UserMap.find_by(user: user, map: @map), true, MAILBOXER_CODE_INVITED_TO_EDIT)
user.notify(mail.subject, 'invite to edit',
UserMap.find_by(user: user, map: @map),
true, MAILBOXER_CODE_INVITED_TO_EDIT)
end
@map.remove_old_collaborators(user_ids)

View file

@ -5,7 +5,7 @@ class NotificationsController < ApplicationController
before_action :set_receipt, only: [:show, :mark_read, :mark_unread]
def index
@notifications = current_user.mailbox.notifications
@notifications = current_user.mailbox.notifications.page(params[:page]).per(25)
respond_to do |format|
format.html

View file

@ -95,6 +95,8 @@ class UsersController < ApplicationController
private
def user_params
params.require(:user).permit(:name, :email, :image, :password, :password_confirmation, :emails_allowed)
params.require(:user).permit(
:name, :email, :image, :password, :password_confirmation, :emails_allowed
)
end
end

View file

@ -40,7 +40,7 @@ module ApplicationHelper
def user_unread_notification_count
return 0 if current_user.nil?
@user_unread_notification_count ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
@uunc ||= current_user.mailboxer_notification_receipts.reduce(0) do |total, receipt|
receipt.is_read ? total : total + 1
end
end

View file

@ -7,10 +7,10 @@ class AccessRequest < ApplicationRecord
self.answered = true
self.save
Mailboxer::Notification.where(notified_object: self).each do |notification|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
user_map = UserMap.create(user: user, map: map)
mail = MapMailer.invite_to_edit_email(map, map.user, user)
user.notify(mail.subject, 'invite to edit', user_map, true, MAILBOXER_CODE_INVITED_TO_EDIT)
@ -21,7 +21,7 @@ class AccessRequest < ApplicationRecord
self.answered = true
self.save
Mailboxer::Notification.where(notified_object: self).each do |notification|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
end

View file

@ -4,7 +4,7 @@ class UserMap < ApplicationRecord
belongs_to :user
def mark_invite_notifications_as_read
Mailboxer::Notification.where(notified_object: self).each do |notification|
Mailboxer::Notification.where(notified_object: self).find_each do |notification|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
end
end

View file

@ -30,6 +30,13 @@
<% end %>
</ul>
</div>
<% if @notifications.total_pages > 1 %>
<div class="centerContent pagination">
<%= paginate @notifications %>
</div>
<% end %>
<%= render partial: 'shared/back_to_mapping' %>
</div>

View file

@ -8,7 +8,7 @@ import NotificationIconComponent from '../../components/NotificationIcon'
const NotificationIcon = {
unreadNotificationsCount: null,
init: function(serverData) {
const self = NotificationIcon
self.unreadNotificationsCount = serverData.unreadNotificationsCount
@ -18,7 +18,7 @@ const NotificationIcon = {
if (newUnreadCount !== null) {
NotificationIcon.unreadNotificationsCount = newUnreadCount
}
if (Active.Mapper !== null) {
ReactDOM.render(React.createElement(NotificationIconComponent, {
unreadNotificationsCount: NotificationIcon.unreadNotificationsCount
@ -27,4 +27,4 @@ const NotificationIcon = {
}
}
export default NotificationIcon
export default NotificationIcon

View file

@ -9,14 +9,14 @@ class NotificationIcon extends Component {
}
render = () => {
var linkClasses = "notificationsIcon upperRightEl upperRightIcon "
let linkClasses = 'notificationsIcon upperRightEl upperRightIcon '
if (this.props.unreadNotificationsCount > 0) {
linkClasses += "unread"
linkClasses += 'unread'
} else {
linkClasses += "read"
linkClasses += 'read'
}
return (
<a className={linkClasses} href="/notifications">
<div className="tooltipsUnder">
@ -26,8 +26,7 @@ class NotificationIcon extends Component {
<div className="unread-notifications-dot"></div>
)}
</a>
)
}
}