forked from shibao/cannery
style ammo group index page
This commit is contained in:
parent
cccc5aafc7
commit
a6a9994b97
@ -10,7 +10,7 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
|
||||
@impl true
|
||||
def mount(_params, session, socket) do
|
||||
{:ok, socket |> assign_defaults(session) |> assign(:ammo_groups, list_ammo_groups())}
|
||||
{:ok, socket |> assign_defaults(session) |> display_ammo_groups()}
|
||||
end
|
||||
|
||||
@impl true
|
||||
@ -38,13 +38,12 @@ defmodule CanneryWeb.AmmoGroupLive.Index do
|
||||
|
||||
@impl true
|
||||
def handle_event("delete", %{"id" => id}, socket) do
|
||||
ammo_group = Ammo.get_ammo_group!(id)
|
||||
{:ok, _} = Ammo.delete_ammo_group(ammo_group)
|
||||
|
||||
{:noreply, socket |> assign(:ammo_groups, list_ammo_groups())}
|
||||
Ammo.get_ammo_group!(id) |> Ammo.delete_ammo_group!()
|
||||
{:noreply, socket |> display_ammo_groups()}
|
||||
end
|
||||
|
||||
defp list_ammo_groups do
|
||||
Ammo.list_ammo_groups()
|
||||
defp display_ammo_groups(%{assigns: %{current_user: current_user}} = socket) do
|
||||
ammo_groups = Ammo.list_ammo_groups(current_user)
|
||||
socket |> assign(:ammo_groups, ammo_groups)
|
||||
end
|
||||
end
|
||||
|
57
lib/cannery_web/live/ammo_group_live/index.html.heex
Normal file
57
lib/cannery_web/live/ammo_group_live/index.html.heex
Normal file
@ -0,0 +1,57 @@
|
||||
<div class="mx-8 flex flex-col space-y-8 justify-center items-center">
|
||||
<h1 class="title text-2xl title-primary-500">
|
||||
Listing Ammo
|
||||
</h1>
|
||||
|
||||
<%= if @ammo_groups |> Enum.empty?() do %>
|
||||
<h2 class="title text-xl text-primary-500">
|
||||
No Ammo 😔
|
||||
</h2>
|
||||
|
||||
<%= live_patch "Add your first box!",
|
||||
to: Routes.ammo_group_index_path(@socket, :new),
|
||||
class: "btn btn-primary" %>
|
||||
<% else %>
|
||||
<%= live_patch "New Ammo group",
|
||||
to: Routes.ammo_group_index_path(@socket, :new),
|
||||
class: "btn btn-primary" %>
|
||||
|
||||
<div class="w-full overflow-x-auto border border-gray-600 rounded-lg shadow-lg bg-black">
|
||||
<table class="min-w-full table-auto text-center bg-white">
|
||||
<thead class="border-b border-primary-600">
|
||||
<tr>
|
||||
<th class="p-2">Count</th>
|
||||
<th class="p-2">Price paid</th>
|
||||
<th class="p-2">Notes</th>
|
||||
|
||||
<th class="p-2"></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ammo_groups">
|
||||
<%= for ammo_group <- @ammo_groups do %>
|
||||
<tr id={ammo_group-"#{ammo_group.id}"}>
|
||||
<td class="p-2"><%= ammo_group.count %></td>
|
||||
<td class="p-2"><%= ammo_group.price_paid %></td>
|
||||
<td class="p-2"><%= ammo_group.notes %></td>
|
||||
|
||||
<td class="p-2 w-full h-full space-y-2 flex flex-col justify-center items-center">
|
||||
<span><%= live_redirect "Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group) %></span>
|
||||
<span><%= live_patch "Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group) %></span>
|
||||
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: ammo_group.id, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<%= if @live_action in [:new, :edit] do %>
|
||||
<%= live_modal CanneryWeb.AmmoGroupLive.FormComponent,
|
||||
id: @ammo_group.id || :new,
|
||||
title: @page_title,
|
||||
action: @live_action,
|
||||
ammo_group: @ammo_group,
|
||||
return_to: Routes.ammo_group_index_path(@socket, :index) %>
|
||||
<% end %>
|
@ -1,39 +0,0 @@
|
||||
<h1>Listing Ammo groups</h1>
|
||||
|
||||
<%= if @live_action in [:new, :edit] do %>
|
||||
<%= live_modal CanneryWeb.AmmoGroupLive.FormComponent,
|
||||
id: @ammo_group.id || :new,
|
||||
title: @page_title,
|
||||
action: @live_action,
|
||||
ammo_group: @ammo_group,
|
||||
return_to: Routes.ammo_group_index_path(@socket, :index) %>
|
||||
<% end %>
|
||||
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Count</th>
|
||||
<th>Price paid</th>
|
||||
<th>Notes</th>
|
||||
|
||||
<th></th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="ammo_groups">
|
||||
<%= for ammo_group <- @ammo_groups do %>
|
||||
<tr id="ammo_group-<%= ammo_group.id %>">
|
||||
<td><%= ammo_group.count %></td>
|
||||
<td><%= ammo_group.price_paid %></td>
|
||||
<td><%= ammo_group.notes %></td>
|
||||
|
||||
<td>
|
||||
<span><%= live_redirect "Show", to: Routes.ammo_group_show_path(@socket, :show, ammo_group) %></span>
|
||||
<span><%= live_patch "Edit", to: Routes.ammo_group_index_path(@socket, :edit, ammo_group) %></span>
|
||||
<span><%= link "Delete", to: "#", phx_click: "delete", phx_value_id: ammo_group.id, data: [confirm: "Are you sure?"] %></span>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
<span><%= live_patch "New Ammo group", to: Routes.ammo_group_index_path(@socket, :new) %></span>
|
Loading…
Reference in New Issue
Block a user