Skip to content

Commit 55a5551

Browse files
Pagination for exercise thumbnails
On the gym index page and search page
1 parent 01d23bc commit 55a5551

10 files changed

Lines changed: 24 additions & 25 deletions

File tree

app/models/exercise.rb

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class Exercise < ActiveRecord::Base
8787
# validates :current_version, presence: true
8888

8989
#~ Pagination ...............................................................
90-
max_paginates_per 50
90+
max_paginates_per 40
9191

9292
Q_MC = 1
9393
Q_CODING = 2
@@ -130,19 +130,16 @@ def self.search(terms, user = nil)
130130
end
131131
if user
132132
visible = Exercise.visible_to_user(user)
133-
result = visible.tagged_with(terms, any: true, wild: true, on: :tags) +
134-
visible.tagged_with(terms, any: true, wild: true, on: :languages) +
135-
visible.tagged_with(terms, any: true, wild: true, on: :styles) +
136-
visible.where('(name regexp (?)) or (exercises.id in (?))', r, ids)
137-
return result.uniq
138133
else
139134
visible = Exercise.publicly_visible
140-
result = visible.tagged_with(terms, any: true, wild: true, on: :tags) +
141-
visible.tagged_with(terms, any: true, wild: true, on: :languages) +
142-
visible.tagged_with(terms, any: true, wild: true, on: :styles) +
143-
visible.where('(name regexp (?)) or (exercises.id in (?))', r, ids)
144-
return result.uniq
145135
end
136+
137+
result = visible.tagged_with(terms, any: true, wild: true, on: :tags)
138+
.union(visible.tagged_with(terms, any: true, wild: true, on: :languages))
139+
.union(visible.tagged_with(terms, any: true, wild: true, on: :styles))
140+
.union(visible.where('(name regexp (?)) or (exercises.id in (?))', r, ids))
141+
.distinct
142+
return result
146143
end
147144

148145

app/views/exercises/_exercise.html.haml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,9 @@
122122
= difficulty_image(exercise.experience.to_i)
123123
.taglist
124124
- exercise.languages.each do |lang|
125-
= link_to lang.name, exercises_search_path(search: lang.name),
126-
method: :post, class: 'tag lang'
125+
= link_to lang.name, exercises_search_path(search: lang.name), class: 'tag lang'
127126
- exercise.tags.each do |tag|
128-
= link_to tag.name, exercises_search_path(search: tag.name),
129-
method: :post, class: 'tag'
127+
= link_to tag.name, exercises_search_path(search: tag.name), class: 'tag'
130128
-#
131129
- attempt = nil
132130
- uid = 0

app/views/exercises/_find_exercises_to_add.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
%h2 Search for exercises
22
.row.search-area
3-
= form_tag exercises_search_path(params[:search]), remote: true do
3+
= form_tag exercises_search_path(params[:search]), method: :get, remote: true do
44
.col-xs-8
55
= text_field_tag :search, nil, placeholder: 'e.g. recursion', class: 'form-control input-sm', id: 'search-terms'
66
.col-xs-3

app/views/exercises/search.html.haml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
%p
33
Searching for:
44
- @terms.each do |t|
5-
= link_to t, exercises_search_path(search: t), method: :post, class: 'tag'
5+
= link_to t, exercises_search_path(search: t), class: 'tag'
66

77
- uid = user_signed_in? ? current_user.id : 0
88
- if not(@msg.empty?)
@@ -15,7 +15,9 @@
1515
.clearfix
1616

1717
- if not(@exs.empty?)
18+
- @exs = @exs.page params[:page]
1819
%h2 Individual Exercises
1920
- @exs.in_groups_of(2, false) do |row|
2021
= render row, user: current_user
2122
.clearfix
23+
= paginate @exs

app/views/users/calc_performance.html.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
- @tag_scores.each do |t|
1414
%tr
1515
%td
16-
=link_to t[:tag_name], exercises_search_path(:search => t[:tag_name]),
17-
method: :post, class: 'tag'
16+
=link_to t[:tag_name], exercises_search_path(:search => t[:tag_name]), class: 'tag'
1817
%td
1918
- earned = rand(500)
2019
- possible = rand(500)

app/views/workouts/_workout.html.haml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,7 @@
113113
= difficulty_image(workout.highest_difficulty.to_i)
114114
.taglist
115115
- workout.tags.each do |t|
116-
= link_to t.name, exercises_search_path(search: t.name),
117-
method: :post, class: 'tag'
116+
= link_to t.name, exercises_search_path(search: t.name), class: 'tag'
118117

119118
-#.well.well-sm.col-md-5
120119
.row

app/views/workouts/review.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
%p
1010
Tags:
1111
- @workout.tags.each do |t|
12-
=link_to t.name, exercises_search_path(search: t.name), method: :post, class: 'tag'
12+
=link_to t.name, exercises_search_path(search: t.name), class: 'tag'
1313

1414
- if course_offering && course_offering.is_staff?(review_user)
1515
%table.table.table-striped{ style: 'width: auto' }

app/views/workouts/show.html.haml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
%p
1414
Tags:
1515
- @workout.tags.each do |t|
16-
=link_to t.name, exercises_search_path(search: t.name), method: :post, class: 'tag'
16+
=link_to t.name, exercises_search_path(search: t.name), class: 'tag'
1717

1818
- if course_offering && course_offering.is_staff?(current_user)
1919
%table.table.table-striped{ style: 'width: auto' }

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161
patch 'exercises/:id/practice' => 'exercises#evaluate',
6262
as: :exercise_evaluate
6363
get 'exercises/:id/embed' => 'exercises#embed', as: :exercise_embed
64-
post 'exercises/search' => 'exercises#search', as: :exercises_search
64+
get 'exercises/search' => 'exercises#search', as: :exercises_search
6565
get 'exercises/query_data' => 'exercises#query_data',
6666
as: :exercises_query_data
6767
get 'exercises/:id/download_attempt_data' =>

lib/tasks/sample_data.rake

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,11 @@ namespace :db do
7676

7777
# Create a workout with one exercise, and a second exercise
7878
w = FactoryBot.create :workout_with_exercises
79-
FactoryBot.create :coding_exercise, name: 'Factorial 3'
79+
80+
50.times do |i|
81+
FactoryBot.create :coding_exercise, name: "Factorial #{i}"
82+
FactoryBot.create :mc_exercise, name: "MCQ #{i}"
83+
end
8084

8185
user_group = FactoryBot.create :user_group
8286
user_group.users << [ instructor, instructor2 ]

0 commit comments

Comments
 (0)