Skip to content
Permalink
Browse files

Merge pull request #66 from yumoose/notification-pagination

Add notification pagination
  • Loading branch information...
yumoose committed Jun 14, 2019
2 parents 6f44eb9 + d0f9ba8 commit fcdf5d9f4267e27b5da781e9219af2373eba7e71

Large diffs are not rendered by default.

@@ -190,6 +190,9 @@ div.leagues {
.notifications .tile .icon img {
background-color: #ffa039; }

.notifications .notification.unread {
font-weight: bold; }

table.body.mailer table.container p, table.body.mailer table.container a {
font-family: "Muli", "Helvetica Neue", Helvetica, Arial, sans-serif; }

@@ -467,6 +470,20 @@ form.main {
font-size: 1.25em;
margin-bottom: 0.5em; }

.pagination li.page-item.disabled a {
background-color: transparent;
border: 1px solid rgba(0, 0, 0, 0.125); }

.pagination a {
color: #ef4b62;
background-color: rgba(0, 0, 0, 0.03);
transition: background-color 0.15s;
border: 1px solid rgba(0, 0, 0, 0.125); }
.pagination a:hover {
color: #ef4b62;
background-color: rgba(0, 0, 0, 0.1);
border: 1px solid rgba(0, 0, 0, 0.125); }

a.dropdown-item {
display: flex;
justify-content: space-between; }

Large diffs are not rendered by default.

@@ -82,4 +82,10 @@
}
}
}

.notification {
&.unread {
font-weight: bold;
}
}
}
@@ -33,6 +33,28 @@ $dark-grey: #343a40;
@import "home";
@import "tournament";

.pagination {
li.page-item.disabled {
a {
background-color: transparent;
border: 1px solid rgba(0,0,0,.125);
}
}

a {
color: $brand-primary;
background-color: rgba(0, 0, 0, 0.03);
transition: background-color 0.15s;
border: 1px solid rgba(0,0,0,.125);

&:hover {
color: $brand-primary;
background-color: rgba(0, 0, 0, 0.1);
border: 1px solid rgba(0,0,0,.125);
}
}
}

a.dropdown-item {
display: flex;
justify-content: space-between;
@@ -5,8 +5,10 @@ class NotificationController < ApplicationController

def index
player = current_player.not_nil!
unread_notifications = Notification.for_player(player).unread.order(created_at: :desc).to_a #.map(&.presented)
read_notifications = Notification.for_player(player).read.order(created_at: :desc).to_a #.map(&.presented)

total_items = Notification.for_player(player).count
last_page = total_items / per_page
notifications = Notification.for_player(player).order(created_at: :desc).limit(per_page).offset(offset)

render("index.slang")
end
@@ -50,4 +52,16 @@ class NotificationController < ApplicationController

redirect_to "/notifications"
end

private def page_number
(params[:page]? || 1).to_i
end

private def per_page
10
end

private def offset
(page_number - 1) * per_page
end
end
@@ -1,4 +1,4 @@
a.tile href="/notifications/#{notification.id}"
== render(partial: "notification/_icon.slang")
.content = notification.title
.content class="notification #{notification.read? ? "read" : "unread"}" = notification.title
.secondary = time_units_since(notification.created_at)
@@ -6,12 +6,21 @@
== csrf_tag
== submit(t("notification.actions.mark_all_as_read"), class: "btn btn-dark")

h6.section-header Unread
.notifications.tiles
- unread_notifications.each do |notification|
== render(partial: "_notification_tile.slang")
- if notifications.empty?
p No notifications to show
- else
.notifications.tiles
- notifications.each do |notification|
== render(partial: "_notification_tile.slang")

h6.section-header Read
.notifications.tiles
- read_notifications.each do |notification|
== render(partial: "_notification_tile.slang")
nav
ul class="pagination justify-content-center"
li class="page-item #{"disabled" if page_number == 1}"
a class="page-link" href="/notifications?page=#{[1, page_number - 1].max}" Previous

- (1..(total_items / per_page)).to_a.each do |page_number|
li class="page-item"
a class="page-link" href="/notifications?page=#{page_number}" = page_number

li class="page-item #{"disabled" if page_number == last_page}"
a class="page-link" href="/notifications?page=#{[last_page, page_number + 1].min}" Next

0 comments on commit fcdf5d9

Please sign in to comment.
You can’t perform that action at this time.