cannery/lib/cannery_web/live/ammo_group_live/index.html.heex

174 lines
6.0 KiB
Plaintext
Raw Normal View History

2022-02-15 23:52:44 -05:00
<div class="flex flex-col space-y-8 justify-center items-center">
2022-02-01 00:14:14 -05:00
<h1 class="title text-2xl title-primary-500">
2022-02-15 17:33:07 -05:00
<%= gettext("Ammo") %>
2022-02-01 00:14:14 -05:00
</h1>
<%= if @ammo_groups |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-500">
2022-02-15 23:52:44 -05:00
<%= gettext("No Ammo") %>
<%= display_emoji("😔") %>
2022-02-01 00:14:14 -05:00
</h2>
2022-02-09 00:20:04 -05:00
<%= live_patch(dgettext("actions", "Add your first box!"),
2022-02-01 00:14:14 -05:00
to: Routes.ammo_group_index_path(@socket, :new),
2022-02-01 01:08:18 -05:00
class: "btn btn-primary"
) %>
2022-02-01 00:14:14 -05:00
<% else %>
2022-02-09 00:20:04 -05:00
<%= live_patch(dgettext("actions", "New Ammo group"),
2022-02-01 00:14:14 -05:00
to: Routes.ammo_group_index_path(@socket, :new),
2022-02-01 01:08:18 -05:00
class: "btn btn-primary"
) %>
2022-02-01 00:14:14 -05:00
<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>
2022-02-15 17:33:45 -05:00
<th class="p-2">
<%= gettext("Ammo type") %>
</th>
2022-02-01 01:08:18 -05:00
<th class="p-2">
2022-02-09 00:20:04 -05:00
<%= gettext("Count") %>
2022-02-01 01:08:18 -05:00
</th>
<th class="p-2">
2022-02-09 00:20:04 -05:00
<%= gettext("Price paid") %>
2022-02-01 01:08:18 -05:00
</th>
<th class="p-2">
2022-02-09 00:20:04 -05:00
<%= gettext("Notes") %>
2022-02-01 01:08:18 -05:00
</th>
2022-02-15 17:33:45 -05:00
<th class="p-2">
<%= gettext("Range") %>
2022-02-15 17:33:45 -05:00
</th>
<th class="p-2">
<%= gettext("Container") %>
</th>
2022-02-01 00:14:14 -05:00
<th class="p-2"></th>
</tr>
</thead>
<tbody id="ammo_groups">
<%= for ammo_group <- @ammo_groups do %>
2022-02-05 01:59:40 -05:00
<tr id={"ammo_group-#{ammo_group.id}"}>
2022-02-15 17:33:45 -05:00
<td class="p-2">
<%= live_patch(ammo_group.ammo_type.name,
to: Routes.ammo_type_show_path(Endpoint, :show, ammo_group.ammo_type),
class: "link"
) %>
</td>
2022-02-01 01:08:18 -05:00
<td class="p-2">
<%= ammo_group.count %>
</td>
2022-02-05 01:59:40 -05:00
2022-02-01 01:08:18 -05:00
<td class="p-2">
<%= if ammo_group.price_paid do %>
2022-02-17 21:24:59 -05:00
<%= gettext("$%{amount}",
amount: ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2)
) %>
<% end %>
2022-02-01 01:08:18 -05:00
</td>
2022-02-05 01:59:40 -05:00
2022-02-01 01:08:18 -05:00
<td class="p-2">
<%= ammo_group.notes %>
</td>
2022-02-01 00:14:14 -05:00
2022-02-15 17:33:45 -05:00
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<button
type="button"
class="btn btn-primary"
phx-click="toggle_staged"
phx-value-ammo_group_id={ammo_group.id}
>
<%= if ammo_group.staged, do: gettext("Unstage"), else: gettext("Stage") %>
</button>
<%= live_patch(dgettext("actions", "Record shots"),
to: Routes.ammo_group_index_path(Endpoint, :add_shot_group, ammo_group),
class: "btn btn-primary"
) %>
</div>
2022-02-15 17:33:45 -05:00
</td>
<td class="p-2">
<%= if ammo_group.container do %>
<%= live_patch(ammo_group.container.name,
to: Routes.ammo_group_index_path(@socket, :move, ammo_group),
class: "btn btn-primary"
) %>
<% end %>
2022-02-15 17:33:45 -05:00
</td>
2022-02-15 23:52:44 -05:00
<td class="p-2">
2022-02-15 17:33:45 -05:00
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_group_show_path(@socket, :show, ammo_group),
2022-02-16 22:39:53 -05:00
class: "text-primary-500 link",
data: [qa: "view-#{ammo_group.id}"] do %>
2022-02-15 17:33:45 -05:00
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
2022-02-05 01:59:40 -05:00
2022-02-15 17:33:45 -05:00
<%= live_patch to: Routes.ammo_group_index_path(@socket, :edit, ammo_group),
2022-02-16 22:39:53 -05:00
class: "text-primary-500 link",
data: [qa: "edit-#{ammo_group.id}"] do %>
2022-02-15 17:33:45 -05:00
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
2022-02-05 01:59:40 -05:00
2022-02-15 17:33:45 -05:00
<%= link to: "#",
class: "text-primary-500 link",
phx_click: "delete",
phx_value_id: ammo_group.id,
2022-02-16 22:39:53 -05:00
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_group.id}"
] do %>
2022-02-15 17:33:45 -05:00
<i class="fa-fw fa-lg fas fa-trash"></i>
<% end %>
</div>
2022-02-01 00:14:14 -05:00
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</div>
<%= cond do %>
<% @live_action in [:new, :edit] -> %>
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
<.live_component
module={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(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
<% @live_action == :add_shot_group -> %>
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
<.live_component
module={CanneryWeb.Components.AddShotGroupComponent}
id={:new}
title={@page_title}
action={@live_action}
ammo_group={@ammo_group}
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
<% @live_action == :move -> %>
<.modal return_to={Routes.ammo_group_index_path(Endpoint, :index)}>
<.live_component
module={CanneryWeb.Components.MoveAmmoGroupComponent}
id={@ammo_group.id}
title={@page_title}
action={@live_action}
ammo_group={@ammo_group}
return_to={Routes.ammo_group_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
<% true -> %>
2022-02-17 21:24:59 -05:00
<% end %>