Skip to content

Commit

Permalink
Add nationality to player
Browse files Browse the repository at this point in the history
  • Loading branch information
MarioRodrigues10 committed Sep 15, 2023
1 parent aac1d14 commit 9ca8f34
Show file tree
Hide file tree
Showing 12 changed files with 279 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
strategy:
matrix:
otp: [25.x]
elixir: [1.13.x]
elixir: [1.14.x]

steps:
- name: ☁️ Checkout repository
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ jobs:
strategy:
matrix:
otp: [25.x]
elixir: [1.13.x]
elixir: [1.14.x]
services:
db:
image: postgres:14.1
Expand Down
4 changes: 2 additions & 2 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
erlang 25.0.2
elixir 1.13.4-otp-25
elixir 1.14.2-otp-25
erlang 25.1.2
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ local machine for development and testing purposes.
The following software is required to be installed on your system:

- [Erlang 25+](https://www.erlang.org/downloads)
- [Elixir 1.13+](https://elixir-lang.org/install.html)
- [Elixir 1.14+](https://elixir-lang.org/install.html)

We recommend using [asdf version manager][asdf-vm] to install and manage all
the programming languages' requirements.
Expand Down
3 changes: 2 additions & 1 deletion lib/cesium_cup/teams/player.ex
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule CesiumCup.Teams.Player do

alias CesiumCup.Uploaders

@required_fields ~w(date_of_birth name course position height weight team_id captain)a
@required_fields ~w(date_of_birth name nationality course position height weight team_id captain)a

@optional_fields []

Expand All @@ -19,6 +19,7 @@ defmodule CesiumCup.Teams.Player do
field :date_of_birth, :date
field :name, :string
field :course, :string
field :nationality, :string
field :height, :decimal
field :weight, :decimal
field :captain, :boolean, default: false
Expand Down
42 changes: 27 additions & 15 deletions lib/cesium_cup_web/live/home_live/index.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -63,22 +63,34 @@
<div>
<div class="border-b border-gray-200">
<nav class="-mb-px flex space-x-8" aria-label="Tabs">
<%= live_redirect("Group Stage", to: "?tab=group", class: "#{if @tab == "group" do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md") %>
<%= live_patch("Knockout Stage", to: "?tab=knockout_stage", class: "#{if @tab == "knockout_stage" do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md") %>
<%= live_redirect("Group Stage",
to: "?tab=group",
class:
"#{if @tab == "group" do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md"
) %>
<%= live_patch("Knockout Stage",
to: "?tab=knockout_stage",
class:
"#{if @tab == "knockout_stage" do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md"
) %>
<%= for round <- @elimination_rounds do %>
<%= live_redirect(round.name, to: "?tab=#{round.name}", class: "#{if @tab == round.name do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} show lg:hidden whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md") %>
<%= live_redirect(round.name,
to: "?tab=#{round.name}",
class:
"#{if @tab == round.name do
"border-quinary text-gray-900"
else
"border-transparent text-gray-500 hover:text-gray-700 hover:border-gray-300"
end} show lg:hidden whitespace-nowrap py-4 px-1 border-b-4 font-medium text-md"
) %>
<% end %>
</nav>
</div>
Expand Down
4 changes: 4 additions & 0 deletions lib/cesium_cup_web/live/player_live/form_component.ex
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ defmodule CesiumCupWeb.PlayerLive.FormComponent do
alias CesiumCup.Teams

@extensions_whitelist ~w(.jpg .jpeg .gif .png)
@nationalities File.read!("priv/fake/nationalities.txt") |> String.split("\n")
@positions ~w(goalkeeper fixed wing target)a

@impl true
def mount(socket) do
Expand All @@ -23,6 +25,8 @@ defmodule CesiumCupWeb.PlayerLive.FormComponent do
socket
|> assign(assigns)
|> assign(:teams, teams)
|> assign(:nationalities, @nationalities)
|> assign(:positions, @positions)
|> assign(:changeset, changeset)}
end

Expand Down
14 changes: 11 additions & 3 deletions lib/cesium_cup_web/live/player_live/form_component.html.heex
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
<div class="">
<%= live_file_input(@uploads.picture, class: "hidden") %>
<a onclick={"document.getElementById('#{@uploads.picture.ref}').click()"}>
<div class={"#{if length(@uploads.picture.entries) != 0 do
<div class={
"#{if length(@uploads.picture.entries) != 0 do
"hidden"
end} ring-4 ring-white rounded-lg cursor-pointer bg-secondary sm:w-24 group sm:h-24 transition-color duration-200 ease-in hover:bg-tertiary"}>
end} ring-4 ring-white rounded-lg cursor-pointer bg-secondary sm:w-24 group sm:h-24 transition-color duration-200 ease-in hover:bg-tertiary"
}>
<div class="flex justify-center items-center w-full h-full"></div>
</div>
<section>
Expand All @@ -34,6 +36,12 @@
<%= error_tag(f, :name) %>
</div>

<div class="mb-4">
<label for="name" class="block mb-1 text-sm font-medium text-gray-900">Nationality</label>
<%= select(f, :nationality, @nationalities, prompt: "Choose a Nationality", class: "bg-white border border-gray-200 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5") %>
<%= error_tag(f, :nationality) %>
</div>

<div class="mb-4">
<label for="course" class="block mb-1 text-sm font-medium text-gray-900">Course</label>
<%= text_input(f, :course, class: "bg-white border border-gray-200 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5") %>
Expand All @@ -48,7 +56,7 @@

<div class="mb-4">
<label for="position" class="block mb-1 text-sm font-medium text-gray-900">Position</label>
<%= text_input(f, :position, class: "bg-white border border-gray-200 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5") %>
<%= select(f, :position, @positions, prompt: "Choose a position", class: "bg-white border border-gray-200 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5") %>
<%= error_tag(f, :position) %>
</div>

Expand Down
224 changes: 224 additions & 0 deletions priv/fake/nationalities.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
Afghans
Albanians
Algerians
Americans
Andorrans
Angolans
Antiguans and Barbudans
Argentines
Armenians
Arubans
Australians
Austrians
Azerbaijanis
Bahamians
Bahrainis
Bangladeshis
Barbadians
Basques
Belarusians
Belgians
Belizeans
Beninese
Bermudians
Bhutanese
Bolivians
Bosniaks
Bosnians and Herzegovinians
Botswana
Brazilians
Bretons
British
British Virgin Islanders
Bruneians
Bulgarians
Macedonian Bulgarians
Burkinabés
Burmese
Burundians
Cambodians
Cameroonians
Canadians
Catalans
Cape Verdeans
List of Caymanians
Chaldeans
Chadians
Chileans
Chinese
Colombians
Comorians
Congolese (DRC)
Congolese (RotC)
Costa Ricans
Croats
Cubans
Cypriots
Czechs
Danes
Greenlanders
Djiboutians
Dominicans (Commonwealth)
Dominicans (Republic)
Dutch
East Timorese
Ecuadorians
Egyptians
Emiratis
English
Equatoguineans
Eritreans
Estonians
Ethiopians
Falkland Islanders
Faroese
Fijians
Finns
Finnish Swedish
Filipinos
French citizens
Gabonese
Gambians
Georgians
Germans
Baltic Germans
Ghanaians
Gibraltarians
Greeks
Greek Macedonians
Grenadians
Guatemalans
Guianese (French)
Guineans
Guinea-Bissau nationals
Guyanese
Haitians
Hondurans
Hong Kongers
Hungarians
Icelanders
I-Kiribati
Indians
Indonesians
Iranians
Iraqis
Irish
Israelis
Italians
Ivoirians
Jamaicans
Japanese
Jordanians
Kazakhs
Kenyans
Kosovars
Kuwaitis
Kyrgyzs
Lao
Latvians
Lebanese
Liberians
Libyans
Liechtensteiners
Lithuanians
Luxembourgers
Macao
Macedonians
Malagasy
Malawians
Malaysians
Maldivians
Malians
Maltese
Manx
Marshallese
Mauritanians
Mauritians
Mexicans
Micronesians
Moldovans
Monégasque
Mongolians
Montenegrins
Moroccans
Mozambicans
Namibians
Nauruans
Nepalese
New Zealanders
Nicaraguans
Nigeriens
Nigerians
Norwegians
Omani
Pakistanis
Palauans
Palestinians
Panamanians
Papua New Guineans
Paraguayans
Peruvians
Poles
Portuguese
Puerto Ricans
Qatari
Quebecers
Réunionnais
Romanians
Russians
Baltic Russians
Rwandans
Saint Kitts and Nevis
Saint Lucians
Salvadorans
Sammarinese
Samoans
São Tomé and Príncipe
Saudis
Scots
Senegalese
Serbs
Seychellois
Sierra Leoneans
Singaporeans
Slovaks
Slovenes
Solomon Islanders
Somalis
Somalilanders
Sotho
South Africans
Spaniards
Sri Lankans
Sudanese
Surinamese
Swazi
Swedes
Swiss
Syriacs
Syrians
Taiwanese
Tamils
Tajik
Tanzanians
Thais
Tibetans
Tobagonians
Togolese
Tongans
Trinidadians
Tunisians
Turks
Tuvaluans
Ugandans
Ukrainians
Uruguayans
Uzbeks
Vanuatuans
Venezuelans
Vietnamese
Vincentians
Welsh
Yemenis
Zambians
Zimbabweans
3 changes: 2 additions & 1 deletion priv/repo/migrations/20221209225201_create_players.exs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ defmodule CesiumCup.Repo.Migrations.CreatePlayers do
create table(:players, primary_key: false) do
add :id, :binary_id, primary_key: true

add :name, :string
add :name, :string, null: false
add :nationality, :string, null: false
add :course, :string
add :date_of_birth, :date
add :position, :string
Expand Down
Loading

0 comments on commit 9ca8f34

Please sign in to comment.