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

195 lines
5.7 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-15 17:33:45 -05:00
<h1 class="title text-2xl title-primary-500">
<%= gettext("Range day") %>
</h1>
2023-03-29 22:54:55 -04:00
<%= if @packs |> Enum.empty?() do %>
2022-02-17 22:29:01 -05:00
<h1 class="title text-xl text-primary-600">
2022-02-15 23:52:44 -05:00
<%= gettext("No ammo staged") %>
<%= display_emoji("😔") %>
2022-02-15 17:33:45 -05:00
</h1>
2023-04-14 23:34:11 -04:00
<.link navigate={~p"/ammo"} class="btn btn-primary">
<%= dgettext("actions", "Why not get some ready to shoot?") %>
</.link>
2022-02-15 17:33:45 -05:00
<% else %>
2023-04-14 23:34:11 -04:00
<.link navigate={~p"/ammo"} class="btn btn-primary">
<%= dgettext("actions", "Stage ammo") %>
</.link>
2022-02-15 17:33:45 -05:00
2022-12-03 22:09:32 -05:00
<div class="w-full flex flex-row 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} = pack <- @packs}
pack={pack}
original_count={Map.fetch!(@original_counts, pack_id)}
cpr={Map.get(@cprs, pack_id)}
last_used_date={Map.get(@last_used_dates, pack_id)}
current_user={@current_user}
>
2023-02-04 10:28:13 -05:00
<button
type="button"
class="btn btn-primary"
phx-click="toggle_staged"
2023-03-29 22:54:55 -04:00
phx-value-pack_id={pack.id}
2023-02-04 10:28:13 -05:00
data-confirm={"#{dgettext("prompts", "Are you sure you want to unstage this ammo?")}"}
>
2023-03-29 22:54:55 -04:00
<%= if pack.staged,
2023-02-04 10:28:13 -05:00
do: dgettext("actions", "Unstage from range"),
else: dgettext("actions", "Stage for range") %>
</button>
2022-02-15 17:33:45 -05:00
2023-04-14 23:34:11 -04:00
<.link patch={~p"/range/add_shot_record/#{pack}"} class="btn btn-primary">
2023-02-04 10:28:13 -05:00
<%= dgettext("actions", "Record shots") %>
</.link>
2023-03-29 22:58:07 -04:00
</.pack_card>
2022-12-03 22:09:32 -05:00
</div>
2022-02-15 17:33:45 -05:00
<% end %>
2022-02-17 21:24:59 -05:00
<hr class="hr" />
2022-02-15 17:33:45 -05:00
<%= if @shot_record_count == 0 do %>
2022-02-17 22:29:01 -05:00
<h1 class="title text-xl text-primary-600">
2022-02-15 23:52:44 -05:00
<%= gettext("No shots recorded") %>
<%= display_emoji("😔") %>
2022-02-15 17:33:45 -05:00
</h1>
<% else %>
2022-02-17 22:29:01 -05:00
<h1 class="title text-2xl text-primary-600">
<%= gettext("Shot log") %>
</h1>
2022-11-09 21:04:57 -05:00
<canvas
id="shot-log-chart"
phx-hook="ShotLogChart"
phx-update="ignore"
class="max-h-72"
data-chart-data={Jason.encode!(@chart_data)}
2022-11-11 19:34:23 -05:00
data-label={gettext("Rounds shot")}
2022-11-09 21:04:57 -05:00
data-color={random_color()}
2022-11-11 19:34:23 -05:00
aria-label={gettext("Rounds shot chart")}
2022-11-09 21:04:57 -05:00
role="img"
>
<%= dgettext("errors", "Your browser does not support the canvas element.") %>
</canvas>
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-09-07 19:14:42 -04:00
<%= label(f, :class, gettext("Class"),
class: "title text-primary-600 text-lg text-center"
) %>
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-12-03 21:27:39 -05:00
<.form
:let={f}
2023-03-17 21:06:08 -04:00
for={%{}}
as={:search}
2022-12-03 21:27:39 -05:00
phx-change="search"
phx-submit="search"
2023-03-23 22:07:25 -04:00
class="grow flex items-center"
2022-12-03 21:27:39 -05:00
>
<%= text_input(f, :search_term,
2023-03-23 22:07:25 -04:00
class: "grow input input-primary",
2022-12-03 21:27:39 -05:00
phx_debounce: 300,
2024-07-28 12:52:41 -04:00
placeholder: gettext("Search shot records"),
role: "search",
value: @search
2022-12-03 21:27:39 -05:00
) %>
</.form>
</div>
2023-03-30 20:43:30 -04:00
<%= if @shot_records |> Enum.empty?() do %>
2022-12-03 21:27:39 -05:00
<h1 class="title text-xl text-primary-600">
<%= gettext("No shots recorded") %>
<%= display_emoji("😔") %>
</h1>
<% else %>
<.live_component
2023-03-30 20:43:30 -04:00
module={CanneryWeb.Components.ShotRecordTableComponent}
2023-05-12 21:50:23 -04:00
id="shot-records-index-table"
2023-03-30 20:43:30 -04:00
shot_records={@shot_records}
2022-12-03 21:40:05 -05:00
current_user={@current_user}
>
2023-03-30 20:43:30 -04:00
<:actions :let={shot_record}>
2022-12-03 21:40:05 -05:00
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<.link
2023-04-14 23:34:11 -04:00
patch={~p"/range/edit/#{shot_record}"}
2022-12-03 21:40:05 -05:00
class="text-primary-600 link"
2023-03-15 00:45:08 -04:00
aria-label={
2023-03-30 20:43:30 -04:00
dgettext("actions", "Edit shot record of %{shot_record_count} shots",
shot_record_count: shot_record.count
2023-03-15 00:45:08 -04:00
)
}
2022-12-03 21:40:05 -05:00
>
<i class="fa-fw fa-lg fas fa-edit"></i>
</.link>
<.link
href="#"
class="text-primary-600 link"
phx-click="delete"
2023-03-30 20:43:30 -04:00
phx-value-id={shot_record.id}
2022-12-03 21:40:05 -05:00
data-confirm={
dgettext("prompts", "Are you sure you want to delete this shot record?")
}
2023-03-15 00:45:08 -04:00
aria-label={
2023-03-30 20:43:30 -04:00
dgettext("actions", "Delete shot record of %{shot_record_count} shots",
shot_record_count: shot_record.count
2023-03-15 00:45:08 -04:00
)
}
2022-12-03 21:40:05 -05:00
>
<i class="fa-fw fa-lg fas fa-trash"></i>
</.link>
</div>
</:actions>
</.live_component>
2022-12-03 21:27:39 -05:00
<% end %>
2022-02-15 17:33:45 -05:00
<% end %>
</div>
<%= case @live_action do %>
<% :edit -> %>
2023-04-14 23:34:11 -04:00
<.modal return_to={~p"/range"}>
<.live_component
module={CanneryWeb.RangeLive.FormComponent}
2023-03-30 20:43:30 -04:00
id={@shot_record.id}
title={@page_title}
action={@live_action}
2023-03-30 20:43:30 -04:00
shot_record={@shot_record}
2023-04-14 23:34:11 -04:00
return_to={~p"/range"}
current_user={@current_user}
/>
</.modal>
2023-03-30 20:43:30 -04:00
<% :add_shot_record -> %>
2023-04-14 23:34:11 -04:00
<.modal return_to={~p"/range"}>
<.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}
2023-04-14 23:34:11 -04:00
return_to={~p"/range"}
current_user={@current_user}
/>
</.modal>
<% _ -> %>
<% end %>