forked from shibao/cannery
move components to Components context
This commit is contained in:
48
lib/cannery_web/components/ammo_group_card.ex
Normal file
48
lib/cannery_web/components/ammo_group_card.ex
Normal file
@ -0,0 +1,48 @@
|
||||
defmodule CanneryWeb.Components.AmmoGroupCard do
|
||||
@moduledoc """
|
||||
Display card for an ammo group
|
||||
"""
|
||||
|
||||
use CanneryWeb, :component
|
||||
alias Cannery.Repo
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
def ammo_group_card(assigns) do
|
||||
assigns = assigns |> assign(:ammo_group, assigns.ammo_group |> Repo.preload(:ammo_type))
|
||||
|
||||
~H"""
|
||||
<div
|
||||
id={"ammo_group-#{@ammo_group.id}"}
|
||||
class="px-8 py-4 flex flex-col justify-center items-center
|
||||
border border-gray-400 rounded-lg shadow-lg hover:shadow-md"
|
||||
>
|
||||
<%= live_redirect to: Routes.ammo_group_show_path(Endpoint, :show, @ammo_group),
|
||||
class: "mb-2 link" do %>
|
||||
<h1 class="title text-xl title-primary-500">
|
||||
<%= @ammo_group.ammo_type.name %>
|
||||
</h1>
|
||||
<% end %>
|
||||
|
||||
<div class="flex flex-col justify-center items-center">
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Count:") %>
|
||||
<%= @ammo_group.count %>
|
||||
</span>
|
||||
|
||||
<%= if @ammo_group.notes do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Notes:") %>
|
||||
<%= @ammo_group.notes %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<%= if @ammo_group.price_paid do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Price paid:") %> $ <%= @ammo_group.price_paid |> :erlang.float_to_binary(decimals: 2) %>
|
||||
</span>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
52
lib/cannery_web/components/container_card.ex
Normal file
52
lib/cannery_web/components/container_card.ex
Normal file
@ -0,0 +1,52 @@
|
||||
defmodule CanneryWeb.Components.ContainerCard do
|
||||
@moduledoc """
|
||||
Display card for a container
|
||||
"""
|
||||
|
||||
use CanneryWeb, :component
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
def container_card(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
id={"container-#{@container.id}"}
|
||||
class="px-8 py-4 flex flex-col justify-center items-center
|
||||
border border-gray-400 rounded-lg shadow-lg hover:shadow-md"
|
||||
>
|
||||
<div class="mb-4 flex flex-col justify-center items-center">
|
||||
<%= 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">
|
||||
<%= gettext("Description:") %>
|
||||
<%= @container.desc %>
|
||||
</span>
|
||||
<% end %>
|
||||
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Type:") %>
|
||||
<%= @container.type %>
|
||||
</span>
|
||||
|
||||
<%= if @container.location do %>
|
||||
<span class="rounded-lg title text-lg">
|
||||
<%= gettext("Location:") %>
|
||||
<%= @container.location %>
|
||||
</span>
|
||||
<% end %>
|
||||
</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
|
43
lib/cannery_web/components/modal.ex
Normal file
43
lib/cannery_web/components/modal.ex
Normal file
@ -0,0 +1,43 @@
|
||||
defmodule CanneryWeb.Components.Modal do
|
||||
@moduledoc """
|
||||
Livecomponent that displays a floating modal window
|
||||
"""
|
||||
|
||||
use CanneryWeb, :live_component
|
||||
|
||||
@impl true
|
||||
def render(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
id={@id}
|
||||
class="fixed z-10 left-0 top-0
|
||||
w-full h-full overflow-hidden
|
||||
p-8 flex flex-col justify-center items-center"
|
||||
style="opacity: 1 !important; background-color: rgba(0,0,0,0.4);"
|
||||
phx-capture-click="close"
|
||||
phx-window-keydown="close"
|
||||
phx-key="escape"
|
||||
phx-target={"#{@id}"}
|
||||
phx-page-loading
|
||||
>
|
||||
<div class="w-full max-w-3xl max-h-128 relative overflow-y-auto
|
||||
flex flex-col justify-start items-center
|
||||
bg-white border-2 rounded-lg">
|
||||
<%= live_patch to: @return_to,
|
||||
class:
|
||||
"absolute top-8 right-10 text-gray-500 hover:text-gray-800 transition-all duration-500 ease-in-out" do %>
|
||||
<i class="fa-fw fa-lg fas fa-times"></i>
|
||||
<% end %>
|
||||
<div class="p-8 flex flex-col space-y-4 justify-start items-center">
|
||||
<%= live_component(@component, @opts) %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
|
||||
@impl true
|
||||
def handle_event("close", _, socket) do
|
||||
{:noreply, push_patch(socket, to: socket.assigns.return_to)}
|
||||
end
|
||||
end
|
40
lib/cannery_web/components/tag_card.ex
Normal file
40
lib/cannery_web/components/tag_card.ex
Normal file
@ -0,0 +1,40 @@
|
||||
defmodule CanneryWeb.Components.TagCard do
|
||||
@moduledoc """
|
||||
Display card for a tag
|
||||
"""
|
||||
|
||||
use CanneryWeb, :component
|
||||
alias CanneryWeb.Endpoint
|
||||
|
||||
def tag_card(assigns) do
|
||||
~H"""
|
||||
<div
|
||||
id={"tag-#{@tag.id}"}
|
||||
class="mx-4 my-2 px-8 py-4 space-x-4 flex justify-center items-center
|
||||
border border-gray-400 rounded-lg shadow-lg hover:shadow-md"
|
||||
>
|
||||
<h1
|
||||
class="px-4 py-2 rounded-lg title text-xl"
|
||||
style={"color: #{@tag.text_color}; background-color: #{@tag.bg_color}"}
|
||||
>
|
||||
<%= @tag.name %>
|
||||
</h1>
|
||||
|
||||
<%= live_patch to: Routes.tag_index_path(Endpoint, :edit, @tag),
|
||||
class: "text-primary-500 link" do %>
|
||||
<i class="fa-fw fa-lg fas fa-edit"></i>
|
||||
<% end %>
|
||||
|
||||
<%= link to: "#",
|
||||
class: "text-primary-500 link",
|
||||
phx_click: "delete",
|
||||
phx_value_id: @tag.id,
|
||||
data: [
|
||||
confirm: dgettext("prompts", "Are you sure you want to delete %{name}?", name: @tag.name)
|
||||
] do %>
|
||||
<i class="fa-fw fa-lg fas fa-trash"></i>
|
||||
<% end %>
|
||||
</div>
|
||||
"""
|
||||
end
|
||||
end
|
108
lib/cannery_web/components/topbar.ex
Normal file
108
lib/cannery_web/components/topbar.ex
Normal file
@ -0,0 +1,108 @@
|
||||
defmodule CanneryWeb.Components.Topbar do
|
||||
@moduledoc """
|
||||
Component that renders a topbar with user functions/links
|
||||
"""
|
||||
|
||||
use CanneryWeb, :component
|
||||
|
||||
alias Cannery.Accounts
|
||||
alias CanneryWeb.HomeLive
|
||||
|
||||
def topbar(assigns) do
|
||||
assigns =
|
||||
%{results: [], title_content: nil, flash: nil, current_user: nil} |> Map.merge(assigns)
|
||||
|
||||
~H"""
|
||||
<header class="mb-8 px-8 py-4 w-full bg-primary-400 overflow-x-hidden">
|
||||
<nav role="navigation">
|
||||
<div class="flex flex-row justify-between items-center space-x-4">
|
||||
<div class="flex flex-row justify-start items-center space-x-2">
|
||||
<%= link to: Routes.live_path(CanneryWeb.Endpoint, HomeLive) do %>
|
||||
<h1 class="leading-5 text-xl text-white hover:underline">
|
||||
Cannery
|
||||
</h1>
|
||||
<% end %>
|
||||
<%= if @title_content do %>
|
||||
<span>|</span>
|
||||
<%= @title_content %>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<ul class="flex flex-col sm:flex-row flex-wrap justify-center items-center
|
||||
space-x-4 text-lg text-white text-ellipsis">
|
||||
<%= if @current_user do %>
|
||||
<li>
|
||||
<%= link(gettext("Tags"),
|
||||
class: "hover:underline",
|
||||
to: Routes.tag_index_path(CanneryWeb.Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link(gettext("Containers"),
|
||||
class: "hover:underline",
|
||||
to: Routes.container_index_path(CanneryWeb.Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link(gettext("Ammo"),
|
||||
class: "hover:underline",
|
||||
to: Routes.ammo_type_index_path(CanneryWeb.Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link(gettext("Manage"),
|
||||
class: "hover:underline",
|
||||
to: Routes.ammo_group_index_path(CanneryWeb.Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<%= if @current_user.role == :admin do %>
|
||||
<li>
|
||||
<%= link(gettext("Invites"),
|
||||
class: "hover:underline",
|
||||
to: Routes.invite_index_path(CanneryWeb.Endpoint, :index)
|
||||
) %>
|
||||
</li>
|
||||
<% end %>
|
||||
<li>
|
||||
<%= link(@current_user.email,
|
||||
class: "hover:underline truncate",
|
||||
to: Routes.user_settings_path(CanneryWeb.Endpoint, :edit)
|
||||
) %>
|
||||
</li>
|
||||
<li>
|
||||
<%= link to: Routes.user_session_path(CanneryWeb.Endpoint, :delete),
|
||||
method: :delete,
|
||||
data: [confirm: dgettext("prompts", "Are you sure you want to log out?")] do %>
|
||||
<i class="fas fa-sign-out-alt"></i>
|
||||
<% end %>
|
||||
</li>
|
||||
<%= if @current_user.role == :admin and function_exported?(Routes, :live_dashboard_path, 2) do %>
|
||||
<li>
|
||||
<%= link to: Routes.live_dashboard_path(CanneryWeb.Endpoint, :home) do %>
|
||||
<i class="fas fa-tachometer-alt"></i>
|
||||
<% end %>
|
||||
</li>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<%= if Accounts.allow_registration?() do %>
|
||||
<li>
|
||||
<%= link(dgettext("actions", "Register"),
|
||||
class: "hover:underline",
|
||||
to: Routes.user_registration_path(CanneryWeb.Endpoint, :new)
|
||||
) %>
|
||||
</li>
|
||||
<% end %>
|
||||
<li>
|
||||
<%= link(dgettext("actions", "Log in"),
|
||||
class: "hover:underline",
|
||||
to: Routes.user_session_path(CanneryWeb.Endpoint, :new)
|
||||
) %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
</nav>
|
||||
</header>
|
||||
"""
|
||||
end
|
||||
end
|
Reference in New Issue
Block a user