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">
|
|
|
|
<%= @ammo_type.name %>
|
|
|
|
</h1>
|
|
|
|
|
2022-02-05 16:22:02 -05:00
|
|
|
<%= if @ammo_type.desc do %>
|
2022-04-19 20:08:12 -04:00
|
|
|
<span class="max-w-2xl w-full px-8 py-4 rounded-lg
|
2022-02-05 16:22:02 -05:00
|
|
|
text-center title text-lg
|
2022-04-19 20:08:12 -04:00
|
|
|
border border-primary-600">
|
2022-02-05 16:22:02 -05:00
|
|
|
<%= @ammo_type.desc %>
|
|
|
|
</span>
|
|
|
|
<% end %>
|
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
|
|
|
|
patch={Routes.ammo_type_show_path(Endpoint, :edit, @ammo_type)}
|
|
|
|
class="text-primary-600 link"
|
|
|
|
data-qa="edit"
|
|
|
|
>
|
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!",
|
|
|
|
name: @ammo_type.name
|
|
|
|
)
|
|
|
|
}
|
|
|
|
data-qa="delete"
|
|
|
|
>
|
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
|
|
|
|
2022-11-12 13:52:24 -05:00
|
|
|
<%= if @fields_to_display do %>
|
|
|
|
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
|
|
|
|
<%= for %{label: label, key: key, type: type} <- @fields_list do %>
|
|
|
|
<%= if @ammo_type |> Map.get(key) do %>
|
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= label %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= case type do %>
|
|
|
|
<% :boolean -> %>
|
|
|
|
<%= @ammo_type |> Map.get(key) |> humanize() %>
|
|
|
|
<% _ -> %>
|
|
|
|
<%= @ammo_type |> Map.get(key) %>
|
|
|
|
<% 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">
|
|
|
|
<%= @ammo_type |> Ammo.get_round_count_for_ammo_type(@current_user) %>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<h3 class="title text-lg">
|
2022-11-10 21:25:03 -05:00
|
|
|
<%= gettext("Used rounds:") %>
|
2022-02-19 00:18:24 -05:00
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type |> Ammo.get_used_count_for_ammo_type(@current_user) %>
|
|
|
|
</span>
|
|
|
|
|
2022-11-10 21:25:03 -05:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Total ever rounds:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type |> Ammo.get_historical_count_for_ammo_type(@current_user) %>
|
|
|
|
</span>
|
2022-11-12 13:52:24 -05:00
|
|
|
</div>
|
2022-11-10 21:25:03 -05:00
|
|
|
|
2022-11-12 13:52:24 -05:00
|
|
|
<hr class="hr" />
|
|
|
|
|
|
|
|
<div class="grid sm:grid-cols-2 gap-4 text-center justify-center items-center">
|
2022-11-10 21:25:03 -05:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Packs:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type |> Ammo.get_ammo_groups_count_for_type(@current_user) %>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Used packs:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type |> Ammo.get_used_ammo_groups_count_for_type(@current_user) %>
|
|
|
|
</span>
|
|
|
|
|
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Total ever packs:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type |> Ammo.get_ammo_groups_count_for_type(@current_user, true) %>
|
|
|
|
</span>
|
2022-11-12 13:52:24 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<hr class="hr" />
|
2022-11-10 21:25:03 -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-05-05 21:43:49 -04:00
|
|
|
<h3 class="title text-lg">
|
|
|
|
<%= gettext("Added on:") %>
|
|
|
|
</h3>
|
|
|
|
|
|
|
|
<span class="text-primary-600">
|
|
|
|
<%= @ammo_type.inserted_at |> display_datetime() %>
|
|
|
|
</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">
|
2022-02-17 21:24:59 -05:00
|
|
|
<%= gettext("$%{amount}",
|
|
|
|
amount: @avg_cost_per_round |> :erlang.float_to_binary(decimals: 2)
|
|
|
|
) %>
|
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">
|
2022-02-08 00:21:22 -05:00
|
|
|
<%= if @ammo_groups |> 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
|
|
|
|
module={CanneryWeb.Components.AmmoGroupTableComponent}
|
|
|
|
id="ammo-type-show-table"
|
|
|
|
ammo_groups={@ammo_groups}
|
|
|
|
current_user={@current_user}
|
|
|
|
>
|
|
|
|
<:container :let={%{container: %{name: container_name} = container}}>
|
|
|
|
<.link
|
|
|
|
navigate={Routes.container_show_path(Endpoint, :show, container)}
|
|
|
|
class="mx-2 my-1 link"
|
|
|
|
>
|
|
|
|
<%= container_name %>
|
|
|
|
</.link>
|
|
|
|
</:container>
|
|
|
|
</.live_component>
|
|
|
|
<% else %>
|
|
|
|
<div class="flex flex-wrap justify-center items-center">
|
|
|
|
<%= for ammo_group <- @ammo_groups do %>
|
|
|
|
<.ammo_group_card ammo_group={ammo_group} show_container={true} />
|
|
|
|
<% end %>
|
|
|
|
</div>
|
|
|
|
<% end %>
|
2022-02-05 01:59:40 -05:00
|
|
|
<% end %>
|
|
|
|
</div>
|
2022-01-31 23:20:57 -05:00
|
|
|
</div>
|
|
|
|
|
|
|
|
<%= if @live_action in [:edit] do %>
|
2022-02-14 01:26:51 -05:00
|
|
|
<.modal return_to={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)}>
|
|
|
|
<.live_component
|
|
|
|
module={CanneryWeb.AmmoTypeLive.FormComponent}
|
|
|
|
id={@ammo_type.id}
|
|
|
|
title={@page_title}
|
|
|
|
action={@live_action}
|
|
|
|
ammo_type={@ammo_type}
|
|
|
|
return_to={Routes.ammo_type_show_path(Endpoint, :show, @ammo_type)}
|
|
|
|
current_user={@current_user}
|
|
|
|
/>
|
|
|
|
</.modal>
|
2022-01-31 23:20:57 -05:00
|
|
|
<% end %>
|