Compare commits

..

6 Commits

3 changed files with 62 additions and 46 deletions

View File

@ -3,6 +3,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
alias BeetRoundServer.Biddings alias BeetRoundServer.Biddings
alias BeetRoundServer.Biddings.Bidding alias BeetRoundServer.Biddings.Bidding
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
@impl true @impl true
def render(assigns) do def render(assigns) do
@ -10,28 +11,37 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
<Layouts.app flash={@flash} current_scope={@current_scope}> <Layouts.app flash={@flash} current_scope={@current_scope}>
<.header> <.header>
{@page_title} {@page_title}
<:subtitle>Use this form to manage bidding records in your database.</:subtitle> <:subtitle>Bitte gib hier den Betrag ein, den Du monatlich bezahlen willst.</:subtitle>
</.header> </.header>
<%= if @bidding.bidding_round == 0 do %>
<.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save"> <p><b>Keine Bietrunde aktiv.</b></p>
<.input field={@form[:bidding_round]} type="number" label="Bidding round" />
<.input field={@form[:amount]} type="number" label="Amount" />
<.input field={@form[:depot_wish_one]} type="text" label="Depot wish one" />
<.input field={@form[:depot_wish_two]} type="text" label="Depot wish two" />
<footer> <footer>
<.button phx-disable-with="Saving..." variant="primary">Save Bidding</.button>
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button> <.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
</footer> </footer>
<% else %>
<.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save">
<.input field={@form[:amount]} type="number" label="Betrag" />
<.input field={@form[:depot_wish_one]} type="text" label="Depot Wunsch 1" />
<.input field={@form[:depot_wish_two]} type="text" label="Depot Wunsch 2" />
<.input field={@form[:bidding_round]} type="number" readonly hidden />
<footer>
<.button phx-disable-with="Bearbeitung..." variant="primary">Gebot abgeben</.button>
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Abbrechen</.button>
</footer>
</.form> </.form>
<% end %>
</Layouts.app> </Layouts.app>
""" """
end end
@impl true @impl true
def mount(params, _session, socket) do def mount(params, _session, socket) do
# current_round = BiddingRoundFacade.get_current_round()
{:ok, {:ok,
socket socket
|> assign(:return_to, return_to(params["return_to"])) |> assign(:return_to, return_to(params["return_to"]))
# |> assign(bidding_round: current_round)
|> apply_action(socket.assigns.live_action, params)} |> apply_action(socket.assigns.live_action, params)}
end end
@ -42,23 +52,34 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
bidding = Biddings.get_bidding!(socket.assigns.current_scope, id) bidding = Biddings.get_bidding!(socket.assigns.current_scope, id)
socket socket
|> assign(:page_title, "Edit Bidding") |> assign(:page_title, "Gebot bearbeiten")
|> assign(:bidding, bidding) |> assign(:bidding, bidding)
|> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding))) |> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding)))
end end
defp apply_action(socket, :new, _params) do defp apply_action(socket, :new, _params) do
bidding = %Bidding{user_id: socket.assigns.current_scope.user.id} current_round = BiddingRoundFacade.get_current_round()
bidding = %Bidding{
user_id: socket.assigns.current_scope.user.id,
bidding_round: current_round
}
socket socket
|> assign(:page_title, "New Bidding") |> assign(:page_title, "Neues Gebot")
|> assign(:bidding, bidding) |> assign(:bidding, bidding)
|> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding))) |> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding)))
end end
@impl true @impl true
def handle_event("validate", %{"bidding" => bidding_params}, socket) do def handle_event("validate", %{"bidding" => bidding_params}, socket) do
changeset = Biddings.change_bidding(socket.assigns.current_scope, socket.assigns.bidding, bidding_params) changeset =
Biddings.change_bidding(
socket.assigns.current_scope,
socket.assigns.bidding,
bidding_params
)
{:noreply, assign(socket, form: to_form(changeset, action: :validate))} {:noreply, assign(socket, form: to_form(changeset, action: :validate))}
end end
@ -67,11 +88,15 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
end end
defp save_bidding(socket, :edit, bidding_params) do defp save_bidding(socket, :edit, bidding_params) do
case Biddings.update_bidding(socket.assigns.current_scope, socket.assigns.bidding, bidding_params) do case Biddings.update_bidding(
socket.assigns.current_scope,
socket.assigns.bidding,
bidding_params
) do
{:ok, bidding} -> {:ok, bidding} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Bidding updated successfully") |> put_flash(:info, "Gebot erfolgreich bearbeitet")
|> push_navigate( |> push_navigate(
to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding) to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding)
)} )}
@ -86,7 +111,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
{:ok, bidding} -> {:ok, bidding} ->
{:noreply, {:noreply,
socket socket
|> put_flash(:info, "Bidding created successfully") |> put_flash(:info, "Gebot erfolgreich abgegeben")
|> push_navigate( |> push_navigate(
to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding) to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding)
)} )}

View File

@ -9,44 +9,33 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
~H""" ~H"""
<Layouts.app flash={@flash} current_scope={@current_scope}> <Layouts.app flash={@flash} current_scope={@current_scope}>
<.header> <.header>
Listing Biddings {@current_scope.user.email}
<:actions> <:actions>
<.button variant="primary" navigate={~p"/biddings/new"}> <.button variant="primary" navigate={~p"/biddings/new"}>
<.icon name="hero-plus" /> New Bidding <.icon name="hero-plus" /> Neues Gebot
</.button> </.button>
</:actions> </:actions>
</.header> </.header>
<%= if @bidding_round == 0 do %> <%= if @bidding_round == 0 do %>
<p>Keine Bietrunde aktiv.</p> <p>Keine Bietrunde aktiv. Aktuell kein Bieten möglich!</p>
<% else %> <% else %>
<p>Aktive Bietrunde: {@bidding_round}</p> <p>Aktive Bietrunde: {@bidding_round} - Es kann geboten werden!</p>
<% end %> <% end %>
<.table <br />
id="biddings"
rows={@streams.biddings} <%= if @current_bidding do %>
row_click={fn {_id, bidding} -> JS.navigate(~p"/biddings/#{bidding}") end} <p><b>Aktuelles Gebot:</b></p>
> <.list>
<:col :let={{_id, bidding}} label="Bidding round">{bidding.bidding_round}</:col> <:item title="Bietrunde">{@current_bidding.bidding_round}</:item>
<:col :let={{_id, bidding}} label="Amount">{bidding.amount}</:col> <:item title="monatl. Betrag">{@current_bidding.amount}</:item>
<:col :let={{_id, bidding}} label="Depot wish one">{bidding.depot_wish_one}</:col> <:item title="Depot Wunsch 1">{@current_bidding.depot_wish_one}</:item>
<:col :let={{_id, bidding}} label="Depot wish two">{bidding.depot_wish_two}</:col> <:item title="Depot Wunsch 2">{@current_bidding.depot_wish_two}</:item>
<:action :let={{_id, bidding}}> </.list>
<div class="sr-only"> <% else %>
<.link navigate={~p"/biddings/#{bidding}"}>Show</.link> <p>Noch kein Gebot abgegeben</p>
</div> <% end %>
<.link navigate={~p"/biddings/#{bidding}/edit"}>Edit</.link>
</:action>
<:action :let={{id, bidding}}>
<.link
phx-click={JS.push("delete", value: %{id: bidding.id}) |> hide("##{id}")}
data-confirm="Are you sure?"
>
Delete
</.link>
</:action>
</.table>
</Layouts.app> </Layouts.app>
""" """
end end
@ -58,11 +47,13 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
end end
current_round = BiddingRoundFacade.get_current_round() current_round = BiddingRoundFacade.get_current_round()
current_bidding = Biddings.get_most_recent_bidding(socket.assigns.current_scope)
{:ok, {:ok,
socket socket
|> assign(:page_title, "Listing Biddings") |> assign(:page_title, "Aktuelles Gebot")
|> assign(bidding_round: current_round) |> assign(bidding_round: current_round)
|> assign(current_bidding: current_bidding)
|> stream(:biddings, list_biddings(socket.assigns.current_scope))} |> stream(:biddings, list_biddings(socket.assigns.current_scope))}
end end

View File

@ -12,7 +12,7 @@ msgstr ""
## From Ecto.Changeset.cast/4 ## From Ecto.Changeset.cast/4
msgid "can't be blank" msgid "can't be blank"
msgstr "" msgstr "Muss ausgefüllt werden!"
## From Ecto.Changeset.unique_constraint/3 ## From Ecto.Changeset.unique_constraint/3
msgid "has already been taken" msgid "has already been taken"