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

104 lines
3.6 KiB
Plaintext

<div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500">
<%= gettext("Ammo Types") %>
</h1>
<%= if @ammo_types |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<%= gettext("No Ammo Types") %>
<%= display_emoji("😔") %>
</h2>
<%= live_patch(dgettext("actions", "Add your first type!"),
to: Routes.ammo_type_index_path(Endpoint, :new),
class: "btn btn-primary"
) %>
<% else %>
<%= live_patch(dgettext("actions", "New Ammo type"),
to: Routes.ammo_type_index_path(Endpoint, :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>
<%= for {field_name, _field, _type} <- @columns_to_display do %>
<th class="p-2">
<%= field_name %>
</th>
<% end %>
<th class="p-2">
<%= gettext("Total # of rounds") %>
</th>
<th class="p-2"></th>
</tr>
</thead>
<tbody>
<%= for ammo_type <- @ammo_types do %>
<tr id={"ammo_type-#{ammo_type.id}"}>
<%= for {_label, field, type} <- @columns_to_display do %>
<td class="p-2">
<%= case type do %>
<% :boolean -> %>
<%= ammo_type |> Map.get(field) |> humanize() %>
<% _other -> %>
<%= ammo_type |> Map.get(field) %>
<% end %>
</td>
<% end %>
<td class="p-2">
<%= ammo_type |> Ammo.get_round_count_for_ammo_type(@current_user) %>
</td>
<td class="p-2">
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<%= live_redirect to: Routes.ammo_type_show_path(Endpoint, :show, ammo_type),
class: "text-primary-600 link",
data: [qa: "view-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-eye"></i>
<% end %>
<%= live_patch to: Routes.ammo_type_index_path(Endpoint, :edit, ammo_type),
class: "text-primary-600 link",
data: [qa: "edit-#{ammo_type.id}"] do %>
<i class="fa-fw fa-lg fas fa-edit"></i>
<% end %>
<%= link to: "#",
class: "text-primary-600 link",
phx_click: "delete",
phx_value_id: ammo_type.id,
data: [
confirm: dgettext("prompts", "Are you sure you want to delete this ammo?"),
qa: "delete-#{ammo_type.id}"
] do %>
<i class="fa-lg fas fa-trash"></i>
<% end %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% end %>
</div>
<%= if @live_action in [:new, :edit] do %>
<.modal return_to={Routes.ammo_type_index_path(Endpoint, :index)}>
<.live_component
module={CanneryWeb.AmmoTypeLive.FormComponent}
id={@ammo_type.id || :new}
title={@page_title}
action={@live_action}
ammo_type={@ammo_type}
return_to={Routes.ammo_type_index_path(Endpoint, :index)}
current_user={@current_user}
}
/>
</.modal>
<% end %>