2022-11-06 23:08:18 -05:00
|
|
|
<div class="space-y-4 flex flex-col justify-center items-center">
|
2022-01-31 23:20:57 -05:00
|
|
|
<h1 class="title text-2xl title-primary-500">
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= @type.name %>
|
2022-01-31 23:20:57 -05:00
|
|
|
</h1>
|
|
|
|
|
2023-02-04 10:28:13 -05:00
|
|
|
<span
|
2023-03-30 21:53:52 -04:00
|
|
|
:if={@type.desc}
|
2023-02-04 10:28:13 -05:00
|
|
|
class="max-w-2xl w-full px-8 py-4 rounded-lg
|
2023-03-18 21:06:00 -04:00
|
|
|
text-center title text-lg
|
|
|
|
border border-primary-600"
|
2023-02-04 10:28:13 -05:00
|
|
|
>
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= @type.desc %>
|
2023-02-04 10:28:13 -05:00
|
|
|
</span>
|
2022-02-05 01:59:40 -05:00
|
|
|
|
2022-02-17 22:29:01 -05:00
|
|
|
<div class="flex space-x-4 justify-center items-center text-primary-600">
|
2022-11-07 22:36:38 -05:00
|
|
|
<.link
|
2023-04-14 23:34:11 -04:00
|
|
|
patch={~p"/type/#{@type}/edit"}
|
2022-11-07 22:36:38 -05:00
|
|
|
class="text-primary-600 link"
|
2023-03-30 21:53:52 -04:00
|
|
|
aria-label={dgettext("actions", "Edit %{type_name}", type_name: @type.name)}
|
2022-11-07 22:36:38 -05:00
|
|
|
>
|
2022-02-05 01:59:40 -05:00
|
|
|
<i class="fa-fw fa-lg fas fa-edit"></i>
|
2022-11-07 22:36:38 -05:00
|
|
|
</.link>
|
2022-02-05 01:59:40 -05:00
|
|
|
|
2022-11-07 22:36:38 -05:00
|
|
|
<.link
|
|
|
|
href="#"
|
|
|
|
class="text-primary-600 link"
|
|
|
|
phx-click="delete"
|
|
|
|
data-confirm={
|
|
|
|
dgettext(
|
|
|
|
"prompts",
|
|
|
|
"Are you sure you want to delete %{name}? This will delete all %{name} type ammo as well!",
|
2023-03-30 21:53:52 -04:00
|
|
|
name: @type.name
|
2022-11-07 22:36:38 -05:00
|
|
|
)
|
|
|
|
}
|
2023-03-30 21:53:52 -04:00
|
|
|
aria-label={dgettext("actions", "Delete %{type_name}", type_name: @type.name)}
|
2022-11-07 22:36:38 -05:00
|
|
|
>
|
2022-02-05 01:59:40 -05:00
|
|
|
<i class="fa-fw fa-lg fas fa-trash"></i>
|
2022-11-07 22:36:38 -05:00
|
|
|
</.link>
|
2022-01-31 23:20:57 -05:00
|
|
|
</div>
|
|
|
|
|
2022-02-17 21:24:59 -05:00
|
|
|
<hr class="hr" />
|
2022-02-05 16:22:02 -05:00
|
|
|
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= if @type.class || @custom_fields? do %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
|
2023-03-23 22:07:25 -04:00
|
|
|
<h3 class="title text-lg">
|
2023-03-28 23:08:40 -04:00
|
|
|
<%= gettext("Class") %>
|
2023-03-23 22:07:25 -04:00
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= case @type.class do %>
|
2023-03-23 22:07:25 -04:00
|
|
|
<% :shotgun -> %>
|
|
|
|
<%= gettext("Shotgun") %>
|
|
|
|
<% :rifle -> %>
|
|
|
|
<%= gettext("Rifle") %>
|
|
|
|
<% :pistol -> %>
|
|
|
|
<%= gettext("Pistol") %>
|
|
|
|
<% _ -> %>
|
|
|
|
<%= gettext("None specified") %>
|
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<%= for %{label: label, key: key, type: type} <- @fields_to_display do %>
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= if @type |> Map.get(key) do %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= label %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= case type do %>
|
|
|
|
<% :boolean -> %>
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= @type |> Map.get(key) |> humanize() %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<% _ -> %>
|
2023-03-30 21:53:52 -04:00
|
|
|
<%= @type |> Map.get(key) %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<% end %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
2022-02-05 16:22:02 -05:00
|
|
|
<% end %>
|
2022-11-12 13:52:24 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="hr" />
|
|
|
|
<% end %>
|
2022-02-06 00:40:01 -05:00
|
|
|
|
2022-11-12 13:52:24 -05:00
|
|
|
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
|
2022-02-19 00:18:24 -05:00
|
|
|
<h3 class="title text-lg">
|
2022-11-10 21:25:03 -05:00
|
|
|
<%= gettext("Rounds:") %>
|
2022-02-19 00:18:24 -05:00
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
2023-03-18 21:06:00 -04:00
|
|
|
<%= @rounds %>
|
2022-02-19 00:18:24 -05:00
|
|
|
</span>
|
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<%= if @show_used do %>
|
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Used rounds:") %>
|
|
|
|
</h3>
|
2022-02-19 00:18:24 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @used_rounds %>
|
|
|
|
</span>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Total ever rounds:") %>
|
|
|
|
</h3>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @historical_round_count %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
2022-11-12 13:52:24 -05:00
|
|
|
|
2022-11-10 21:25:03 -05:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Packs:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
2023-03-18 21:06:00 -04:00
|
|
|
<%= @packs_count %>
|
2022-11-10 21:25:03 -05:00
|
|
|
</span>
|
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<%= if @show_used do %>
|
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Used packs:") %>
|
|
|
|
</h3>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @used_packs_count %>
|
|
|
|
</span>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Total ever packs:") %>
|
|
|
|
</h3>
|
2022-11-12 13:52:24 -05:00
|
|
|
|
2023-03-19 11:43:13 -04:00
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @historical_packs_count %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2022-05-05 21:43:49 -04:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Added on:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
2023-03-30 21:53:52 -04:00
|
|
|
<.datetime id={"#{@type.id}-inserted-at"} datetime={@type.inserted_at} />
|
2022-05-05 21:43:49 -04:00
|
|
|
</span>
|
|
|
|
|
2022-02-06 00:40:01 -05:00
|
|
|
<%= if @avg_cost_per_round do %>
|
2022-02-18 23:25:44 -05:00
|
|
|
<h3 class="title text-lg">
|
2022-11-12 13:52:24 -05:00
|
|
|
<%= gettext("Average CPR") %>:
|
2022-02-06 00:40:01 -05:00
|
|
|
</h3>
|
|
|
|
|
2022-02-18 23:25:44 -05:00
|
|
|
<span class="text-primary-600">
|
2023-03-18 21:06:00 -04:00
|
|
|
<%= gettext("$%{amount}", amount: display_currency(@avg_cost_per_round)) %>
|
2022-02-06 00:40:01 -05:00
|
|
|
</span>
|
2022-02-18 23:25:44 -05:00
|
|
|
<% else %>
|
2022-02-23 19:41:21 -05:00
|
|
|
<h3 class="mx-8 my-4 title text-lg text-primary-600 col-span-2">
|
2022-02-18 23:25:44 -05:00
|
|
|
<%= gettext("No cost information") %>
|
|
|
|
</h3>
|
2022-02-06 00:40:01 -05:00
|
|
|
<% end %>
|
2022-02-05 16:22:02 -05:00
|
|
|
</div>
|
|
|
|
|
2022-02-17 21:24:59 -05:00
|
|
|
<hr class="hr" />
|
2022-02-05 01:59:40 -05:00
|
|
|
|
2022-11-12 13:52:24 -05:00
|
|
|
<div class="flex justify-center items-center space-x-4">
|
2022-11-07 00:25:34 -05:00
|
|
|
<.toggle_button action="toggle_show_used" value={@show_used}>
|
|
|
|
<span class="title text-lg text-primary-600">
|
|
|
|
<%= gettext("Show used") %>
|
|
|
|
</span>
|
|
|
|
</.toggle_button>
|
2022-11-12 13:52:24 -05:00
|
|
|
|
|
|
|
<.toggle_button action="toggle_table" value={@view_table}>
|
|
|
|
<span class="title text-lg text-primary-600">
|
|
|
|
<%= gettext("View as table") %>
|
|
|
|
</span>
|
|
|
|
</.toggle_button>
|
2022-11-07 00:25:34 -05:00
|
|
|
</div>
|
|
|
|
|
2022-11-12 13:52:24 -05:00
|
|
|
<div class="w-full p-4">
|
2023-03-29 22:54:55 -04:00
|
|
|
<%= if @packs |> Enum.empty?() do %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<h2 class="px-4 title text-lg text-primary-600">
|
2022-02-23 19:41:21 -05:00
|
|
|
<%= gettext("No ammo for this type") %>
|
|
|
|
<%= display_emoji("😔") %>
|
|
|
|
</h2>
|
2022-02-05 01:59:40 -05:00
|
|
|
<% else %>
|
2022-11-12 13:52:24 -05:00
|
|
|
<%= if @view_table do %>
|
|
|
|
<.live_component
|
2023-03-29 22:54:55 -04:00
|
|
|
module={CanneryWeb.Components.PackTableComponent}
|
2023-03-30 21:53:52 -04:00
|
|
|
id="type-show-table"
|
2023-03-29 22:54:55 -04:00
|
|
|
packs={@packs}
|
2022-11-12 13:52:24 -05:00
|
|
|
current_user={@current_user}
|
2023-03-19 14:11:01 -04:00
|
|
|
show_used={@show_used}
|
2022-11-12 13:52:24 -05:00
|
|
|
>
|
2023-03-29 22:54:55 -04:00
|
|
|
<:container :let={{_pack, %{name: container_name} = container}}>
|
2023-04-14 23:34:11 -04:00
|
|
|
<.link navigate={~p"/container/#{container}"} class="mx-2 my-1 link">
|
2022-11-12 13:52:24 -05:00
|
|
|
<%= container_name %>
|
|
|
|
</.link>
|
|
|
|
</:container>
|
2023-03-29 22:54:55 -04:00
|
|
|
<:actions :let={%{count: pack_count} = pack}>
|
2023-03-19 15:09:44 -04:00
|
|
|
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
|
|
|
|
<.link
|
2023-04-14 23:34:11 -04:00
|
|
|
navigate={~p"/ammo/show/#{pack}"}
|
2023-03-19 15:09:44 -04:00
|
|
|
class="text-primary-600 link"
|
|
|
|
aria-label={
|
2023-09-07 19:14:42 -04:00
|
|
|
dgettext("actions", "View pack of %{pack_count} bullets",
|
|
|
|
pack_count: pack_count
|
|
|
|
)
|
2023-03-19 15:09:44 -04:00
|
|
|
}
|
|
|
|
>
|
|
|
|
<i class="fa-fw fa-lg fas fa-eye"></i>
|
|
|
|
</.link>
|
|
|
|
</div>
|
|
|
|
</:actions>
|
2022-11-12 13:52:24 -05:00
|
|
|
</.live_component>
|
|
|
|
<% else %>
|
2022-12-03 22:09:32 -05:00
|
|
|
<div class="flex flex-wrap justify-center items-stretch">
|
2023-03-29 22:58:07 -04:00
|
|
|
<.pack_card
|
2023-03-29 22:54:55 -04:00
|
|
|
:for={%{id: pack_id, container_id: container_id} = pack <- @packs}
|
|
|
|
pack={pack}
|
|
|
|
original_count={@original_counts && Map.fetch!(@original_counts, pack_id)}
|
|
|
|
cpr={Map.get(@cprs, pack_id)}
|
|
|
|
last_used_date={Map.get(@last_used_dates, pack_id)}
|
2023-03-18 21:06:00 -04:00
|
|
|
current_user={@current_user}
|
2023-03-19 15:05:09 -04:00
|
|
|
container={Map.fetch!(@containers, container_id)}
|
2023-02-04 10:28:13 -05:00
|
|
|
/>
|
2022-11-12 13:52:24 -05:00
|
|
|
</div>
|
|
|
|
<% end %>
|
2022-02-05 01:59:40 -05:00
|
|
|
<% end %>
|
|
|
|
</div>
|
2022-01-31 23:20:57 -05:00
|
|
|
</div>
|
|
|
|
|
2023-04-14 23:34:11 -04:00
|
|
|
<.modal :if={@live_action == :edit} return_to={~p"/type/#{@type}"}>
|
2023-02-04 10:28:13 -05:00
|
|
|
<.live_component
|
2023-03-30 21:53:52 -04:00
|
|
|
module={CanneryWeb.TypeLive.FormComponent}
|
|
|
|
id={@type.id}
|
2023-02-04 10:28:13 -05:00
|
|
|
title={@page_title}
|
|
|
|
action={@live_action}
|
2023-03-30 21:53:52 -04:00
|
|
|
type={@type}
|
2023-04-14 23:34:11 -04:00
|
|
|
return_to={~p"/type/#{@type}"}
|
2023-02-04 10:28:13 -05:00
|
|
|
current_user={@current_user}
|
|
|
|
/>
|
|
|
|
</.modal>
|