From 8d3da167ef27dd7ee9da73549315517e7dfc180b Mon Sep 17 00:00:00 2001 From: Axel Clark Date: Sun, 25 Feb 2024 13:46:09 -0800 Subject: [PATCH 1/2] Fix typo in seeds championship data --- priv/repo/csv_seed_data/championships.csv | 24 +++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/priv/repo/csv_seed_data/championships.csv b/priv/repo/csv_seed_data/championships.csv index ff90f961..d09def77 100644 --- a/priv/repo/csv_seed_data/championships.csv +++ b/priv/repo/csv_seed_data/championships.csv @@ -34,20 +34,20 @@ CL,overall,233,317,407,6,,false,2018,NA,NA,NA NHL,overall,341,341,405,7,,false,2018,NA,NA,NA NBA,overall,341,341,405,8,,false,2018,NA,NA,NA PGA,overall,469,469,477,9,,false,2018,NA,NA,NA -Masters,event,345,345,353,9,9,false,2018,NA,NA,NA -US Open,event,414,414,422,9,9,false,2018,NA,NA,NA -British Open,event,449,449,457,9,9,false,2018,NA,NA,NA -PGA Championship,event,469,469,477,9,9,false,2018,NA,NA,NA +Masters,event,345,345,353,9,35,false,2018,NA,NA,NA +US Open,event,414,414,422,9,35,false,2018,NA,NA,NA +British Open,event,449,449,457,9,35,false,2018,NA,NA,NA +PGA Championship,event,469,469,477,9,35,false,2018,NA,NA,NA EPL,overall,341,341,395,10,,false,2018,NA,NA,NA LLWS,overall,481,481,491,11,,true,2018,NA,NA,NA MT,overall,485,485,474,12,,false,2018,NA,NA,NA -Australian Open (M),event,263,263,283,12,16,false,2018,NA,NA,NA -French Open (M),event,396,396,408,12,16,false,2018,NA,NA,NA -Wimbledon (M),event,430,430,450,12,16,false,2018,NA,NA,NA -US Open(M),event,485,485,474,12,16,false,2018,NA,NA,NA +Australian Open (M),event,263,263,283,12,42,false,2018,NA,NA,NA +French Open (M),event,396,396,408,12,42,false,2018,NA,NA,NA +Wimbledon (M),event,430,430,450,12,42,false,2018,NA,NA,NA +US Open(M),event,485,485,474,12,42,false,2018,NA,NA,NA WT,overall,485,485,473,13,,false,2018,NA,NA,NA -Australian Open (W),event,263,263,282,13,21,false,2018,NA,NA,NA -French Open (W),event,396,396,407,13,21,false,2018,NA,NA,NA -Wimbledon (W),event,430,430,449,13,21,false,2018,NA,NA,NA -US Open (W),event,485,485,473,13,21,false,2018,NA,NA,NA +Australian Open (W),event,263,263,282,13,47,false,2018,NA,NA,NA +French Open (W),event,396,396,407,13,47,false,2018,NA,NA,NA +Wimbledon (W),event,430,430,449,13,47,false,2018,NA,NA,NA +US Open (W),event,485,485,473,13,47,false,2018,NA,NA,NA MLB,overall,492,492,555,14,,false,2018,NA,NA,NA From 6837dcaca292dce62313e23b461f9bd8af8d684b Mon Sep 17 00:00:00 2001 From: Axel Clark Date: Sat, 24 Feb 2024 20:51:36 -0800 Subject: [PATCH 2/2] Convert championship controller to html * Update championship index action * Update championships controller show action * Update championship live for components * Remove unused championship code and add back tests --- lib/ex338_web/components/core_components.ex | 11 + .../controllers/championship_controller.ex | 6 +- .../controllers/championship_html.ex | 508 ++++++++++++++++++ lib/ex338_web/live/championship_live.ex | 61 ++- .../championship/draft_table.html.leex | 47 -- .../championship/final_results_table.html.eex | 30 -- .../templates/championship/index.html.eex | 11 - .../championship/results_table.html.eex | 36 -- .../templates/championship/show.html.eex | 192 ------- .../championship/slots_standings.html.eex | 36 -- .../championship/slots_table.html.eex | 41 -- .../templates/championship/table.html.eex | 54 -- lib/ex338_web/views/championship_view.ex | 63 --- .../championship_html_test.exs} | 38 +- 14 files changed, 600 insertions(+), 534 deletions(-) create mode 100644 lib/ex338_web/controllers/championship_html.ex delete mode 100644 lib/ex338_web/templates/championship/draft_table.html.leex delete mode 100644 lib/ex338_web/templates/championship/final_results_table.html.eex delete mode 100644 lib/ex338_web/templates/championship/index.html.eex delete mode 100644 lib/ex338_web/templates/championship/results_table.html.eex delete mode 100644 lib/ex338_web/templates/championship/show.html.eex delete mode 100644 lib/ex338_web/templates/championship/slots_standings.html.eex delete mode 100644 lib/ex338_web/templates/championship/slots_table.html.eex delete mode 100644 lib/ex338_web/templates/championship/table.html.eex delete mode 100644 lib/ex338_web/views/championship_view.ex rename test/ex338_web/{views/championship_view_test.exs => controllers/championship_html_test.exs} (79%) diff --git a/lib/ex338_web/components/core_components.ex b/lib/ex338_web/components/core_components.ex index 0d7ddd3f..c75917c2 100644 --- a/lib/ex338_web/components/core_components.ex +++ b/lib/ex338_web/components/core_components.ex @@ -777,6 +777,17 @@ defmodule Ex338Web.CoreComponents do attr :class, :string, default: nil slot :inner_block, required: true + def section_header(assigns) do + ~H""" +

+ <%= render_slot(@inner_block) %> +

+ """ + end + + attr :class, :string, default: nil + slot :inner_block, required: true + def legacy_table(assigns) do ~H"""
diff --git a/lib/ex338_web/controllers/championship_controller.ex b/lib/ex338_web/controllers/championship_controller.ex index cfe2c424..7abe9f93 100644 --- a/lib/ex338_web/controllers/championship_controller.ex +++ b/lib/ex338_web/controllers/championship_controller.ex @@ -1,5 +1,5 @@ defmodule Ex338Web.ChampionshipController do - use Ex338Web, :controller + use Ex338Web, :controller_html alias Ex338.Championships alias Ex338.FantasyLeagues @@ -7,7 +7,7 @@ defmodule Ex338Web.ChampionshipController do def index(conn, %{"fantasy_league_id" => league_id}) do render( conn, - "index.html", + :index, championships: Championships.all_for_league(league_id), fantasy_league: FantasyLeagues.get(league_id) ) @@ -16,7 +16,7 @@ defmodule Ex338Web.ChampionshipController do def show(conn, %{"fantasy_league_id" => league_id, "id" => id}) do render( conn, - "show.html", + :show, championship: Championships.get_championship_by_league(id, league_id), fantasy_league: FantasyLeagues.get(league_id) ) diff --git a/lib/ex338_web/controllers/championship_html.ex b/lib/ex338_web/controllers/championship_html.ex new file mode 100644 index 00000000..736f413c --- /dev/null +++ b/lib/ex338_web/controllers/championship_html.ex @@ -0,0 +1,508 @@ +defmodule Ex338Web.ChampionshipHTML do + use Ex338Web, :html + + def index(assigns) do + ~H""" + <.page_header class="sm:mb-6"> + <%= @fantasy_league.year %> Championships + + + <.championship_table + championships={filter_category(@championships, "overall")} + conn={@conn} + fantasy_league={@fantasy_league} + /> + + <.section_header> + Championship Events + + + <.championship_table + championships={filter_category(@championships, "event")} + conn={@conn} + fantasy_league={@fantasy_league} + /> + """ + end + + defp championship_table(assigns) do + ~H""" + <.legacy_table class="lg:max-w-4xl"> + + + <.legacy_th> + Title + + <.legacy_th class="hidden sm:table-cell"> + Sports League + + <.legacy_th> + Waiver Deadline* + + <.legacy_th> + Trade Deadline* + + <.legacy_th> + Date + + + + + <%= for championship <- @championships do %> + + <.legacy_td class="text-indigo-700" style="word-break: break-word;"> + <.link href={ + ~p"/fantasy_leagues/#{@fantasy_league.id}/championships/#{championship.id}" + }> + <%= championship.title %> + + + <.legacy_td class="hidden sm:table-cell"> +
+
+ <%= championship.sports_league.abbrev %> +
+ + <%= if transaction_deadline_icon(championship) != "" do %> +
+ <%= transaction_deadline_icon(championship) %> +
+ <% end %> +
+ + <.legacy_td> + <%= short_datetime_pst(championship.waiver_deadline_at) %> + + <.legacy_td> + <%= short_datetime_pst(championship.trade_deadline_at) %> + + <.legacy_td> + <%= short_date_pst(championship.championship_at) %> + + + <% end %> + + +

+ * All dates and times are in Pacific Standard Time (PST)/Pacific Daylight Time (PDT). +

+ """ + end + + def show(assigns) do + ~H""" +
+
+
+
+

+
+
+ <%= @championship.title %> +
+ <%= if transaction_deadline_icon(@championship) != "" do %> +
+ <%= transaction_deadline_icon(@championship) %> +
+ <% end %> +
+

+
+ <%= if show_create_slots(@current_user, @championship) do %> +
+ <.link + href={ + ~p"/fantasy_leagues/#{@fantasy_league.id}/championship_slot_admin?#{%{championship_id: @championship.id}}" + } + class="bg-transparent hover:bg-indigo-500 text-indigo-600 text-sm font-medium hover:text-white py-2 px-4 border border-indigo-600 hover:border-transparent rounded" + method="post" + data-confirm="Please confirm to create roster slots" + > + Create Roster Slots + +
+ <% end %> + + <%= if show_create_picks(@current_user, @championship) do %> +
+ <.link + href={ + ~p"/fantasy_leagues/#{@fantasy_league.id}/in_season_draft_order?#{%{championship_id: @championship.id}}" + } + class="bg-transparent hover:bg-indigo-500 text-indigo-600 text-sm font-medium hover:text-white py-2 px-4 border border-indigo-600 hover:border-transparent rounded" + method="post" + data-confirm="Please confirm to create draft picks" + > + Create Draft Picks + +
+ <% end %> +
+
+
+
+
+
+ SportsLeague +
+
+ <%= @championship.sports_league.league_name %> +
+
+
+
+ Waiver Deadline +
+
+ <%= short_datetime_pst(@championship.waiver_deadline_at) %> +
+
+
+
+ Trade Deadline +
+
+ <%= short_datetime_pst(@championship.trade_deadline_at) %> +
+
+ <%= if @championship.draft_starts_at do %> +
+
+ Draft Starts At +
+
+ <%= short_datetime_pst(@championship.draft_starts_at) %> +
+
+
+
+ Time Limit For Each Pick +
+
+ <%= @championship.max_draft_mins %> Minutes +
+
+ <% end %> +
+
+ Championship Date +
+
+ <%= short_date_pst(@championship.championship_at) %> +
+
+
+
+ Timezones +
+
+ All dates and times are in Pacific Standard Time (PST)/Pacific Daylight Time (PDT). +
+
+
+
+
+ +
+ <%= if @championship.events == [] do %> +
+ <.section_header> + <%= @championship.title %> Results + + + <.results_table championship={@championship} /> +
+ <% else %> +
+ <.section_header> + <%= @championship.title %> Results + + + <.final_results_table championship={@championship} /> +
+ +
+ <.section_header> + <%= @championship.title %> Overall Standings + + + <.slots_standings championship={@championship} /> +
+ <% end %> + + <%= if @championship.championship_slots !== [] do %> +
+ <.section_header> + <%= @championship.title %> Roster Slots + + + <.slots_table conn={@conn} current_user={@current_user} championship={@championship} /> +
+ <% end %> + + <%= for event <- @championship.events do %> +
+ <.section_header> + <%= event.title %> Results + + + <.results_table championship={event} /> +
+ + <%= if event.championship_slots !== [] do %> +
+ <.section_header> + <%= event.title %> Roster Slots + + + <.slots_table conn={@conn} current_user={@current_user} championship={event} /> +
+ <% end %> + <% end %> + + <%= if @championship.in_season_draft do %> +
+ <.section_header> + <%= @championship.title %> Draft + + + <%= live_render( + @conn, + Ex338Web.ChampionshipLive, + session: %{ + "current_user_id" => maybe_fetch_current_user_id(@current_user), + "championship_id" => @championship.id, + "fantasy_league_id" => @fantasy_league.id + } + ) %> +
+ <% end %> +
+ """ + end + + defp results_table(assigns) do + ~H""" + <.legacy_table class="md:max-w-3xl"> + + + <.legacy_th> + Rank + + <.legacy_th> + Points + + <.legacy_th> + Fantasy Player + + <.legacy_th> + Owner + + + + + <%= for result <- @championship.championship_results do %> + + <.legacy_td> + <%= result.rank %> + + <.legacy_td> + <%= result.points %> + + <.legacy_td> + <%= result.fantasy_player.player_name %> + + <.legacy_td> + <%= get_team_name(result) %> + + + <% end %> + + + """ + end + + defp final_results_table(assigns) do + ~H""" + <.legacy_table class="md:max-w-2xl"> + + + <.legacy_th> + Rank + + <.legacy_th> + Points + + <.legacy_th> + Fantasy Team + + + + + <%= for result <- @championship.champ_with_events_results do %> + + <.legacy_td> + <%= result.rank %> + + <.legacy_td> + <%= result.points %> + + <.legacy_td> + <%= result.fantasy_team.team_name %> + + + <% end %> + + + """ + end + + defp slots_standings(assigns) do + ~H""" + <.legacy_table class="md:max-w-2xl"> + + + <.legacy_th> + Rank + + <.legacy_th> + Fantasy Team + + <.legacy_th> + Slot + + <.legacy_th> + Points + + + + + <%= for slot <- @championship.slot_standings do %> + + <.legacy_td> + <%= slot.rank %> + + <.legacy_td> + <%= slot.team_name %> + + <.legacy_td> + <%= slot.slot %> + + <.legacy_td> + <%= slot.points %> + + + <% end %> + + + """ + end + + defp slots_table(assigns) do + ~H""" + <.legacy_table class="md:max-w-2xl"> + + + <.legacy_th> + Fantasy Team + + <.legacy_th> + Slot + + <.legacy_th> + Fantasy Player + + <%= if admin?(@current_user) do %> + <.legacy_th> + Action + + <% end %> + + + + <%= for slot <- @championship.championship_slots do %> + + <.legacy_td> + <%= slot.roster_position.fantasy_team.team_name %> + + <.legacy_td> + <%= slot.slot %> + + <.legacy_td> + <%= slot.roster_position.fantasy_player.player_name %> + + <%= if admin?(@current_user) do %> + <.legacy_td> + <.link + href={~p"/admin/#{"championships"}/#{"championship_slot"}/#{slot.id}"} + class="font-medium text-indigo-600 hover:text-indigo-500 transition duration-150 ease-in-out" + > + Edit + + + <% end %> + + <% end %> + + + """ + end + + def get_team_name(%{fantasy_player: %{roster_positions: [position]}}) do + position.fantasy_team.team_name + end + + def get_team_name(_) do + "-" + end + + def filter_category(championships, category) do + Enum.filter(championships, &(&1.category == category)) + end + + def show_create_slots(%{admin: true}, %{category: "event", championship_slots: []}) do + true + end + + def show_create_slots(_user, _championship) do + false + end + + def show_create_picks(%{admin: true}, %{in_season_draft: true, in_season_draft_picks: []}) do + true + end + + def show_create_picks(_user, _championship) do + false + end + + def display_drafted_at_or_pick_due_at(%{available_to_pick?: false, drafted_player_id: nil}) do + "---" + end + + def display_drafted_at_or_pick_due_at( + %{available_to_pick?: true, drafted_player_id: nil} = assigns + ) do + if assigns.over_time? do + ~H""" +
+ <%= short_time_secs_pst(assigns.pick_due_at) %>* +
+ """ + else + ~H""" +
+ <%= short_time_secs_pst(assigns.pick_due_at) %>* +
+ """ + end + end + + def display_drafted_at_or_pick_due_at(%{drafted_at: nil}) do + "---" + end + + def display_drafted_at_or_pick_due_at(pick) do + short_time_pst(pick.drafted_at) + end +end diff --git a/lib/ex338_web/live/championship_live.ex b/lib/ex338_web/live/championship_live.ex index 6f41b9e0..dd5d3994 100644 --- a/lib/ex338_web/live/championship_live.ex +++ b/lib/ex338_web/live/championship_live.ex @@ -2,11 +2,13 @@ defmodule Ex338Web.ChampionshipLive do @moduledoc false use Ex338Web, :live_view + import Ex338Web.ChampionshipHTML, only: [display_drafted_at_or_pick_due_at: 1] + import Ex338Web.CoreComponents + alias Ex338.Accounts alias Ex338.Championships alias Ex338.FantasyLeagues alias Ex338.InSeasonDraftPicks - alias Ex338Web.ChampionshipView def mount(_params, session, socket) do if connected?(socket) do @@ -38,7 +40,58 @@ defmodule Ex338Web.ChampionshipLive do end def render(assigns) do - ChampionshipView.render("draft_table.html", assigns) + ~H""" + <.legacy_table class="md:max-w-2xl"> + + + <.legacy_th> + Order + + <.legacy_th> + Drafted / Due* + + <.legacy_th> + Fantasy Team + + <.legacy_th> + Fantasy Player + + + + + <%= for pick <- @championship.in_season_draft_picks do %> + + <.legacy_td> + <%= pick.position %> + + <.legacy_td> + <%= display_drafted_at_or_pick_due_at(pick) %> + + <.legacy_td style="word-break: break-word;"> + <%= if pick.draft_pick_asset.fantasy_team do %> + <%= fantasy_team_link(@socket, pick.draft_pick_asset.fantasy_team) %> + <% end %> + <%= if admin?(@current_user) do %> + <%= " - " <> + display_autodraft_setting(pick.draft_pick_asset.fantasy_team.autodraft_setting) %> + <% end %> + + <.legacy_td> + <%= if pick.drafted_player do %> + <%= pick.drafted_player.player_name %> + <% else %> + <%= if pick.available_to_pick? && (owner?(@current_user, pick) || admin?(@current_user)) do %> + <.link href={~p"/in_season_draft_picks/#{pick}/edit"} class="text-indigo-700"> + Submit Pick + + <% end %> + <% end %> + + + <% end %> + + + """ end def handle_info(:refresh, socket) do @@ -96,4 +149,8 @@ defmodule Ex338Web.ChampionshipLive do end defp maybe_put_flash(socket, _, _), do: socket + + def display_autodraft_setting(:single), do: "⚠️ Make Pick & Pause" + def display_autodraft_setting(:on), do: "✅ On" + def display_autodraft_setting(:off), do: "❌ Off" end diff --git a/lib/ex338_web/templates/championship/draft_table.html.leex b/lib/ex338_web/templates/championship/draft_table.html.leex deleted file mode 100644 index 1565dd09..00000000 --- a/lib/ex338_web/templates/championship/draft_table.html.leex +++ /dev/null @@ -1,47 +0,0 @@ -<%= table class: "md:max-w-2xl" do %> - - - <%= table_th do %> - Order - <% end %> - <%= table_th do %> - Drafted / Due* - <% end %> - <%= table_th do %> - Fantasy Team - <% end %> - <%= table_th do %> - Fantasy Player - <% end %> - - - - <%= for pick <- @championship.in_season_draft_picks do %> - - <%= table_td do %> - <%= pick.position %> - <% end %> - <%= table_td do %> - <%= display_drafted_at_or_pick_due_at(pick) %> - <% end %> - <%= table_td style: "word-break: break-word;" do %> - <%= if pick.draft_pick_asset.fantasy_team do %> - <%= fantasy_team_link(@socket, pick.draft_pick_asset.fantasy_team) %> - <% end %> - <%= if admin?(@current_user) do %> - <%= " - " <> display_autodraft_setting(pick.draft_pick_asset.fantasy_team.autodraft_setting) %> - <% end %> - <% end %> - <%= table_td do %> - <%= if pick.drafted_player do %> - <%= pick.drafted_player.player_name %> - <% else %> - <%= if pick.available_to_pick? && (owner?(@current_user, pick) || admin?(@current_user)) do %> - <%= link "Submit Pick", to: ~p"/in_season_draft_picks/#{pick}/edit", class: "text-indigo-700" %> - <% end %> - <% end %> - <% end %> - - <% end %> - -<% end %> diff --git a/lib/ex338_web/templates/championship/final_results_table.html.eex b/lib/ex338_web/templates/championship/final_results_table.html.eex deleted file mode 100644 index 238f7c03..00000000 --- a/lib/ex338_web/templates/championship/final_results_table.html.eex +++ /dev/null @@ -1,30 +0,0 @@ -<%= table class: "md:max-w-2xl" do %> - - - <%= table_th do %> - Rank - <% end %> - <%= table_th do %> - Points - <% end %> - <%= table_th do %> - Fantasy Team - <% end %> - - - - <%= for result <- @championship.champ_with_events_results do %> - - <%= table_td do %> - <%= result.rank %> - <% end %> - <%= table_td do %> - <%= result.points %> - <% end %> - <%= table_td do %> - <%= result.fantasy_team.team_name %> - <% end %> - - <% end %> - -<% end %> diff --git a/lib/ex338_web/templates/championship/index.html.eex b/lib/ex338_web/templates/championship/index.html.eex deleted file mode 100644 index 357ff61d..00000000 --- a/lib/ex338_web/templates/championship/index.html.eex +++ /dev/null @@ -1,11 +0,0 @@ -<%= page_header class: "sm:mb-6" do %> - <%= @fantasy_league.year %> Championships -<% end %> - -<%= render "table.html", championships: filter_category(@championships, "overall"), conn: @conn, fantasy_league: @fantasy_league %> - -<%= section_header do %> - Championship Events -<% end %> - -<%= render "table.html", championships: filter_category(@championships, "event"), conn: @conn, fantasy_league: @fantasy_league %> diff --git a/lib/ex338_web/templates/championship/results_table.html.eex b/lib/ex338_web/templates/championship/results_table.html.eex deleted file mode 100644 index 3fcf95c2..00000000 --- a/lib/ex338_web/templates/championship/results_table.html.eex +++ /dev/null @@ -1,36 +0,0 @@ -<%= table class: "md:max-w-3xl" do %> - - - <%= table_th do %> - Rank - <% end %> - <%= table_th do %> - Points - <% end %> - <%= table_th do %> - Fantasy Player - <% end %> - <%= table_th do %> - Owner - <% end %> - - - - <%= for result <- @championship.championship_results do %> - - <%= table_td do %> - <%= result.rank %> - <% end %> - <%= table_td do %> - <%= result.points %> - <% end %> - <%= table_td do %> - <%= result.fantasy_player.player_name %> - <% end %> - <%= table_td do %> - <%= get_team_name(result) %> - <% end %> - - <% end %> - -<% end %> diff --git a/lib/ex338_web/templates/championship/show.html.eex b/lib/ex338_web/templates/championship/show.html.eex deleted file mode 100644 index c6f4f0b0..00000000 --- a/lib/ex338_web/templates/championship/show.html.eex +++ /dev/null @@ -1,192 +0,0 @@ -
-
-
-
-

-
-
- <%= @championship.title %> -
- <%= if transaction_deadline_icon(@championship) != "" do %> -
- <%= transaction_deadline_icon(@championship) %> -
- <% end %> -
-

-
- <%= if show_create_slots(@current_user, @championship) do %> -
- <%= - link "Create Roster Slots", - to: ~p"/fantasy_leagues/#{@fantasy_league.id}/championship_slot_admin?#{%{championship_id: @championship.id}}", - class: "bg-transparent hover:bg-indigo-500 text-indigo-600 text-sm font-medium hover:text-white py-2 px-4 border border-indigo-600 hover:border-transparent rounded", - method: :post, data: [confirm: "Please confirm to create roster slots"] %> - -
- <% end %> - - <%= if show_create_picks(@current_user, @championship) do %> -
- <%= - link "Create Draft Picks", - to: ~p"/fantasy_leagues/#{@fantasy_league.id}/in_season_draft_order?#{%{championship_id: @championship.id}}", - class: "bg-transparent hover:bg-indigo-500 text-indigo-600 text-sm font-medium hover:text-white py-2 px-4 border border-indigo-600 hover:border-transparent rounded", - method: :post, data: [confirm: "Please confirm to create draft picks"] %> - -
- <% end %> -
-
-
-
-
-
- SportsLeague -
-
- <%= @championship.sports_league.league_name %> -
-
-
-
- Waiver Deadline -
-
- <%= short_datetime_pst(@championship.waiver_deadline_at) %> -
-
-
-
- Trade Deadline -
-
- <%= short_datetime_pst(@championship.trade_deadline_at) %> -
-
- <%= if @championship.draft_starts_at do %> -
-
- Draft Starts At -
-
- <%= short_datetime_pst(@championship.draft_starts_at) %> -
-
-
-
- Time Limit For Each Pick -
-
- <%= @championship.max_draft_mins %> Minutes -
-
- <% end %> -
-
- Championship Date -
-
- <%= short_date_pst(@championship.championship_at) %> -
-
-
-
- Timezones -
-
- All dates and times are in Pacific Standard Time (PST)/Pacific Daylight Time (PDT). -
-
-
-
- - -
- -
- - <%= if @championship.events == [] do %> - -
- <%= section_header do %> - <%= @championship.title %> Results - <% end %> - - <%= render "results_table.html", championship: @championship %> -
- - <% else %> - -
- <%= section_header do %> - <%= @championship.title %> Results - <% end %> - - <%= render "final_results_table.html", championship: @championship %> -
- -
- <%= section_header do %> - <%= @championship.title %> Overall Standings - <% end %> - - <%= render "slots_standings.html", championship: @championship %> -
- - <% end %> - - <%= if @championship.championship_slots !== [] do %> -
- <%= section_header do %> - <%= @championship.title %> Roster Slots - <% end %> - - <%= render "slots_table.html", conn: @conn, current_user: @current_user, championship: @championship %> -
- <% end %> - - - <%= for event <- @championship.events do %> - -
- <%= section_header do %> - <%= event.title %> Results - <% end %> - - <%= render "results_table.html", championship: event %> -
- - <%= if event.championship_slots !== [] do %> - -
- <%= section_header do %> - <%= event.title %> Roster Slots - <% end %> - - <%= render "slots_table.html", conn: @conn, current_user: @current_user, championship: event %> -
- <% end %> - <% end %> - - <%= if @championship.in_season_draft do %> -
- <%= section_header do %> - <%= @championship.title %> Draft - - <% end %> - - <%= - live_render( - @conn, - Ex338Web.ChampionshipLive, - session: %{ - "current_user_id" => maybe_fetch_current_user_id(@current_user), - "championship_id" => @championship.id, - "fantasy_league_id" => @fantasy_league.id - } - ) - %> -
- <% end %> -
diff --git a/lib/ex338_web/templates/championship/slots_standings.html.eex b/lib/ex338_web/templates/championship/slots_standings.html.eex deleted file mode 100644 index 86b319bc..00000000 --- a/lib/ex338_web/templates/championship/slots_standings.html.eex +++ /dev/null @@ -1,36 +0,0 @@ -<%= table class: "md:max-w-2xl" do %> - - - <%= table_th do %> - Rank - <% end %> - <%= table_th do %> - Fantasy Team - <% end %> - <%= table_th do %> - Slot - <% end %> - <%= table_th do %> - Points - <% end %> - - - - <%= for slot <- @championship.slot_standings do %> - - <%= table_td do %> - <%= slot.rank %> - <% end %> - <%= table_td do %> - <%= slot.team_name %> - <% end %> - <%= table_td do %> - <%= slot.slot %> - <% end %> - <%= table_td do %> - <%= slot.points %> - <% end %> - - <% end %> - -<% end %> diff --git a/lib/ex338_web/templates/championship/slots_table.html.eex b/lib/ex338_web/templates/championship/slots_table.html.eex deleted file mode 100644 index ac452cc1..00000000 --- a/lib/ex338_web/templates/championship/slots_table.html.eex +++ /dev/null @@ -1,41 +0,0 @@ -<%= table class: "md:max-w-2xl" do %> - - - <%= table_th do %> - Fantasy Team - <% end %> - <%= table_th do %> - Slot - <% end %> - <%= table_th do %> - Fantasy Player - <% end %> - <%= if admin?(@current_user) do %> - <%= table_th do %> - Action - <% end %> - <% end %> - - - - <%= for slot <- @championship.championship_slots do %> - - <%= table_td do %> - <%= slot.roster_position.fantasy_team.team_name %> - <% end %> - <%= table_td do %> - <%= slot.slot %> - <% end %> - <%= table_td do %> - <%= slot.roster_position.fantasy_player.player_name %> - <% end %> - <%= if admin?(@current_user) do %> - <%= table_td do %> - <%= link "Edit", to: ~p"/admin/#{"championships"}/#{"championship_slot"}/#{slot.id}", - class: "font-medium text-indigo-600 hover:text-indigo-500 transition duration-150 ease-in-out" %> - <% end %> - <% end %> - - <% end %> - -<% end %> diff --git a/lib/ex338_web/templates/championship/table.html.eex b/lib/ex338_web/templates/championship/table.html.eex deleted file mode 100644 index fafc58ac..00000000 --- a/lib/ex338_web/templates/championship/table.html.eex +++ /dev/null @@ -1,54 +0,0 @@ -<%= table class: "lg:max-w-4xl" do %> - - - <%= table_th do %> - Title - <% end %> - <%= table_th class: "hidden sm:table-cell" do %> - Sports League - <% end %> - <%= table_th do %> - Waiver Deadline* - <% end %> - <%= table_th do %> - Trade Deadline* - <% end %> - <%= table_th do %> - Date - <% end %> - - - - <%= for championship <- @championships do %> - - <%= table_td class: "text-indigo-700", style: "word-break: break-word;" do %> - <%= link championship.title, to: ~p"/fantasy_leagues/#{@fantasy_league.id}/championships/#{championship.id}" %> - <% end %> - <%= table_td class: "hidden sm:table-cell" do %> -
-
- <%= championship.sports_league.abbrev %> -
- <%= if transaction_deadline_icon(championship) != "" do %> -
- <%= transaction_deadline_icon(championship) %> -
- <% end %> -
- <% end %> - <%= table_td do %> - <%= short_datetime_pst(championship.waiver_deadline_at) %> - <% end %> - <%= table_td do %> - <%= short_datetime_pst(championship.trade_deadline_at) %> - <% end %> - <%= table_td do %> - <%= short_date_pst(championship.championship_at) %> - <% end %> - - <% end %> - -<% end %> -

- * All dates and times are in Pacific Standard Time (PST)/Pacific Daylight Time (PDT). -

diff --git a/lib/ex338_web/views/championship_view.ex b/lib/ex338_web/views/championship_view.ex deleted file mode 100644 index 0ed64858..00000000 --- a/lib/ex338_web/views/championship_view.ex +++ /dev/null @@ -1,63 +0,0 @@ -defmodule Ex338Web.ChampionshipView do - use Ex338Web, :view - - import Ex338Web.FantasyTeamView, only: [display_autodraft_setting: 1] - - def get_team_name(%{fantasy_player: %{roster_positions: [position]}}) do - position.fantasy_team.team_name - end - - def get_team_name(_) do - "-" - end - - def filter_category(championships, category) do - Enum.filter(championships, &(&1.category == category)) - end - - def display_drafted_at_or_pick_due_at(%{available_to_pick?: false, drafted_player_id: nil}) do - "---" - end - - def display_drafted_at_or_pick_due_at( - %{available_to_pick?: true, drafted_player_id: nil} = assigns - ) do - if assigns.over_time? do - ~H""" -
- <%= short_time_secs_pst(assigns.pick_due_at) %>* -
- """ - else - ~H""" -
- <%= short_time_secs_pst(assigns.pick_due_at) %>* -
- """ - end - end - - def display_drafted_at_or_pick_due_at(%{drafted_at: nil}) do - "---" - end - - def display_drafted_at_or_pick_due_at(pick) do - short_time_pst(pick.drafted_at) - end - - def show_create_slots(%{admin: true}, %{category: "event", championship_slots: []}) do - true - end - - def show_create_slots(_user, _championship) do - false - end - - def show_create_picks(%{admin: true}, %{in_season_draft: true, in_season_draft_picks: []}) do - true - end - - def show_create_picks(_user, _championship) do - false - end -end diff --git a/test/ex338_web/views/championship_view_test.exs b/test/ex338_web/controllers/championship_html_test.exs similarity index 79% rename from test/ex338_web/views/championship_view_test.exs rename to test/ex338_web/controllers/championship_html_test.exs index eb9941a1..8f995318 100644 --- a/test/ex338_web/views/championship_view_test.exs +++ b/test/ex338_web/controllers/championship_html_test.exs @@ -1,4 +1,4 @@ -defmodule Ex338Web.ChampionshipViewTest do +defmodule Ex338Web.ChampionshipHTMLTest do use Ex338Web.ConnCase, async: true import Phoenix.LiveViewTest @@ -7,7 +7,7 @@ defmodule Ex338Web.ChampionshipViewTest do alias Ex338.Championships.Championship alias Ex338.Championships.ChampionshipSlot alias Ex338.InSeasonDraftPicks.InSeasonDraftPick - alias Ex338Web.ChampionshipView + alias Ex338Web.ChampionshipHTML describe "get_team_name/1" do test "returns name from a fantasy team struct" do @@ -19,7 +19,7 @@ defmodule Ex338Web.ChampionshipViewTest do } } - result = ChampionshipView.get_team_name(player) + result = ChampionshipHTML.get_team_name(player) assert result == "Brown" end @@ -27,7 +27,7 @@ defmodule Ex338Web.ChampionshipViewTest do test "returns a dash if no positions" do player = %{fantasy_player: %{roster_positions: []}} - result = ChampionshipView.get_team_name(player) + result = ChampionshipHTML.get_team_name(player) assert result == "-" end @@ -42,7 +42,7 @@ defmodule Ex338Web.ChampionshipViewTest do %{name: "D", category: "event"} ] - results = ChampionshipView.filter_category(championships, "overall") + results = ChampionshipHTML.filter_category(championships, "overall") assert Enum.map(results, & &1.name) == ~w(A B) end @@ -55,7 +55,7 @@ defmodule Ex338Web.ChampionshipViewTest do %{name: "D", category: "event"} ] - results = ChampionshipView.filter_category(championships, "event") + results = ChampionshipHTML.filter_category(championships, "event") assert Enum.map(results, & &1.name) == ~w(C D) end @@ -65,7 +65,7 @@ defmodule Ex338Web.ChampionshipViewTest do test "returns dashes if haven't drafted and not available to pick" do pick = %InSeasonDraftPick{available_to_pick?: false, drafted_player_id: nil} - result = ChampionshipView.display_drafted_at_or_pick_due_at(pick) + result = ChampionshipHTML.display_drafted_at_or_pick_due_at(pick) assert result == "---" end @@ -74,7 +74,7 @@ defmodule Ex338Web.ChampionshipViewTest do date = DateTime.from_naive!(~N[2017-09-16 22:30:40.000], "Etc/UTC") pick = %InSeasonDraftPick{available_to_pick?: true, pick_due_at: date} - result = ChampionshipView.display_drafted_at_or_pick_due_at(pick) + result = ChampionshipHTML.display_drafted_at_or_pick_due_at(pick) assert rendered_to_string(result) =~ " 3:30:40 PM" end @@ -82,7 +82,7 @@ defmodule Ex338Web.ChampionshipViewTest do test "returns dashes if already picked but no drafted_at data" do pick = %InSeasonDraftPick{available_to_pick?: true, drafted_player_id: 1, drafted_at: nil} - result = ChampionshipView.display_drafted_at_or_pick_due_at(pick) + result = ChampionshipHTML.display_drafted_at_or_pick_due_at(pick) assert result == "---" end @@ -91,7 +91,7 @@ defmodule Ex338Web.ChampionshipViewTest do date = DateTime.from_naive!(~N[2017-09-16 22:30:00.000], "Etc/UTC") pick = %InSeasonDraftPick{available_to_pick?: true, drafted_player_id: 1, drafted_at: date} - result = ChampionshipView.display_drafted_at_or_pick_due_at(pick) + result = ChampionshipHTML.display_drafted_at_or_pick_due_at(pick) assert result == " 3:30 PM" end @@ -102,7 +102,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: true} championship = %Championship{category: "event", championship_slots: []} - result = ChampionshipView.show_create_slots(user, championship) + result = ChampionshipHTML.show_create_slots(user, championship) assert result == true end @@ -111,7 +111,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: true} championship = %Championship{category: "event", championship_slots: [%ChampionshipSlot{}]} - result = ChampionshipView.show_create_slots(user, championship) + result = ChampionshipHTML.show_create_slots(user, championship) assert result == false end @@ -120,7 +120,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: false} championship = %Championship{category: "event", championship_slots: []} - result = ChampionshipView.show_create_slots(user, championship) + result = ChampionshipHTML.show_create_slots(user, championship) assert result == false end @@ -129,7 +129,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = nil championship = %Championship{category: "event", championship_slots: []} - result = ChampionshipView.show_create_slots(user, championship) + result = ChampionshipHTML.show_create_slots(user, championship) assert result == false end @@ -138,7 +138,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: true} championship = %Championship{category: "overall", championship_slots: []} - result = ChampionshipView.show_create_slots(user, championship) + result = ChampionshipHTML.show_create_slots(user, championship) assert result == false end @@ -149,7 +149,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: true} championship = %Championship{in_season_draft: true, in_season_draft_picks: []} - result = ChampionshipView.show_create_picks(user, championship) + result = ChampionshipHTML.show_create_picks(user, championship) assert result == true end @@ -162,7 +162,7 @@ defmodule Ex338Web.ChampionshipViewTest do in_season_draft_picks: [%InSeasonDraftPick{}] } - result = ChampionshipView.show_create_picks(user, championship) + result = ChampionshipHTML.show_create_picks(user, championship) assert result == false end @@ -171,7 +171,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: false} championship = %Championship{in_season_draft: true, in_season_draft_picks: []} - result = ChampionshipView.show_create_picks(user, championship) + result = ChampionshipHTML.show_create_picks(user, championship) assert result == false end @@ -180,7 +180,7 @@ defmodule Ex338Web.ChampionshipViewTest do user = %User{admin: true} championship = %Championship{in_season_draft: false, in_season_draft_picks: []} - result = ChampionshipView.show_create_picks(user, championship) + result = ChampionshipHTML.show_create_picks(user, championship) assert result == false end