Skip to content

Commit 01d23bc

Browse files
Pagination for the exercise index page
1 parent cf5df9d commit 01d23bc

5 files changed

Lines changed: 43 additions & 1 deletion

File tree

app/assets/stylesheets/custom.scss

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,42 @@ ul.wysihtml5-toolbar li {
279279
}
280280
}
281281

282+
/* Exercise index page pagination */
283+
284+
.pagination {
285+
display: flex;
286+
justify-content: center;
287+
288+
ul {
289+
list-style-type: none;
290+
margin: 0;
291+
padding: 0;
292+
293+
li {
294+
display: inline;
295+
float: left;
296+
}
297+
}
298+
299+
.page, .next, .prev, .first, .last {
300+
a {
301+
text-decoration: none;
302+
color: white;
303+
padding: 2px 10px;
304+
margin: 2px;
305+
border-radius: 3px;
306+
background-color: #5bc0de;
307+
&:hover {
308+
filter: brightness(80%);
309+
}
310+
}
311+
312+
&.active > a {
313+
background-color: #ffc107;
314+
}
315+
}
316+
}
317+
282318
.thumbnail.lg {
283319
width: 45%;
284320
margin-right: 2%;

app/controllers/exercises_controller.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ def index
1919
else
2020
@exercises = Exercise.publicly_visible
2121
end
22+
23+
@exercises = @exercises.page params[:page]
2224
end
2325

2426

app/models/exercise.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,9 @@ class Exercise < ActiveRecord::Base
8686
# exercises, so I'm leaving it out for now:
8787
# validates :current_version, presence: true
8888

89+
#~ Pagination ...............................................................
90+
max_paginates_per 50
91+
8992
Q_MC = 1
9093
Q_CODING = 2
9194
Q_BLANKS = 3

app/views/exercises/index.html.haml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
- @exercises.in_groups_of(2, false) do |row|
1111
= render row, user: current_user
1212
.clearfix
13+
= paginate @exercises
1314
- else
1415
%p
1516
No public exercises are available to view right now. Please wait for

app/views/kaminari/_next_page.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
remote: data-remote
99
1010
- unless current_page.last?
11-
%li{ class: "next_page" }
11+
%li{ class: "next" }
1212
= link_to_unless current_page.last?,
1313
raw(t 'views.pagination.next'),
1414
url,

0 commit comments

Comments
 (0)