Compare commits
6 Commits
1c02f28d25
...
1a4a05ff18
| Author | SHA1 | Date | |
|---|---|---|---|
| 1a4a05ff18 | |||
| f6d5f8d2ca | |||
| dbaa6d136a | |||
| b7ca842cc3 | |||
| 2519560b03 | |||
| d6f2d8c1f6 |
@ -3,6 +3,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
|
||||
alias BeetRoundServer.Biddings
|
||||
alias BeetRoundServer.Biddings.Bidding
|
||||
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
@ -10,28 +11,37 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
||||
<.header>
|
||||
{@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>
|
||||
|
||||
<.form for={@form} id="bidding-form" phx-change="validate" phx-submit="save">
|
||||
<.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" />
|
||||
<%= if @bidding.bidding_round == 0 do %>
|
||||
<p><b>Keine Bietrunde aktiv.</b></p>
|
||||
<footer>
|
||||
<.button phx-disable-with="Saving..." variant="primary">Save Bidding</.button>
|
||||
<.button navigate={return_path(@current_scope, @return_to, @bidding)}>Cancel</.button>
|
||||
</footer>
|
||||
</.form>
|
||||
<% 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>
|
||||
<% end %>
|
||||
</Layouts.app>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def mount(params, _session, socket) do
|
||||
# current_round = BiddingRoundFacade.get_current_round()
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:return_to, return_to(params["return_to"]))
|
||||
# |> assign(bidding_round: current_round)
|
||||
|> apply_action(socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
@ -42,23 +52,34 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
bidding = Biddings.get_bidding!(socket.assigns.current_scope, id)
|
||||
|
||||
socket
|
||||
|> assign(:page_title, "Edit Bidding")
|
||||
|> assign(:page_title, "Gebot bearbeiten")
|
||||
|> assign(:bidding, bidding)
|
||||
|> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding)))
|
||||
end
|
||||
|
||||
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
|
||||
|> assign(:page_title, "New Bidding")
|
||||
|> assign(:page_title, "Neues Gebot")
|
||||
|> assign(:bidding, bidding)
|
||||
|> assign(:form, to_form(Biddings.change_bidding(socket.assigns.current_scope, bidding)))
|
||||
end
|
||||
|
||||
@impl true
|
||||
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))}
|
||||
end
|
||||
|
||||
@ -67,11 +88,15 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
end
|
||||
|
||||
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} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Bidding updated successfully")
|
||||
|> put_flash(:info, "Gebot erfolgreich bearbeitet")
|
||||
|> push_navigate(
|
||||
to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding)
|
||||
)}
|
||||
@ -86,7 +111,7 @@ defmodule BeetRoundServerWeb.BiddingLive.Form do
|
||||
{:ok, bidding} ->
|
||||
{:noreply,
|
||||
socket
|
||||
|> put_flash(:info, "Bidding created successfully")
|
||||
|> put_flash(:info, "Gebot erfolgreich abgegeben")
|
||||
|> push_navigate(
|
||||
to: return_path(socket.assigns.current_scope, socket.assigns.return_to, bidding)
|
||||
)}
|
||||
|
||||
@ -9,44 +9,33 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
|
||||
~H"""
|
||||
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
||||
<.header>
|
||||
Listing Biddings
|
||||
{@current_scope.user.email}
|
||||
<:actions>
|
||||
<.button variant="primary" navigate={~p"/biddings/new"}>
|
||||
<.icon name="hero-plus" /> New Bidding
|
||||
<.icon name="hero-plus" /> Neues Gebot
|
||||
</.button>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<%= if @bidding_round == 0 do %>
|
||||
<p>Keine Bietrunde aktiv.</p>
|
||||
<p>Keine Bietrunde aktiv. Aktuell kein Bieten möglich!</p>
|
||||
<% else %>
|
||||
<p>Aktive Bietrunde: {@bidding_round}</p>
|
||||
<p>Aktive Bietrunde: {@bidding_round} - Es kann geboten werden!</p>
|
||||
<% end %>
|
||||
|
||||
<.table
|
||||
id="biddings"
|
||||
rows={@streams.biddings}
|
||||
row_click={fn {_id, bidding} -> JS.navigate(~p"/biddings/#{bidding}") end}
|
||||
>
|
||||
<:col :let={{_id, bidding}} label="Bidding round">{bidding.bidding_round}</:col>
|
||||
<:col :let={{_id, bidding}} label="Amount">{bidding.amount}</:col>
|
||||
<:col :let={{_id, bidding}} label="Depot wish one">{bidding.depot_wish_one}</:col>
|
||||
<:col :let={{_id, bidding}} label="Depot wish two">{bidding.depot_wish_two}</:col>
|
||||
<:action :let={{_id, bidding}}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/biddings/#{bidding}"}>Show</.link>
|
||||
</div>
|
||||
<.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>
|
||||
<br />
|
||||
|
||||
<%= if @current_bidding do %>
|
||||
<p><b>Aktuelles Gebot:</b></p>
|
||||
<.list>
|
||||
<:item title="Bietrunde">{@current_bidding.bidding_round}</:item>
|
||||
<:item title="monatl. Betrag">{@current_bidding.amount} €</:item>
|
||||
<:item title="Depot Wunsch 1">{@current_bidding.depot_wish_one}</:item>
|
||||
<:item title="Depot Wunsch 2">{@current_bidding.depot_wish_two}</:item>
|
||||
</.list>
|
||||
<% else %>
|
||||
<p>Noch kein Gebot abgegeben</p>
|
||||
<% end %>
|
||||
</Layouts.app>
|
||||
"""
|
||||
end
|
||||
@ -58,11 +47,13 @@ defmodule BeetRoundServerWeb.BiddingLive.Index do
|
||||
end
|
||||
|
||||
current_round = BiddingRoundFacade.get_current_round()
|
||||
current_bidding = Biddings.get_most_recent_bidding(socket.assigns.current_scope)
|
||||
|
||||
{:ok,
|
||||
socket
|
||||
|> assign(:page_title, "Listing Biddings")
|
||||
|> assign(:page_title, "Aktuelles Gebot")
|
||||
|> assign(bidding_round: current_round)
|
||||
|> assign(current_bidding: current_bidding)
|
||||
|> stream(:biddings, list_biddings(socket.assigns.current_scope))}
|
||||
end
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ msgstr ""
|
||||
|
||||
## From Ecto.Changeset.cast/4
|
||||
msgid "can't be blank"
|
||||
msgstr ""
|
||||
msgstr "Muss ausgefüllt werden!"
|
||||
|
||||
## From Ecto.Changeset.unique_constraint/3
|
||||
msgid "has already been taken"
|
||||
|
||||
Reference in New Issue
Block a user