cannery/lib/cannery_web/components/container_card.ex

77 lines
2.4 KiB
Elixir
Raw Normal View History

2022-02-11 22:47:33 -05:00
defmodule CanneryWeb.Components.ContainerCard do
2022-02-05 01:59:40 -05:00
@moduledoc """
Display card for a container
"""
use CanneryWeb, :component
2022-02-18 22:56:46 -05:00
import CanneryWeb.Components.TagCard
2022-02-19 00:31:17 -05:00
alias Cannery.{Containers, Repo}
2022-02-05 01:59:40 -05:00
alias CanneryWeb.Endpoint
2022-02-18 22:56:46 -05:00
def container_card(%{container: container} = assigns) do
assigns = assigns |> Map.put(:container, container |> Repo.preload([:tags, :ammo_groups]))
2022-02-05 01:59:40 -05:00
~H"""
<div
id={"container-#{@container.id}"}
2022-03-28 23:56:45 -04:00
class="overflow-hidden max-w-full mx-4 my-2 px-8 py-4 flex flex-col justify-center items-center space-y-4
2022-02-15 23:20:18 -05:00
border border-gray-400 rounded-lg shadow-lg hover:shadow-md
transition-all duration-300 ease-in-out"
2022-02-05 01:59:40 -05:00
>
2022-03-28 23:56:45 -04:00
<div class="max-w-full mb-4 flex flex-col justify-center items-center space-y-2">
2022-02-05 01:59:40 -05:00
<%= live_redirect to: Routes.container_show_path(Endpoint, :show, @container),
class: "link" do %>
<h1 class="px-4 py-2 rounded-lg title text-xl">
<%= @container.name %>
</h1>
<% end %>
<%= if @container.desc do %>
<span class="rounded-lg title text-lg">
2022-02-09 00:49:47 -05:00
<%= gettext("Description:") %>
<%= @container.desc %>
2022-02-05 01:59:40 -05:00
</span>
<% end %>
<span class="rounded-lg title text-lg">
2022-02-09 00:49:47 -05:00
<%= gettext("Type:") %>
<%= @container.type %>
2022-02-05 01:59:40 -05:00
</span>
<%= if @container.location do %>
<span class="rounded-lg title text-lg">
2022-02-09 00:49:47 -05:00
<%= gettext("Location:") %>
<%= @container.location %>
2022-02-05 01:59:40 -05:00
</span>
<% end %>
2022-02-18 22:56:46 -05:00
<%= if @container.ammo_groups do %>
<span class="rounded-lg title text-lg">
<%= gettext("Rounds:") %>
<%= @container |> Containers.get_container_rounds!() %>
</span>
<% end %>
<div class="flex flex-wrap justify-center items-center">
<%= unless @container.tags |> Enum.empty?() do %>
<%= for tag <- @container.tags do %>
<.simple_tag_card tag={tag} />
<% end %>
<% end %>
<%= if assigns |> Map.has_key?(:tag_actions) do %>
<%= render_slot(@tag_actions) %>
<% end %>
</div>
2022-02-05 01:59:40 -05:00
</div>
<%= if assigns |> Map.has_key?(:inner_block) do %>
<div class="flex space-x-4 justify-center items-center">
<%= render_slot(@inner_block) %>
</div>
<% end %>
</div>
"""
end
end