Fix warnings, remove analyzers and create fact for champion played game
ci / docker (push) Successful in 7m38s

This commit is contained in:
2024-06-06 20:20:45 +02:00
parent fe3d040978
commit 6dd8eea3d3
26 changed files with 92 additions and 402 deletions
@@ -1,90 +0,0 @@
defmodule LoLAnalyticsWeb.ChampionLive.FormComponent do
use LoLAnalyticsWeb, :live_component
alias LoLAnalytics.Accounts
@impl true
def render(assigns) do
~H"""
<div>
<.header>
<%= @title %>
<:subtitle>Use this form to manage champion records in your database.</:subtitle>
</.header>
<.simple_form
for={@form}
id="champion-form"
phx-target={@myself}
phx-change="validate"
phx-submit="save"
>
<:actions>
<.button phx-disable-with="Saving...">Save Champion</.button>
</:actions>
</.simple_form>
</div>
"""
end
@impl true
def update(%{champion: champion} = assigns, socket) do
changeset = Accounts.change_champion(champion)
{:ok,
socket
|> assign(assigns)
|> assign_form(changeset)}
end
@impl true
def handle_event("validate", %{"champion" => champion_params}, socket) do
changeset =
socket.assigns.champion
|> Accounts.change_champion(champion_params)
|> Map.put(:action, :validate)
{:noreply, assign_form(socket, changeset)}
end
def handle_event("save", %{"champion" => champion_params}, socket) do
save_champion(socket, socket.assigns.action, champion_params)
end
defp save_champion(socket, :edit, champion_params) do
case Accounts.update_champion(socket.assigns.champion, champion_params) do
{:ok, champion} ->
notify_parent({:saved, champion})
{:noreply,
socket
|> put_flash(:info, "Champion updated successfully")
|> push_patch(to: socket.assigns.patch)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign_form(socket, changeset)}
end
end
defp save_champion(socket, :new, champion_params) do
case Accounts.create_champion(champion_params) do
{:ok, champion} ->
notify_parent({:saved, champion})
{:noreply,
socket
|> put_flash(:info, "Champion created successfully")
|> push_patch(to: socket.assigns.patch)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign_form(socket, changeset)}
end
end
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
assign(socket, :form, to_form(changeset))
end
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
end
@@ -13,7 +13,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
@impl true
def mount(_params, _session, socket) do
champs = LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.get_win_rates()
champs = LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
mapped =
champs
@@ -73,7 +73,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
end
champs =
LolAnalytics.Facts.ChampionPlayedGame.ChampionPlayedGameRepo.get_win_rates()
LolAnalytics.Facts.ChampionPlayedGame.Repo.get_win_rates()
|> Enum.filter(fn %{name: name} ->
String.downcase(name) |> String.contains?(query_name)
end)
@@ -93,10 +93,6 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
)}
end
def handle_event("filter", unsigned_params, socket) do
{:noreply, socket}
end
@impl true
def handle_params(params, _url, socket) do
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
@@ -108,9 +104,4 @@ defmodule LoLAnalyticsWeb.ChampionLive.Index do
# |> assign(:champion, nil)
end
@impl true
def handle_info({LoLAnalyticsWeb.ChampionLive.FormComponent, {:saved, champion}}, socket) do
{:noreply, stream_insert(socket, :champions, champion)}
end
end
@@ -1,8 +1,6 @@
defmodule LoLAnalyticsWeb.ChampionLive.Show do
use LoLAnalyticsWeb, :live_view
alias LoLAnalytics.Accounts
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
@@ -13,7 +11,7 @@ defmodule LoLAnalyticsWeb.ChampionLive.Show do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:champion, Accounts.get_champion!(id))}
|> assign(:champion, %{id: id})}
end
defp page_title(:show), do: "Show Champion"
@@ -1,25 +1,7 @@
<.header>
Champion <%= @champion.id %>
<:subtitle>This is a champion record from your database.</:subtitle>
<:actions>
<.link patch={~p"/champions/#{@champion}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit champion</.button>
</.link>
</:actions>
<:actions></:actions>
</.header>
<.list>
</.list>
<.back navigate={~p"/champions"}>Back to champions</.back>
<.modal :if={@live_action == :edit} id="champion-modal" show on_cancel={JS.patch(~p"/champions/#{@champion}")}>
<.live_component
module={LoLAnalyticsWeb.ChampionLive.FormComponent}
id={@champion.id}
title={@page_title}
action={@live_action}
champion={@champion}
patch={~p"/champions/#{@champion}"}
/>
</.modal>
@@ -1,8 +1,6 @@
defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
use LoLAnalyticsWeb, :live_component
alias LoLAnalytics.Accounts
@impl true
def render(assigns) do
~H"""
@@ -19,7 +17,6 @@ defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
phx-change="validate"
phx-submit="save"
>
<:actions>
<.button phx-disable-with="Saving...">Save Role</.button>
</:actions>
@@ -27,64 +24,4 @@ defmodule LoLAnalyticsWeb.RoleLive.FormComponent do
</div>
"""
end
@impl true
def update(%{role: role} = assigns, socket) do
changeset = Accounts.change_role(role)
{:ok,
socket
|> assign(assigns)
|> assign_form(changeset)}
end
@impl true
def handle_event("validate", %{"role" => role_params}, socket) do
changeset =
socket.assigns.role
|> Accounts.change_role(role_params)
|> Map.put(:action, :validate)
{:noreply, assign_form(socket, changeset)}
end
def handle_event("save", %{"role" => role_params}, socket) do
save_role(socket, socket.assigns.action, role_params)
end
defp save_role(socket, :edit, role_params) do
case Accounts.update_role(socket.assigns.role, role_params) do
{:ok, role} ->
notify_parent({:saved, role})
{:noreply,
socket
|> put_flash(:info, "Role updated successfully")
|> push_patch(to: socket.assigns.patch)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign_form(socket, changeset)}
end
end
defp save_role(socket, :new, role_params) do
case Accounts.create_role(role_params) do
{:ok, role} ->
notify_parent({:saved, role})
{:noreply,
socket
|> put_flash(:info, "Role created successfully")
|> push_patch(to: socket.assigns.patch)}
{:error, %Ecto.Changeset{} = changeset} ->
{:noreply, assign_form(socket, changeset)}
end
end
defp assign_form(socket, %Ecto.Changeset{} = changeset) do
assign(socket, :form, to_form(changeset))
end
defp notify_parent(msg), do: send(self(), {__MODULE__, msg})
end
@@ -1,9 +1,6 @@
defmodule LoLAnalyticsWeb.RoleLive.Index do
use LoLAnalyticsWeb, :live_view
alias LoLAnalytics.Accounts
alias LoLAnalytics.Accounts.Role
@roles ["ALL", "TOP", "MIDDLE", "JUNGLE", "UTILITY", "BOTTOM"]
@impl true
@@ -1,40 +1,4 @@
<.header>
Listing Roles
<:actions>
<.link patch={~p"/roles/new"}>
<.button>New Role</.button>
</.link>
</:actions>
<:actions></:actions>
</.header>
<.table
id="roles"
rows={@streams.roles}
row_click={fn {_id, role} -> JS.navigate(~p"/roles/#{role}") end}
>
<:action :let={{_id, role}}>
<div class="sr-only">
<.link navigate={~p"/roles/#{role}"}>Show</.link>
</div>
<.link patch={~p"/roles/#{role}/edit"}>Edit</.link>
</:action>
<:action :let={{id, role}}>
<.link
phx-click={JS.push("delete", value: %{id: role.id}) |> hide("##{id}")}
data-confirm="Are you sure?"
>
Delete
</.link>
</:action>
</.table>
<.modal :if={@live_action in [:new, :edit]} id="role-modal" show on_cancel={JS.patch(~p"/roles")}>
<.live_component
module={LoLAnalyticsWeb.RoleLive.FormComponent}
id={@role.id || :new}
title={@page_title}
action={@live_action}
role={@role}
patch={~p"/roles"}
/>
</.modal>
@@ -1,19 +1,16 @@
defmodule LoLAnalyticsWeb.RoleLive.Show do
use LoLAnalyticsWeb, :live_view
alias LoLAnalytics.Accounts
@impl true
def mount(_params, _session, socket) do
{:ok, socket}
end
@impl true
def handle_params(%{"id" => id}, _, socket) do
def handle_params(%{"id" => _id}, _, socket) do
{:noreply,
socket
|> assign(:page_title, page_title(socket.assigns.live_action))
|> assign(:role, Accounts.get_role!(id))}
|> assign(:page_title, page_title(socket.assigns.live_action))}
end
defp page_title(:show), do: "Show Role"
@@ -1,25 +1,7 @@
<.header>
Role <%= @role.id %>
<:subtitle>This is a role record from your database.</:subtitle>
<:actions>
<.link patch={~p"/roles/#{@role}/show/edit"} phx-click={JS.push_focus()}>
<.button>Edit role</.button>
</.link>
</:actions>
<:actions></:actions>
</.header>
<.list>
</.list>
<.back navigate={~p"/roles"}>Back to roles</.back>
<.modal :if={@live_action == :edit} id="role-modal" show on_cancel={JS.patch(~p"/roles/#{@role}")}>
<.live_component
module={LoLAnalyticsWeb.RoleLive.FormComponent}
id={@role.id}
title={@page_title}
action={@live_action}
role={@role}
patch={~p"/roles/#{@role}"}
/>
</.modal>