move staging to container

This commit is contained in:
2025-01-31 23:44:11 -05:00
parent 4464743639
commit 9fb77e8a5d
48 changed files with 948 additions and 899 deletions

View File

@ -96,18 +96,6 @@ defmodule CanneryWeb.PackLive.Index do
{:noreply, socket |> put_flash(:info, prompt) |> display_packs()}
end
def handle_event(
"toggle_staged",
%{"pack_id" => id},
%{assigns: %{current_user: current_user}} = socket
) do
pack = Ammo.get_pack!(id, current_user)
{:ok, _pack} = pack |> Ammo.update_pack(%{"staged" => !pack.staged}, current_user)
{:noreply, socket |> display_packs()}
end
def handle_event("toggle_show_used", _params, %{assigns: %{show_used: show_used}} = socket) do
{:noreply, socket |> assign(:show_used, !show_used) |> display_packs()}
end

View File

@ -1,5 +1,5 @@
<div class="flex flex-col space-y-8 justify-center items-center">
<h1 class="title text-2xl title-primary-500">
<div class="flex flex-col justify-center items-center space-y-8">
<h1 class="text-2xl title title-primary-500">
<%= gettext("Ammo") %>
</h1>
@ -25,7 +25,7 @@
</.link>
</div>
<% @packs_count == 0 -> %>
<h2 class="title text-xl text-primary-600">
<h2 class="text-xl title text-primary-600">
<%= gettext("No ammo") %>
<%= display_emoji("😔") %>
</h2>
@ -38,7 +38,7 @@
<%= dgettext("actions", "Add Ammo") %>
</.link>
<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">
<div class="flex flex-col justify-center items-center space-y-4 w-full max-w-2xl sm:flex-row sm:space-y-0 sm:space-x-4">
<.form
:let={f}
for={%{}}
@ -71,7 +71,7 @@
as={:search}
phx-change="search"
phx-submit="search"
class="grow flex items-center"
class="flex items-center grow"
>
<%= text_input(f, :search_term,
class: "grow input input-primary",
@ -83,14 +83,14 @@
</.form>
<.toggle_button action="toggle_show_used" value={@show_used}>
<span class="title text-lg text-primary-600">
<span class="text-lg title text-primary-600">
<%= gettext("Show used") %>
</span>
</.toggle_button>
</div>
<%= if @packs |> Enum.empty?() do %>
<h2 class="title text-xl text-primary-600">
<h2 class="text-xl title text-primary-600">
<%= gettext("No Ammo") %>
<%= display_emoji("😔") %>
</h2>
@ -108,18 +108,7 @@
</.link>
</:type>
<:range :let={pack}>
<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"
phx-value-pack_id={pack.id}
>
<%= if pack.staged,
do: dgettext("actions", "Unstage"),
else: dgettext("actions", "Stage") %>
</button>
<div class="flex flex-wrap justify-center items-center px-4 py-2 h-full min-w-20">
<.link
patch={~p"/ammo/add_shot_record/#{pack}"}
class="mx-2 my-1 text-sm btn btn-primary"
@ -129,7 +118,7 @@
</div>
</:range>
<:container :let={{pack, %{name: container_name} = container}}>
<div class="min-w-20 py-2 px-4 h-full flex flew-wrap justify-center items-center">
<div class="flex flex-wrap justify-center items-center px-4 py-2 h-full min-w-20">
<.link navigate={~p"/container/#{container}"} class="mx-2 my-1 link">
<%= container_name %>
</.link>
@ -140,7 +129,7 @@
</div>
</:container>
<:actions :let={%{count: pack_count} = pack}>
<div class="py-2 px-4 h-full space-x-4 flex justify-center items-center">
<div class="flex justify-center items-center px-4 py-2 space-x-4 h-full">
<.link
navigate={~p"/ammo/show/#{pack}"}
class="text-primary-600 link"

View File

@ -57,16 +57,6 @@ defmodule CanneryWeb.PackLive.Show do
{:noreply, socket |> put_flash(:info, prompt) |> push_navigate(to: redirect_to)}
end
def handle_event(
"toggle_staged",
_params,
%{assigns: %{pack: pack, current_user: current_user}} = socket
) do
{:ok, pack} = pack |> Ammo.update_pack(%{"staged" => !pack.staged}, current_user)
{:noreply, socket |> display_pack(pack)}
end
def handle_event(
"delete_shot_record",
%{"id" => id},

View File

@ -1,43 +1,43 @@
<div class="mx-auto space-y-4 max-w-3xl flex flex-col justify-center items-center">
<h1 class="title text-2xl title-primary-500">
<div class="flex flex-col justify-center items-center mx-auto space-y-4 max-w-3xl">
<h1 class="text-2xl title title-primary-500">
<%= @pack.type.name %>
</h1>
<div class="space-y-2 flex flex-col justify-center items-center">
<span class="rounded-lg title text-lg">
<div class="flex flex-col justify-center items-center space-y-2">
<span class="text-lg rounded-lg title">
<%= gettext("Count:") %>
<%= @pack.count %>
</span>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Original count:") %>
<%= @original_count %>
</span>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Percentage left:") %>
<%= gettext("%{percentage}%", percentage: @percentage_remaining) %>
</span>
<%= if @pack.notes do %>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Notes:") %>
<%= @pack.notes %>
</span>
<% end %>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Purchased on:") %>
<.date id={"#{@pack.id}-purchased-on"} date={@pack.purchased_on} />
</span>
<%= if @pack.price_paid do %>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Original cost:") %>
<%= gettext("$%{amount}", amount: display_currency(@pack.price_paid)) %>
</span>
<span class="rounded-lg title text-lg">
<span class="text-lg rounded-lg title">
<%= gettext("Current value:") %>
<%= gettext("$%{amount}",
amount: display_currency(@pack.price_paid * @percentage_remaining / 100)
@ -76,12 +76,6 @@
</div>
<div class="flex flex-wrap justify-center items-center text-primary-600">
<button type="button" class="mx-4 my-2 btn btn-primary" phx-click="toggle_staged">
<%= if @pack.staged,
do: dgettext("actions", "Unstage from range"),
else: dgettext("actions", "Stage for range") %>
</button>
<.link patch={~p"/ammo/show/move/#{@pack}"} class="btn btn-primary">
<%= dgettext("actions", "Move ammo") %>
</.link>
@ -96,7 +90,7 @@
<div>
<%= if @container do %>
<h1 class="mb-4 px-4 py-2 text-center rounded-lg title text-xl">
<h1 class="px-4 py-2 mb-4 text-xl text-center rounded-lg title">
<%= gettext("Stored in") %>
</h1>
@ -109,7 +103,7 @@
<%= unless @shot_records |> Enum.empty?() do %>
<hr class="mb-4 w-full" />
<h1 class="mb-4 px-4 py-2 text-center rounded-lg title text-xl">
<h1 class="px-4 py-2 mb-4 text-xl text-center rounded-lg title">
<%= gettext("Rounds used") %>
</h1>