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

242 lines
8.1 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>
<%= 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>
2022-11-09 23:47:11 -05:00
<.link navigate={Routes.container_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add a container first") %>
</.link>
</div>
2023-03-30 21:53:52 -04:00
<% @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>
2023-03-30 21:53:52 -04:00
<.link navigate={Routes.type_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "add a type first") %>
</.link>
</div>
2023-03-29 22:54:55 -04:00
<% @packs_count == 0 -> %>
2023-03-23 22:07:25 -04:00
<h2 class="title text-xl text-primary-600">
<%= gettext("No ammo") %>
<%= display_emoji("😔") %>
</h2>
2023-03-29 22:54:55 -04:00
<.link patch={Routes.pack_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add your first box!") %>
</.link>
<% true -> %>
2023-03-29 22:54:55 -04:00
<.link patch={Routes.pack_index_path(Endpoint, :new)} class="btn btn-primary">
<%= dgettext("actions", "Add Ammo") %>
</.link>
2022-02-01 00:14:14 -05:00
2023-03-23 22:07:25 -04:00
<div class="w-full flex flex-col sm:flex-row justify-center items-center space-y-4 sm:space-y-0 sm:space-x-4 max-w-2xl">
<.form
:let={f}
for={%{}}
2023-03-30 21:53:52 -04:00
as={:type}
2023-03-28 23:08:40 -04:00
phx-change="change_class"
phx-submit="change_class"
2023-03-23 22:07:25 -04:00
class="flex items-center"
>
2023-03-28 23:08:40 -04:00
<%= label(f, :class, gettext("Class"),
class: "title text-primary-600 text-lg text-center"
) %>
2022-12-03 18:46:44 -05:00
2023-03-23 22:07:25 -04:00
<%= select(
f,
2023-03-28 23:08:40 -04:00
:class,
2023-03-23 22:07:25 -04:00
[
{gettext("All"), :all},
{gettext("Rifle"), :rifle},
{gettext("Shotgun"), :shotgun},
{gettext("Pistol"), :pistol}
],
class: "mx-2 my-1 min-w-md input input-primary",
2023-03-28 23:08:40 -04:00
value: @class
2023-03-23 22:07:25 -04:00
) %>
</.form>
2022-11-07 00:47:22 -05:00
2023-03-23 22:07:25 -04:00
<.form
:let={f}
for={%{}}
as={:search}
phx-change="search"
phx-submit="search"
class="grow flex items-center"
>
<%= text_input(f, :search_term,
class: "grow input input-primary",
value: @search,
role: "search",
phx_debounce: 300,
placeholder: gettext("Search ammo")
) %>
</.form>
<.toggle_button action="toggle_show_used" value={@show_used}>
<span class="title text-lg text-primary-600">
<%= gettext("Show used") %>
</span>
</.toggle_button>
</div>
2023-03-29 22:54:55 -04:00
<%= if @packs |> Enum.empty?() do %>
2023-03-23 22:07:25 -04:00
<h2 class="title text-xl text-primary-600">
<%= gettext("No Ammo") %>
<%= display_emoji("😔") %>
</h2>
<% else %>
<.live_component
2023-03-29 22:54:55 -04:00
module={CanneryWeb.Components.PackTableComponent}
2023-03-30 21:38:56 -04:00
id="pack-index-table"
2023-03-29 22:54:55 -04:00
packs={@packs}
2023-03-23 22:07:25 -04:00
current_user={@current_user}
show_used={@show_used}
>
2023-03-30 21:53:52 -04:00
<:type :let={%{name: type_name} = type}>
<.link navigate={Routes.type_show_path(Endpoint, :show, type)} class="link">
<%= type_name %>
2023-03-23 22:07:25 -04:00
</.link>
2023-03-30 21:53:52 -04:00
</:type>
2023-03-29 22:54:55 -04:00
<:range :let={pack}>
2023-03-23 22:07:25 -04:00
<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"
2023-03-29 22:54:55 -04:00
phx-value-pack_id={pack.id}
2023-03-23 22:07:25 -04:00
>
2023-03-29 22:54:55 -04:00
<%= if pack.staged,
2023-03-23 22:07:25 -04:00
do: dgettext("actions", "Unstage"),
else: dgettext("actions", "Stage") %>
</button>
2023-03-23 22:07:25 -04:00
<.link
2023-03-30 20:43:30 -04:00
patch={Routes.pack_index_path(Endpoint, :add_shot_record, pack)}
2023-03-23 22:07:25 -04:00
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</div>
</:range>
2023-03-29 22:54:55 -04:00
<:container :let={{pack, %{name: container_name} = container}}>
2023-03-23 22:07:25 -04:00
<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>
2023-03-23 22:07:25 -04:00
<.link
2023-03-29 22:54:55 -04:00
patch={Routes.pack_index_path(Endpoint, :move, pack)}
2023-03-23 22:07:25 -04:00
class="mx-2 my-1 text-sm btn btn-primary"
>
<%= dgettext("actions", "Move ammo") %>
</.link>
</div>
</:container>
2023-03-29 22:54:55 -04:00
<:actions :let={%{count: pack_count} = pack}>
2023-03-23 22:07:25 -04:00
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
<.link
2023-03-29 22:54:55 -04:00
navigate={Routes.pack_show_path(Endpoint, :show, pack)}
2023-03-23 22:07:25 -04:00
class="text-primary-600 link"
aria-label={
2023-03-29 23:49:45 -04:00
dgettext("actions", "View pack of %{pack_count} bullets", pack_count: pack_count)
2023-03-23 22:07:25 -04:00
}
>
<i class="fa-fw fa-lg fas fa-eye"></i>
</.link>
2023-03-23 22:07:25 -04:00
<.link
2023-03-29 22:54:55 -04:00
patch={Routes.pack_index_path(Endpoint, :edit, pack)}
2023-03-23 22:07:25 -04:00
class="text-primary-600 link"
aria-label={
2023-03-29 23:49:45 -04:00
dgettext("actions", "Edit pack of %{pack_count} bullets", pack_count: pack_count)
2023-03-23 22:07:25 -04:00
}
>
<i class="fa-fw fa-lg fas fa-edit"></i>
</.link>
2023-03-23 22:07:25 -04:00
<.link
2023-03-29 22:54:55 -04:00
patch={Routes.pack_index_path(Endpoint, :clone, pack)}
2023-03-23 22:07:25 -04:00
class="text-primary-600 link"
aria-label={
2023-03-29 23:49:45 -04:00
dgettext("actions", "Clone pack of %{pack_count} bullets",
2023-03-29 22:54:55 -04:00
pack_count: pack_count
2023-03-23 22:07:25 -04:00
)
}
>
<i class="fa-fw fa-lg fas fa-copy"></i>
</.link>
2023-03-23 22:07:25 -04:00
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
2023-03-29 22:54:55 -04:00
phx-value-id={pack.id}
2023-03-23 22:07:25 -04:00
data-confirm={dgettext("prompts", "Are you sure you want to delete this ammo?")}
aria-label={
2023-03-29 23:49:45 -04:00
dgettext("actions", "Delete pack of %{pack_count} bullets",
2023-03-29 22:54:55 -04:00
pack_count: pack_count
2023-03-23 22:07:25 -04:00
)
}
>
<i class="fa-fw fa-lg fas fa-trash"></i>
</.link>
</div>
</:actions>
</.live_component>
<% end %>
2022-02-01 00:14:14 -05:00
<% end %>
</div>
<%= case @live_action do %>
<% create when create in [:new, :edit, :clone] -> %>
2023-03-29 22:54:55 -04:00
<.modal return_to={Routes.pack_index_path(Endpoint, :index)}>
<.live_component
2023-03-29 22:54:55 -04:00
module={CanneryWeb.PackLive.FormComponent}
id={@pack.id || :new}
title={@page_title}
action={@live_action}
2023-03-29 22:54:55 -04:00
pack={@pack}
return_to={Routes.pack_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
2023-03-30 20:43:30 -04:00
<% :add_shot_record -> %>
2023-03-29 22:54:55 -04:00
<.modal return_to={Routes.pack_index_path(Endpoint, :index)}>
<.live_component
2023-03-30 20:43:30 -04:00
module={CanneryWeb.Components.AddShotRecordComponent}
id={:new}
title={@page_title}
action={@live_action}
2023-03-29 22:54:55 -04:00
pack={@pack}
return_to={Routes.pack_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
<% :move -> %>
2023-03-29 22:54:55 -04:00
<.modal return_to={Routes.pack_index_path(Endpoint, :index)}>
<.live_component
2023-03-29 22:54:55 -04:00
module={CanneryWeb.Components.MovePackComponent}
id={@pack.id}
title={@page_title}
action={@live_action}
2023-03-29 22:54:55 -04:00
pack={@pack}
return_to={Routes.pack_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
<% _ -> %>
<% end %>