88 lines
2.7 KiB
Elixir
88 lines
2.7 KiB
Elixir
defmodule BeetRoundServerWeb.BiddingLive.Index do
|
|
use BeetRoundServerWeb, :live_view
|
|
|
|
alias BeetRoundServer.Biddings
|
|
alias BeetRoundServer.BiddingRounds.BiddingRoundFacade
|
|
|
|
@impl true
|
|
def render(assigns) do
|
|
~H"""
|
|
<Layouts.app flash={@flash} current_scope={@current_scope}>
|
|
<.header>
|
|
Listing Biddings
|
|
<:actions>
|
|
<.button variant="primary" navigate={~p"/biddings/new"}>
|
|
<.icon name="hero-plus" /> New Bidding
|
|
</.button>
|
|
</:actions>
|
|
</.header>
|
|
|
|
<%= if @bidding_round == 0 do %>
|
|
<p>Keine Bietrunde aktiv.</p>
|
|
<% else %>
|
|
<p>Aktive Bietrunde: {@bidding_round}</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>
|
|
</Layouts.app>
|
|
"""
|
|
end
|
|
|
|
@impl true
|
|
def mount(_params, _session, socket) do
|
|
if connected?(socket) do
|
|
Biddings.subscribe_biddings(socket.assigns.current_scope)
|
|
end
|
|
|
|
current_round = BiddingRoundFacade.get_current_round()
|
|
|
|
{:ok,
|
|
socket
|
|
|> assign(:page_title, "Listing Biddings")
|
|
|> assign(bidding_round: current_round)
|
|
|> stream(:biddings, list_biddings(socket.assigns.current_scope))}
|
|
end
|
|
|
|
@impl true
|
|
def handle_event("delete", %{"id" => id}, socket) do
|
|
bidding = Biddings.get_bidding!(socket.assigns.current_scope, id)
|
|
{:ok, _} = Biddings.delete_bidding(socket.assigns.current_scope, bidding)
|
|
|
|
{:noreply, stream_delete(socket, :biddings, bidding)}
|
|
end
|
|
|
|
@impl true
|
|
def handle_info({type, %BeetRoundServer.Biddings.Bidding{}}, socket)
|
|
when type in [:created, :updated, :deleted] do
|
|
{:noreply,
|
|
stream(socket, :biddings, list_biddings(socket.assigns.current_scope), reset: true)}
|
|
end
|
|
|
|
defp list_biddings(current_scope) do
|
|
Biddings.list_biddings(current_scope)
|
|
end
|
|
end
|