Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(pages): patrons page #317

Merged
merged 16 commits into from
Nov 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions app/components/footer/copyright_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p>
Made with ♥️ by
<%= link_to "pil0u", "slack://user?team=T02NE0241&id=URZ0F4TEF", class: "text-white font-semibold hover:text-aoc-atmospheric" %>,
<%= link_to "Aquaj", "slack://user?team=T02NE0241&id=U0J5GUEAW", class: "text-white font-semibold hover:text-aoc-atmospheric" %> &
<%= link_to "Joenn", "slack://user?team=T02NE0241&id=U045Z0313UP", class: "text-white font-semibold hover:text-aoc-atmospheric" %>
<%= link_to "pil0u", "slack://user?team=T02NE0241&id=URZ0F4TEF", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %>,
<%= link_to "Aquaj", "slack://user?team=T02NE0241&id=U0J5GUEAW", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %> &
<%= link_to "Joenn", "slack://user?team=T02NE0241&id=U045Z0313UP", target: :_blank, rel: :noopener, class: "text-white font-semibold hover:text-aoc-atmospheric" %>
<%= link_to "https://github.com/pil0u/lewagon-aoc", target: :_blank, rel: "noopener", class: "text-other-green hover:link-external" do %>
<%= link_to "https://github.com/pil0u/lewagon-aoc", target: :_blank, rel: :noopener, class: "text-other-green hover:link-external" do %>
<i class="fab fa-github"></i>
<% end %>
</p>
3 changes: 2 additions & 1 deletion app/components/footer/nav_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<nav>
<%= link_to "code of conduct", code_of_conduct_path, class: "link-explicit" %>
<%= link_to "stats", stats_path, class: "link-explicit" %>
<%= link_to "patrons", patrons_path, class: "link-explicit" %>
<%= link_to "the wall", messages_path, class: "link-explicit" %>
<%= link_to "community", Aoc.slack_channel, class: "link-explicit link-slack" %>
<%= link_to "community", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>
</nav>
11 changes: 10 additions & 1 deletion app/controllers/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

class PagesController < ApplicationController
skip_before_action :authenticate_user!, only: %i[admin code_of_conduct faq participation stats welcome]
before_action :render_countdown, only: %i[code_of_conduct faq participation setup stats welcome], if: :render_countdown?
before_action :render_countdown, only: %i[code_of_conduct faq participation patrons setup stats welcome], if: :render_countdown?

def admin; end

Expand Down Expand Up @@ -52,6 +52,15 @@ def participation
@cities.sort_by! { |city| [city[:participation_ratio] * -1, city[:vanity_name]] }
end

def patrons
@users = User
.select("users.uid, users.username, COUNT(referees.id) AS referrals")
.select("CEIL(100 * LN(COUNT(referees.id) + 1)) AS aura")
.joins("LEFT JOIN users referees ON users.id = referees.referrer_id")
.group("users.id")
.order(aura: :desc)
end

def setup
@private_leaderboard = ENV.fetch("AOC_ROOMS").split(",").last

Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ def referral_code
"R#{uid.to_s.rjust(5, '0')}"
end

def referral_link(request)
"#{request.base_url}/?referral_code=#{referral_code}"
end

def referrer_code
referrer&.referral_code
end
Expand Down
2 changes: 1 addition & 1 deletion app/views/days/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

<% if @day <= Aoc.latest_day %>
<span>·</span>
<%= link_to "link to puzzle", Aoc.url(@day), target: :_blank, rel: "noopener", class: "link-explicit link-external" %>
<%= link_to "link to puzzle", Aoc.url(@day), target: :_blank, rel: :noopener, class: "link-explicit link-external" %>
<% end %>
</div>

Expand Down
4 changes: 2 additions & 2 deletions app/views/pages/admin.html.erb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<% if user_signed_in? %>

<div class="my-2">
<%= link_to "Blazer", blazer_path, class: "button" %>
<%= link_to "GoodJob", good_job_path, class: "button" %>
<%= link_to "Blazer", blazer_path, target: :_blank, rel: :noopener, class: "button" %>
<%= link_to "GoodJob", good_job_path, target: :_blank, rel: :noopener, class: "button" %>
<%= link_to "/participation", participation_path, class: "button" %>
</div>

Expand Down
6 changes: 4 additions & 2 deletions app/views/pages/code_of_conduct.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
<li>
<h3 class="strong">Be respectful and empathetic towards all community members</h3>
<p>
This event and the <%= link_to "#aoc Slack channel", Aoc.slack_channel, class: "link-explicit link-slack" %>
This event and the
<%= link_to "#aoc Slack channel", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>
should be a safe place for everyone. Always assume positive intent, be positive, friendly and helpful to
others. Focus on good vibes; we do not tolerate any form of derogatory comments or personal attacks.
</p>
Expand All @@ -46,7 +47,8 @@
<h3 class="strong">Please, don't try to break in</h3>
<p>
Attempting to access the platform in unauthorized ways is not permitted and is not fun for the community or the
Admins. The platform's code is <%= link_to "open", "https://github.com/pil0u/lewagon-aoc/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %>
Admins. The platform's code is
<%= link_to "open", "https://github.com/pil0u/lewagon-aoc/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %>
and all the data you can find here is available upon request. Also, scores are computed from AoC's data, so they
cannot be changed by breaking in <em>here</em> anyway.
</p>
Expand Down
10 changes: 5 additions & 5 deletions app/views/pages/faq.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

<div class="flex flex-col gap-y-2 text-justify">
<p>
<%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %>
<%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %>
is an Advent calendar of small programming puzzles that you can solve in any programming language.
</p>
<p>
Expand Down Expand Up @@ -72,7 +72,7 @@
</p>
<p>
Puzzles from past editions are available
<%= link_to "here", "https://adventofcode.com/events", target: :ext, class: "link-explicit link-external" %>.
<%= link_to "here", "https://adventofcode.com/events", target: :_blank, rel: :noopener, class: "link-explicit link-external" %>.
</p>
</div>
</details>
Expand All @@ -92,8 +92,8 @@
</p>
<p>
If you get stuck on a puzzle, you can always
<%= link_to "discuss with other Wagoners", Aoc.slack_channel, class: "link-explicit link-slack" %>! This event
is about <span class="strong">sharing, learning, and mutual help, irrespective of your skill level</span>.
<%= link_to "discuss with other Wagoners", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>!
This event is about <span class="strong">sharing, learning, and mutual help, irrespective of your skill level</span>.
It's also a perfect time to reconnect with your campus/batch 🤙
</p>
</div>
Expand All @@ -109,7 +109,7 @@
</p>
<p>
You build your squad by assembling your dream team (find people
<%= link_to "on Slack", Aoc.slack_channel, class: "link-explicit link-slack" %>) and create a squad in your
<%= link_to "on Slack", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>) and create a squad in your
<%= link_to "settings", settings_path, class: "link-explicit link-internal" %><sup>(*)</sup> in 1 click.
</p>
<p>
Expand Down
68 changes: 68 additions & 0 deletions app/views/pages/patrons.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<%= render PageTitleComponent.new(title: "Patrons") %>

<div class="my-4 flex flex-col gap-y-4">
<p>
Influencers of Le Wagon, this is your moment.
</p>

<p>
Your referral code
<code
class="hover:cursor-pointer hover:text-gold active:text-aoc-gray"
data-controller="clipboard"
data-action="click->clipboard#copy"
data-clipboard-content-value="<%= current_user.referral_code %>"><%= current_user.referral_code %></code>
is your fame booster. Share it everywhere to your fellow Wagoners: your batch channel
<%= link_to "on Slack", Aoc.slack_channel, target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>,
your WhatsApp groups, by mail or pigeon, whatever feels right. You even have a personal link you can share:
</p>

<code
class="w-max mx-auto hover:cursor-pointer hover:text-gold active:text-aoc-gray"
data-controller="clipboard"
data-action="click->clipboard#copy"
data-clipboard-content-value="<%= current_user.referral_link(request) %>">
<%= current_user.referral_link(request) %>
</code>

<p>
Every time someone signs up using your code, you will increase your <span class="strong">aura</span>. Finding people
who solve a few puzzles can only help your <span class="strong">aura</span> as well.
</p>

<p>
One more thing. The top referrer by December 8th wins a <code>100€</code> Amazon voucher 💸
</p>

<p>
Good luck!
</p>
</div>

<table class="block overflow-x-auto whitespace-nowrap w-full max-w-lg mx-auto">
<thead>
<tr class="border-b border-aoc-gray-darker">
<th class="font-light w-full"></th>
<th class="font-light min-w-[6rem]">Referrals</th>
<th class="font-light min-w-[6rem]">Aura</th>
</tr>
</thead>

<tbody>
<% @users.each do |user| %>
<tr class="hover:bg-hover">
<td class="text-center">
<%= link_to user[:username], profile_path(user[:uid]), class: "hover:text-gold" %>
</td>

<td class="text-center">
<%= user[:referrals] %>
</td>

<td class="text-center strong">
<%= user[:aura].to_i %>
</td>
</tr>
<% end %>
</tbody>
</table>
8 changes: 4 additions & 4 deletions app/views/pages/setup.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"Log in to Advent of Code",
"https://adventofcode.com/auth/login",
target: :_blank,
rel: "noopener",
rel: :noopener,
class: "link-explicit link-external"
) %>, using either your GitHub account or another OAuth option.
</li>
Expand All @@ -42,7 +42,7 @@
"Go to this page",
"https://adventofcode.com/leaderboard/private",
target: :_blank,
rel: "noopener",
rel: :noopener,
class: "link-explicit link-external"
) %>, enter the following code <code class="strong"><%= current_user.private_leaderboard %></code> and click [Join].
</p>
Expand All @@ -57,7 +57,7 @@
"your settings",
"https://adventofcode.com/settings",
target: :_blank,
rel: "noopener",
rel: :noopener,
class: "link-explicit link-external"
) %>. It's the number next to <code>anonymous user #<span class="strong">XXXXXXX</span></code>.
</li>
Expand Down Expand Up @@ -124,7 +124,7 @@
<p class="mt-4 italic text-sm opacity-80">
If you have completed all these steps, <b>waited 10 minutes</b>, and your status remains
<span class="not-italic text-aoc-atmospheric">Pending</span>, please send a message in this
<%= link_to "Slack thread", "https://lewagon-alumni.slack.com/archives/C02PN711H09/p1700598449505399", class: "link-explicit link-slack" %>
<%= link_to "Slack thread", "https://lewagon-alumni.slack.com/archives/C02PN711H09/p1700598449505399", target: :_blank, rel: :noopener, class: "link-explicit link-slack" %>
with the following details:
<code class="not-italic strong">id:<%= current_user.id %>;aoc_id:<%= current_user.aoc_id %></code>
</p>
2 changes: 1 addition & 1 deletion app/views/pages/welcome.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex flex-col text-justify max-w-prose mx-auto gap-y-6">
<p>
<%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: "noopener", class: "link-explicit link-external" %>
<%= link_to "Advent of Code", "https://adventofcode.com/", target: :_blank, rel: :noopener, class: "link-explicit link-external" %>
is an Advent calendar of small programming puzzles that can be solved in any programming language you like.
</p>

Expand Down
9 changes: 5 additions & 4 deletions app/views/users/edit.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,25 +77,26 @@
<%= render PageTitleComponent.new(title: "Referral") %>

<p class="my-4">
When you share the event to your friends, ask them to add this referral code during the setup. This will boost your aura.
When you share the event to your friends, ask them to add this referral code during the setup. This will boost your
<%= link_to "aura", patrons_path, class: "strong hover:text-gold" %>.
</p>

<div class="my-4 flex flex-col justify-center gap-y-1 sm:flex-row sm:items-center sm:gap-x-3">
<input type="text" value="<%= current_user.referral_code %>" class="input" disabled autocomplete="off">

<button
class="button"
class="button active:text-aoc-gray"
data-controller="clipboard"
data-action="click->clipboard#copy"
data-clipboard-content-value="<%= current_user.referral_code %>">
Copy code
</button>

<button
class="button"
class="button active:text-aoc-gray"
data-controller="clipboard"
data-action="click->clipboard#copy"
data-clipboard-content-value="<%= "#{request.base_url}/?referral_code=#{current_user.referral_code}" %>">
data-clipboard-content-value="<%= current_user.referral_link(request) %>">
Copy invite link
</button>
</div>
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ def omniauth_callbacks(provider)
authenticated :user, ->(user) { user.confirmed? } do
get "/", to: "pages#calendar", as: :calendar
get "/countdown", to: "pages#countdown"
get "/patrons", to: "pages#patrons"
get "/campus/:slug", to: "campuses#show", as: :campus
get "/city/:slug", to: "campuses#show", as: :city # Retrocompat in case of old links
get "/day/:day", to: "days#show", as: :day, day: /[1-9]|1\d|2[0-5]/
Expand Down
30 changes: 30 additions & 0 deletions spec/controllers/pages_controller_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# frozen_string_literal: true

require "rails_helper"

RSpec.describe PagesController do
let!(:referrer) { create :user, uid: "1" }
let!(:referee_one) { create :user, username: "Aquaj", uid: "2", referrer: }
let!(:referee_two) { create :user, username: "wJoenn", uid: "3", referrer: }
let!(:referee_three) { create :user, username: "Aurrou", uid: "4", referrer: referee_one }

describe "#patrons" do
it "requires to be authenticated", :logged_out do
get :patrons

expect(response).to have_http_status :redirect
end

it "queries the username, the amount of referees and the aura for every User" do
sign_in(referrer)
get :patrons

expect(@controller.instance_variable_get(:@users).map(&:as_json)).to contain_exactly(
hash_including("uid" => "1", "username" => "pil0u", "referrals" => 2, "aura" => 110.0),
hash_including("uid" => "2", "username" => "Aquaj", "referrals" => 1, "aura" => 70.0),
hash_including("uid" => "3", "username" => "wJoenn", "referrals" => 0, "aura" => 0.0),
hash_including("uid" => "4", "username" => "Aurrou", "referrals" => 0, "aura" => 0.0)
)
end
end
end