Skip to content

Commit

Permalink
fix(campus): rename view files and template references of city to cam…
Browse files Browse the repository at this point in the history
…pus (#324)

* fix(campus): rename view files and template references of city to campus

* fix(campus): tests

* feat(campus): further migrate cities to campuses

* fix(campus): update campus route path

* Fix the user show

* Show and order cities dropdown by vanity_name

* Form label

* Update campus show

* CityRowComponent -> CampusRowComponent

---------

Co-authored-by: pil0u <8350914+pil0u@users.noreply.github.com>
  • Loading branch information
wJoenn and pil0u committed Nov 17, 2023
1 parent 23f4f98 commit e85acfe
Show file tree
Hide file tree
Showing 19 changed files with 98 additions and 98 deletions.
2 changes: 1 addition & 1 deletion .erb-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ linters:
ErbSafety:
exclude:
- "**/app/components/header/nav_component.html.erb"
- "**/app/components/scores/city_row_component.html.erb"
- "**/app/components/scores/campus_row_component.html.erb"
- "**/app/components/scores/squad_row_component.html.erb"
- "**/app/components/scores/user_row_component.html.erb"
- "**/app/components/snippets/box_component.html.erb"
Expand Down
37 changes: 37 additions & 0 deletions app/components/scores/campus_row_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<%# The scale-100 trick is to make the last td absolute, relative to the tr %>

<tr class="scale-100 hover:bg-hover <%= "bg-aoc-green bg-opacity-20" if @campus[:id] == @user.city_id %>">
<td class="<%= class_names(rank_css(@campus[:rank])) %>">
<%= link_to campus_path(@campus[:slug]), class: "flex justify-center" do %>
<%= (@campus[:rank] if @campus[:display_rank]) || "&nbsp".html_safe %>
<% end %>
</td>

<td>
<%= link_to campus_path(@campus[:slug]), class: "flex justify-center" do %>
<%= @campus[:vanity_name] %>
<% end %>
</td>

<td class="py-1 strong text-lg">
<%= link_to campus_path(@campus[:slug]), class: "flex justify-center" do %>
<%= @campus[:score] %>
<% end %>
</td>

<td>
<%= link_to campus_path(@campus[:slug]), class: "flex justify-center" do %>
<%= @campus[:total_members] %>
<% end %>
</td>

<td title="# of members who solved daily part 1&#10;# of members who solved daily part 2&#10;# of top contributors of the campus">
<%= link_to campus_path(@campus[:slug]), class: "flex text-center" do %>
<span class="basis-1/3 text-aoc-silver text-opacity-80"><%= @campus[:daily_contributors_part_1] %></span>
<span class="basis-1/3 text-aoc-gold text-opacity-50"><%= @campus[:daily_contributors_part_2] %></span>
<span class="basis-1/3">/<%= @campus[:top_contributors] %></span>
<% end %>
</td>

<%= render Scores::RankEvolutionCellComponent.new(previous_rank: @campus[:previous_rank], current_rank: @campus[:rank]) %>
</tr>
14 changes: 14 additions & 0 deletions app/components/scores/campus_row_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Scores
class CampusRowComponent < ApplicationComponent
include ScoresHelper

with_collection_parameter :campus

def initialize(campus:, user:)
@campus = campus
@user = user
end
end
end
37 changes: 0 additions & 37 deletions app/components/scores/city_row_component.html.erb

This file was deleted.

14 changes: 0 additions & 14 deletions app/components/scores/city_row_component.rb

This file was deleted.

2 changes: 1 addition & 1 deletion app/components/scores/nav_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<nav class="text-sm flex mb-8 mx-auto px-2 pb-2 gap-x-4 lg:gap-x-6 border-b border-aoc-gray-darker">
<%= render NavTabComponent.new(link: { name: "squads", path: scores_squads_path }) %>
<%= render NavTabComponent.new(link: { name: "cities", path: scores_cities_path }) %>
<%= render NavTabComponent.new(link: { name: "campuses", path: scores_campuses_path }) %>
<%= render NavTabComponent.new(link: { name: "solo", path: scores_solo_path }) %>
<%= render NavTabComponent.new(link: { name: "insanity", path: scores_insanity_path }) %>
</nav>
4 changes: 2 additions & 2 deletions app/components/user_form_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</div>

<div class="flex flex-col gap-y-1 sm:flex-row sm:items-center sm:gap-x-3">
<%= f.label :city_name, "Campus" %>
<%= f.collection_select(:city_id, City.order(:name), :id, :name, { prompt: "", selected: @user.batch&.city_id }, class: "input", disabled: @user.batch&.city_id?) %>
<%= f.label :campus_name, "Campus" %>
<%= f.collection_select(:city_id, City.order(:vanity_name), :id, :vanity_name, { prompt: "", selected: @user.batch&.city_id }, class: "input", disabled: @user.batch&.city_id?) %>
</div>

<div class="flex items-center gap-x-3 w-48 sm:w-fit">
Expand Down
22 changes: 11 additions & 11 deletions app/controllers/campuses_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@

class CampusesController < ApplicationController
def show
@city = City.find_by_slug(params[:slug]) # rubocop:disable Rails/DynamicFindBy
@campus = City.find_by_slug(params[:slug]) # rubocop:disable Rails/DynamicFindBy

casual_scores = Scores::SoloScores.get
casual_presenter = Scores::UserScoresPresenter.new(casual_scores)
casual_participants = casual_presenter.get
squad_user_uids = @city.users.pluck(:uid).map(&:to_i)
@city_users = casual_participants.select { |p| p[:uid].in? squad_user_uids }
.sort_by { |p| p[:score] * -1 }
compute_ranks_from_score(@city_users)
squad_user_uids = @campus.users.pluck(:uid).map(&:to_i)
@campus_users = casual_participants.select { |p| p[:uid].in? squad_user_uids }
.sort_by { |p| p[:score] * -1 }
compute_ranks_from_score(@campus_users)

city_scores = Scores::CityScores.get
city_presenter = Scores::CityScoresPresenter.new(city_scores)
cities = city_presenter.get
@city_stats = cities.find { |h| h[:id] == @city.id }
campus_scores = Scores::CityScores.get
campus_presenter = Scores::CityScoresPresenter.new(campus_scores)
campuses = campus_presenter.get
@campus_stats = campuses.find { |h| h[:id] == @campus.id }
# TODO: remove when implemented
@city_stats[:silver_stars] = @city_users.sum { |h| h[:silver_stars] }
@city_stats[:gold_stars] = @city_users.sum { |h| h[:gold_stars] }
@campus_stats[:silver_stars] = @campus_users.sum { |h| h[:silver_stars] }
@campus_stats[:gold_stars] = @campus_users.sum { |h| h[:gold_stars] }
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/scores_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ def campuses
scores = Scores::CityScores.get
presenter = Scores::CityScoresPresenter.new(scores)

@cities = presenter.get
@campuses = presenter.get

add_display_rank(@cities)
add_display_rank(@campuses)
end

def insanity
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def show
city_scores = Scores::CityScores.get
city_presenter = Scores::CityScoresPresenter.new(city_scores)
cities = city_presenter.get
@city_stats = cities.find { |h| h[:id] == @user.city_id }
@campus_stats = cities.find { |h| h[:id] == @user.city_id }

# Sort user achievements in the same order as in the YAML definition
@achievements = @user.achievements
Expand Down
2 changes: 1 addition & 1 deletion app/presenters/scores/city_scores_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def get
def identity_of(city)
{
id: city.id,
name: city.name,
vanity_name: city.vanity_name,
slug: city.slug
}
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
<div class="text-lg flex flex-wrap flex-col sm:flex-row items-center sm:justify-between">
<div class="flex flex-wrap gap-x-6">
<h2 class="strong"><%= @city.vanity_name %></h2>
<h2 class="strong"><%= @campus.vanity_name %></h2>
</div>

<div class="flex gap-x-6">
<span>
<% if @city_stats[:silver_stars] > 0 %>
<span class="text-aoc-silver"><%= @city_stats[:silver_stars] %>*</span>
<% if @campus_stats[:silver_stars] > 0 %>
<span class="text-aoc-silver"><%= @campus_stats[:silver_stars] %>*</span>
<% end %>
<span class="text-aoc-gold"><%= @city_stats[:gold_stars] %>*</span>
<span class="text-aoc-gold"><%= @campus_stats[:gold_stars] %>*</span>
</span>
<span>·</span>
<span class="text-aoc-atmospheric"><%= @city_stats[:score] %> pts</span>
<span class="text-aoc-atmospheric"><%= @campus_stats[:score] %> pts</span>
<span>·</span>
<span><%= @city_stats[:rank] %><sup><%= @city_stats[:rank].ordinal %></sup></span>
<span><%= @campus_stats[:rank] %><sup><%= @campus_stats[:rank].ordinal %></sup></span>
</div>
</div>

<p class="my-4">
The scores of the <span class="strong">top <%= @city_stats[:top_contributors] %> contributors</span> are averaged to build the score of <%= @city.name %>.
The scores of the <span class="strong">top <%= @campus_stats[:top_contributors] %> contributors</span> are averaged to build the score of <%= @campus.name %>.
</p>

<table class="block overflow-x-auto whitespace-nowrap w-full max-w-2xl mx-auto">
Expand All @@ -33,6 +33,6 @@
</thead>

<tbody>
<%= render Scores::UserRowComponent.with_collection(@city_users, user: current_user) %>
<%= render Scores::UserRowComponent.with_collection(@campus_users, user: current_user) %>
</tbody>
</table>
6 changes: 3 additions & 3 deletions app/views/pages/faq.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -184,9 +184,9 @@
Ranking campuses is hard, because the number of Alumni per campus is very different.
</p>
<p>
For <em>each challenge</em>, only the scores of your campus's top contributors are taken into account. The number
of top contributors is determined by your <span class="strong">campus's size</span>: it's either
<code class="strong">3%</code> of your campus's size, or <code class="strong">10</code> contributors, whatever
For <em>each challenge</em>, only the scores of your campus' top contributors are taken into account. The number
of top contributors is determined by your <span class="strong">campus' size</span>: it's either
<code class="strong">3%</code> of your campus' size, or <code class="strong">10</code> contributors, whatever
the <em>greatest</em>.
</p>
<p>
Expand Down
4 changes: 2 additions & 2 deletions app/views/pages/participation.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<div class="my-4 flex flex-col gap-y-4">
<p>
The city which brings the most sign ups - <em>in proportion to their size</em> - by November 30th will be allowed to
The campus which brings the most sign ups - <em>in proportion to their size</em> - by November 30th will be allowed to
customise their name on the platform (custom <span class="text-[#d946ef]">colour</span>, custom 𝑛𝑎𝑚𝑒).
</p>

Expand All @@ -11,7 +11,7 @@
</p>

<p>
The assignment of users to their city is manual: they need to select it in
The assignment of users to their campus is automatic: they can see it in
their <%= link_to "settings", settings_path, class: "link-internal link-explicit" %>.
</p>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/pages/welcome.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

<p>
Solving any puzzle, <em>at any time</em>, earns you points 💎. Not only for you, but also for
<span class="strong">your campus city</span> from <span class="text-wagon-red">Le Wagon</span> or your dream
<span class="strong">your campus</span> from <span class="text-wagon-red">Le Wagon</span> or your dream
<span class="strong">squad of 4 players</span>.
</p>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<%= render PageTitleComponent.new(title: "Campus scoreboard") %>

<p class="my-4">
For each <em>challenge</em>, we compute the average score of the top contributors. The score of the city is the sum of
For each <em>challenge</em>, we compute the average score of the top contributors. The score of the campus is the sum of
these averages. <%= link_to "More info", faq_path, class: "link-explicit link-internal" %>.
</p>

Expand All @@ -14,11 +14,11 @@
<th class="font-light w-full"></th>
<th class="font-light min-w-[6rem]">Score</th>
<th class="font-light min-w-[6rem]">Members</th>
<th class="font-light min-w-[7rem] hover:cursor-help" title="# of members who solved daily part 1&#10;# of members who solved daily part 2&#10;# of top contributors of the city">Daily contr.</th>
<th class="font-light min-w-[7rem] hover:cursor-help" title="# of members who solved daily part 1&#10;# of members who solved daily part 2&#10;# of top contributors of the campus">Daily contr.</th>
</tr>
</thead>

<tbody>
<%= render Scores::CityRowComponent.with_collection(@cities, user: current_user) %>
<%= render Scores::CampusRowComponent.with_collection(@campuses, user: current_user) %>
</tbody>
</table>
10 changes: 5 additions & 5 deletions app/views/users/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -59,19 +59,19 @@
<% end %>
<% end %>

<% if @city_stats.present? %>
<%= link_to city_path(@city_stats[:slug]), class: "w-36 h-36 p-2 flex flex-col justify-between border border-aoc-gray-darker bg-aoc-gray-darkest hover:bg-aoc-gray-darker" do %>
<% if @campus_stats.present? %>
<%= link_to campus_path(@campus_stats[:slug]), class: "w-36 h-36 p-2 flex flex-col justify-between border border-aoc-gray-darker bg-aoc-gray-darkest hover:bg-aoc-gray-darker" do %>
<h3 class="h-2/5 flex items-center justify-center strong text-center text-lg">
<%= @city_stats[:name] %>
<%= @campus_stats[:vanity_name] %>
</h3>

<div class="h-3/5 flex flex-col justify-around">
<span class="flex items-center justify-center text-aoc-atmospheric text-lg">
<%= @city_stats[:score] %> pts
<%= @campus_stats[:score] %> pts
</span>

<span class="flex items-center justify-center text-lg">
<%= @city_stats[:rank] %><sup><%= @city_stats[:rank].ordinal %></sup>
<%= @campus_stats[:rank] %><sup><%= @campus_stats[:rank].ordinal %></sup>
</span>
</div>
<% end %>
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def omniauth_callbacks(provider)
authenticated :user, ->(user) { user.confirmed? } do
get "/", to: "pages#calendar", as: :calendar
get "/countdown", to: "pages#countdown"
get "/campuses/:slug", to: "campuses#show", as: :campus
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]/
get "/day/:day/:challenge", to: "snippets#show", as: :snippet, day: /[1-9]|1\d|2[0-5]/, challenge: /[1-2]/, constraints: SolvedPuzzleConstraint.new
Expand Down
10 changes: 5 additions & 5 deletions spec/presenters/scores/city_scores_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,15 +44,15 @@
)
end

it "completes the city info" do
it "completes the campus info" do
expect(described_class.new(input).get).to contain_exactly(
hash_including(id: 1, name: "Bordeaux", slug: "bordeaux"),
hash_including(id: 2, name: "Rio de Janeiro", slug: "rio-de-janeiro"),
hash_including(id: 3, name: "Paris", slug: "paris")
hash_including(id: 1, vanity_name: "Bordeaux", slug: "bordeaux"),
hash_including(id: 2, vanity_name: "Rio de Janeiro", slug: "rio-de-janeiro"),
hash_including(id: 3, vanity_name: "Paris", slug: "paris")
)
end

it "completes the city stats" do
it "completes the campus stats" do
expect(described_class.new(input).get).to contain_exactly(
hash_including(id: 1, total_members: 2, top_contributors: 10,
daily_contributors_part_1: 3, daily_contributors_part_2: 2),
Expand Down

0 comments on commit e85acfe

Please sign in to comment.