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

183 lines
6.3 KiB
Plaintext

<div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500">
<%= gettext("Ammo") %>
</h1>
<%= if @ammo_groups |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<%= gettext("No Ammo") %>
<%= display_emoji("😔") %>
</h2>
<% end %>
<%= cond do %>
<% @containers_count == 0 -> %>
<div class="flex justify-center items-center">
<h2 class="m-2 title text-md text-primary-600">
<%= dgettext("prompts", "You'll need to") %>
</h2>
<.link navigate={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add a container first") %>
</.link>
</div>
<% @ammo_types_count == 0 -> %>
<div class="flex justify-center items-center">
<h2 class="m-2 title text-md text-primary-600">
<%= dgettext("prompts", "You'll need to") %>
</h2>
<.link navigate={Routes.ammo_type_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add an ammo type first") %>
</.link>
</div>
<% @ammo_groups |> Enum.empty?() -> %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add your first box!") %>
</.link>
<% true -> %>
<.link patch={Routes.ammo_group_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add Ammo") %>
</.link>
<% end %>
<%= unless @ammo_groups |> Enum.empty?() do %>
<div class="flex flex-col space-y-4 justify-center items-center">
<.toggle_button action="toggle_show_used" value={@show_used}>
<span class="title text-lg text-primary-600">
<%= gettext("Show used") %>
</span>
</.toggle_button>
</div>
<.live_component
module={CanneryWeb.Components.AmmoGroupTableComponent}
id="ammo-group-index-table"
ammo_groups={@ammo_groups}
current_user={@current_user}
show_used={@show_used}
>
<:ammo_type :let={%{name: ammo_type_name} = ammo_type}>
<.link navigate={Routes.ammo_type_show_path(Endpoint, :show, ammo_type)} class="link">
<%= ammo_type_name %>
</.link>
</:ammo_type>
<:range :let={ammo_group}>
<div class="min-w-20 py-2 px-4 h-full flex flew-wrap justify-center items-center">
<button
type="button"
class="mx-2 my-1 text-sm 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>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :add_shot_group, ammo_group)}
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</div>
</:range>
<:container :let={%{container: %{name: container_name} = container} = ammo_group}>
<div class="min-w-20 py-2 px-4 h-full flex flew-wrap justify-center items-center">
<.link
navigate={Routes.container_show_path(Endpoint, :show, container)}
class="mx-2 my-1 link"
>
<%= container_name %>
</.link>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :move, ammo_group)}
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= gettext("Move ammo") %>
</.link>
</div>
</:container>
<:actions :let={ammo_group}>
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
<.link
navigate={Routes.ammo_group_show_path(Endpoint, :show, ammo_group)}
class="text-primary-600 link"
data-qa={"view-#{ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-eye"></i>
</.link>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :edit, ammo_group)}
class="text-primary-600 link"
data-qa={"edit-#{ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
</.link>
<.link
patch={Routes.ammo_group_index_path(Endpoint, :clone, ammo_group)}
class="text-primary-600 link"
data-qa={"clone-#{ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-copy"></i>
</.link>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
phx-value-id={ammo_group.id}
data-confirm={dgettext("prompts", "Are you sure you want to delete this ammo?")}
data-qa={"delete-#{ammo_group.id}"}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
</.link>
</div>
</:actions>
</.live_component>
<% end %>
</div>
<%= cond do %>
<% @live_action in [:new, :edit, :clone] -> %>
<.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 -> %>
<%= nil %>
<% end %>