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

163 lines
5.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-15 17:33:45 -05:00
<h1 class="title text-2xl title-primary-500">
<%= gettext("Range day") %>
</h1>
<%= if @ammo_groups |> 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>
2022-11-09 23:47:11 -05:00
<.link navigate={Routes.ammo_group_index_path(Endpoint, :index)} class="btn btn-primary">
<%= dgettext("actions", "Why not get some ready to shoot?") %>
</.link>
2022-02-15 17:33:45 -05:00
<% else %>
2022-11-09 23:47:11 -05:00
<.link navigate={Routes.ammo_group_index_path(Endpoint, :index)} 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-02-04 10:28:13 -05:00
<.ammo_group_card :for={ammo_group <- @ammo_groups} ammo_group={ammo_group}>
<button
type="button"
class="btn btn-primary"
phx-click="toggle_staged"
phx-value-ammo_group_id={ammo_group.id}
data-confirm={"#{dgettext("prompts", "Are you sure you want to unstage this ammo?")}"}
>
<%= if ammo_group.staged,
do: dgettext("actions", "Unstage from range"),
else: dgettext("actions", "Stage for range") %>
</button>
2022-02-15 17:33:45 -05:00
2023-02-04 10:28:13 -05:00
<.link
patch={Routes.range_index_path(Endpoint, :add_shot_group, ammo_group)}
class="btn btn-primary"
>
<%= dgettext("actions", "Record shots") %>
</.link>
</.ammo_group_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
2022-12-03 21:27:39 -05:00
<%= if @shot_groups |> Enum.empty?() and @search |> is_nil() 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>
2022-12-03 21:27:39 -05: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-xl">
<.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"
class="grow self-stretch flex flex-col items-stretch"
>
<%= text_input(f, :search_term,
class: "input input-primary",
value: @search,
phx_debounce: 300,
placeholder: gettext("Search shot records")
) %>
</.form>
</div>
<%= if @shot_groups |> Enum.empty?() do %>
<h1 class="title text-xl text-primary-600">
<%= gettext("No shots recorded") %>
<%= display_emoji("😔") %>
</h1>
<% else %>
<.live_component
2022-12-03 21:40:05 -05:00
module={CanneryWeb.Components.ShotGroupTableComponent}
2022-12-03 21:27:39 -05:00
id="shot_groups_index_table"
2022-12-03 21:40:05 -05:00
shot_groups={@shot_groups}
current_user={@current_user}
>
<:actions :let={shot_group}>
<div class="px-4 py-2 space-x-4 flex justify-center items-center">
<.link
patch={Routes.range_index_path(Endpoint, :edit, shot_group)}
class="text-primary-600 link"
2023-03-15 00:45:08 -04:00
aria-label={
2023-03-17 21:00:24 -04:00
dgettext("actions", "Edit shot record of %{shot_group_count} shots",
2023-03-15 00:45:08 -04:00
shot_group_count: shot_group.count
)
}
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"
phx-value-id={shot_group.id}
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-17 21:00:24 -04:00
dgettext("actions", "Delete shot record of %{shot_group_count} shots",
2023-03-15 00:45:08 -04:00
shot_group_count: shot_group.count
)
}
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>
2023-02-04 10:28:13 -05:00
<.modal :if={@live_action == :edit} return_to={Routes.range_index_path(Endpoint, :index)}>
<.live_component
module={CanneryWeb.RangeLive.FormComponent}
id={@shot_group.id}
title={@page_title}
action={@live_action}
shot_group={@shot_group}
return_to={Routes.range_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>
2022-02-15 17:33:45 -05:00
2023-02-04 10:28:13 -05:00
<.modal
:if={@live_action == :add_shot_group}
return_to={Routes.range_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.range_index_path(Endpoint, :index)}
current_user={@current_user}
/>
</.modal>