Autogen Yield liveviews
This commit is contained in:
46
lib/osuuspuutarha_web/live/yield_live/index.ex
Normal file
46
lib/osuuspuutarha_web/live/yield_live/index.ex
Normal file
@@ -0,0 +1,46 @@
|
||||
defmodule OsuuspuutarhaWeb.YieldLive.Index do
|
||||
use OsuuspuutarhaWeb, :live_view
|
||||
|
||||
alias Osuuspuutarha.Harvest
|
||||
alias Osuuspuutarha.Harvest.Yield
|
||||
|
||||
@impl true
|
||||
def mount(_params, _session, socket) do
|
||||
{:ok, assign(socket, :yields, list_yields())}
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_params(params, _url, socket) do
|
||||
{:noreply, apply_action(socket, socket.assigns.live_action, params)}
|
||||
end
|
||||
|
||||
defp apply_action(socket, :edit, %{"id" => id}) do
|
||||
socket
|
||||
|> assign(:page_title, "Edit Yield")
|
||||
|> assign(:yield, Harvest.get_yield!(id))
|
||||
end
|
||||
|
||||
defp apply_action(socket, :new, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "New Yield")
|
||||
|> assign(:yield, %Yield{})
|
||||
end
|
||||
|
||||
defp apply_action(socket, :index, _params) do
|
||||
socket
|
||||
|> assign(:page_title, "Listing Yields")
|
||||
|> assign(:yield, nil)
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
yield = Harvest.get_yield!(id)
|
||||
{:ok, _} = Harvest.delete_yield(yield)
|
||||
|
||||
{:noreply, assign(socket, :yields, list_yields())}
|
||||
end
|
||||
|
||||
defp list_yields do
|
||||
Harvest.list_yields()
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user