Skip to content

Commit 0eacc82

Browse files
committed
Add temporary competition count
1 parent 2260e60 commit 0eacc82

File tree

9 files changed

+66
-20
lines changed

9 files changed

+66
-20
lines changed

app/controllers/entries_controller.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ def create
2626

2727
# for anonymous id routing, update :link based on id
2828
@entry.update_column(:link, ((@entry.id**3).to_s(36)))
29+
30+
# temporary for the competition
31+
if @entry.created_at >= DateTime.parse("2021-04-27 22:00:00")
32+
count = current_user.competition
33+
unless count
34+
count = 0
35+
end
36+
count += 1
37+
current_user.update_column(:competition, count)
38+
end
39+
2940
redirect_to new_entry_path
3041
else
3142
flash.now[:error] = @entry.errors.full_messages[0]

app/controllers/pages_controller.rb

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,15 +82,8 @@ def competition
8282
"Partake in Learn Oshiwambo's competitions and help advance Oshiwambo
8383
to English translations.",
8484
%w[competition win reward learn oshiwambo])
85-
end
8685

87-
# also same method in profiles_controller.rb and entries_controller.rb
88-
def get_verified(entry)
89-
@vote = (entry.get_likes :vote_scope => 'verify').first
90-
if @vote
91-
@user = User.find_by(id: @vote.voter_id)
92-
end
86+
@users = User.all.order(competition: :desc).limit(10)
9387
end
94-
helper_method :get_verified, :hot
9588

9689
end

app/controllers/reports_controller.rb

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ def destroy
3434
end
3535
end
3636

37-
# also same method in profiles_controller.rb and entries_controller.rb
38-
def get_verified(entry)
39-
@vote = (entry.get_likes :vote_scope => 'verify').first
40-
if @vote
41-
@user = User.find_by(id: @vote.voter_id)
42-
end
43-
end
44-
helper_method :get_verified
45-
4637
private
4738

4839
def set_report

app/views/entries/_index.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
<% if comp_count == 2 %>
2020
<div class="text-gray small text-center" style="padding-bottom: 1em;">
21-
<%= link_to "Competition Rules", competition_path, class: "text-yellow" %>
21+
<%= link_to "Competition Rules & Rankings", competition_path, class: "text-yellow" %>
2222
</div>
2323
<% end %>
2424
<% comp_count = comp_count + 1 %>

app/views/pages/_competition.html.erb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!--suppress ALL -->
2+
<tr class="clickable-row" data-href="<%= profile_path(user) %>">
3+
<th class="table-row" scope="row">
4+
<%= "@" + user.username %>
5+
<%= is_moderator(user) %>
6+
</th>
7+
<td class="text-right table-row">
8+
<%= user.created_at.strftime("%b %Y") %>
9+
</td>
10+
</tr>
11+
12+
<script>
13+
$(document).ready(function () {
14+
$('[data-href]').click(function () {
15+
window.location = $(this).data("href");
16+
});
17+
});
18+
</script>

app/views/pages/competition.html.erb

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,29 @@
33
integrity="sha384-vSIIfh2YWi9wW0r9iZe7RJPrKwp6bG+s9QZMoITbCckVJqGCCRhc+ccxNcdpHuYu"
44
crossorigin="anonymous">
55

6-
<strong class="text-yellow" style="font-size: 1.7em;">Competition</strong>
6+
<strong class="text-yellow" style="font-size: 1.7em;">Rankings</strong>
7+
<div class="text-secondary m-0 p-0 small">
8+
Top 10 users with the highest number of entries
9+
</div>
10+
<hr class="custom-horizontal">
11+
12+
<table class="table table-custom table-hover text-gray">
13+
<thead>
14+
<tr style="font-weight: normal;">
15+
<th class="border-0" style="font-weight: normal;" scope="col">Username</th>
16+
<th class="border-0 text-right" style="font-weight: normal;" scope="col">Joined</th>
17+
</tr>
18+
</thead>
19+
<tbody>
20+
<% @users.each do | user | %>
21+
<%= render 'pages/competition', user: user %>
22+
<% end %>
23+
</tbody>
24+
</table>
25+
26+
<br>
27+
28+
<strong class="text-yellow" style="font-size: 1.7em;">Competition Rules</strong>
729
<hr class="custom-horizontal">
830

931
<p class="text-gray">
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class AddCompetitionToUser < ActiveRecord::Migration[6.1]
2+
def change
3+
add_column :users, :competition, :integer, default: 0
4+
end
5+
end

db/schema.rb

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

usefull.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,3 +131,8 @@ SQL PG
131131
select *
132132
from entries
133133
where user_id = '187' and created_at between 'April 10, 2021 15:00' and 'April 11, 2021 22:00';
134+
135+
----------------------------------------------------------------------------
136+
$ rake db:rollback STEP=1
137+
138+
----------------------------------------------------------------------------

0 commit comments

Comments
 (0)