Mailboxer notification pagination
This commit is contained in:
parent
88e98c7342
commit
0960159265
9 changed files with 28 additions and 18 deletions
|
@ -38,7 +38,9 @@ class AccessController < ApplicationController
|
||||||
# who we then send an email to
|
# who we then send an email to
|
||||||
user = User.find(user_id)
|
user = User.find(user_id)
|
||||||
mail = MapMailer.invite_to_edit_email(@map, current_user, user)
|
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
|
end
|
||||||
@map.remove_old_collaborators(user_ids)
|
@map.remove_old_collaborators(user_ids)
|
||||||
|
|
||||||
|
|
|
@ -5,7 +5,7 @@ class NotificationsController < ApplicationController
|
||||||
before_action :set_receipt, only: [:show, :mark_read, :mark_unread]
|
before_action :set_receipt, only: [:show, :mark_read, :mark_unread]
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@notifications = current_user.mailbox.notifications
|
@notifications = current_user.mailbox.notifications.page(params[:page]).per(25)
|
||||||
|
|
||||||
respond_to do |format|
|
respond_to do |format|
|
||||||
format.html
|
format.html
|
||||||
|
|
|
@ -95,6 +95,8 @@ class UsersController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def user_params
|
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
|
||||||
end
|
end
|
||||||
|
|
|
@ -40,7 +40,7 @@ module ApplicationHelper
|
||||||
|
|
||||||
def user_unread_notification_count
|
def user_unread_notification_count
|
||||||
return 0 if current_user.nil?
|
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
|
receipt.is_read ? total : total + 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,10 +7,10 @@ class AccessRequest < ApplicationRecord
|
||||||
self.answered = true
|
self.answered = true
|
||||||
self.save
|
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)
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
||||||
end
|
end
|
||||||
|
|
||||||
user_map = UserMap.create(user: user, map: map)
|
user_map = UserMap.create(user: user, map: map)
|
||||||
mail = MapMailer.invite_to_edit_email(map, map.user, user)
|
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)
|
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.answered = true
|
||||||
self.save
|
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)
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,7 +4,7 @@ class UserMap < ApplicationRecord
|
||||||
belongs_to :user
|
belongs_to :user
|
||||||
|
|
||||||
def mark_invite_notifications_as_read
|
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)
|
Mailboxer::Receipt.where(notification: notification).update_all(is_read: true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -30,6 +30,13 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<% if @notifications.total_pages > 1 %>
|
||||||
|
<div class="centerContent pagination">
|
||||||
|
<%= paginate @notifications %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
|
||||||
<%= render partial: 'shared/back_to_mapping' %>
|
<%= render partial: 'shared/back_to_mapping' %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ import NotificationIconComponent from '../../components/NotificationIcon'
|
||||||
|
|
||||||
const NotificationIcon = {
|
const NotificationIcon = {
|
||||||
unreadNotificationsCount: null,
|
unreadNotificationsCount: null,
|
||||||
|
|
||||||
init: function(serverData) {
|
init: function(serverData) {
|
||||||
const self = NotificationIcon
|
const self = NotificationIcon
|
||||||
self.unreadNotificationsCount = serverData.unreadNotificationsCount
|
self.unreadNotificationsCount = serverData.unreadNotificationsCount
|
||||||
|
@ -18,7 +18,7 @@ const NotificationIcon = {
|
||||||
if (newUnreadCount !== null) {
|
if (newUnreadCount !== null) {
|
||||||
NotificationIcon.unreadNotificationsCount = newUnreadCount
|
NotificationIcon.unreadNotificationsCount = newUnreadCount
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Active.Mapper !== null) {
|
if (Active.Mapper !== null) {
|
||||||
ReactDOM.render(React.createElement(NotificationIconComponent, {
|
ReactDOM.render(React.createElement(NotificationIconComponent, {
|
||||||
unreadNotificationsCount: NotificationIcon.unreadNotificationsCount
|
unreadNotificationsCount: NotificationIcon.unreadNotificationsCount
|
||||||
|
@ -27,4 +27,4 @@ const NotificationIcon = {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default NotificationIcon
|
export default NotificationIcon
|
||||||
|
|
|
@ -9,14 +9,14 @@ class NotificationIcon extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
render = () => {
|
render = () => {
|
||||||
var linkClasses = "notificationsIcon upperRightEl upperRightIcon "
|
let linkClasses = 'notificationsIcon upperRightEl upperRightIcon '
|
||||||
|
|
||||||
if (this.props.unreadNotificationsCount > 0) {
|
if (this.props.unreadNotificationsCount > 0) {
|
||||||
linkClasses += "unread"
|
linkClasses += 'unread'
|
||||||
} else {
|
} else {
|
||||||
linkClasses += "read"
|
linkClasses += 'read'
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<a className={linkClasses} href="/notifications">
|
<a className={linkClasses} href="/notifications">
|
||||||
<div className="tooltipsUnder">
|
<div className="tooltipsUnder">
|
||||||
|
@ -26,8 +26,7 @@ class NotificationIcon extends Component {
|
||||||
<div className="unread-notifications-dot"></div>
|
<div className="unread-notifications-dot"></div>
|
||||||
)}
|
)}
|
||||||
</a>
|
</a>
|
||||||
|
|
||||||
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue