add containers show page

This commit is contained in:
shibao 2022-01-31 21:56:02 -05:00
parent b14c5ce88a
commit cc7162d267
3 changed files with 60 additions and 41 deletions

View File

@ -14,10 +14,20 @@ defmodule CanneryWeb.ContainerLive.Show do
@impl true @impl true
def handle_params(%{"id" => id}, _, socket) do def handle_params(%{"id" => id}, _, socket) do
{:noreply, socket =
socket socket
|> assign(:page_title, page_title(socket.assigns.live_action)) |> assign(
|> assign(:container, Containers.get_container!(id))} page_title: page_title(socket.assigns.live_action),
container: Containers.get_container!(id)
)
{:noreply, socket}
end
@impl true
def handle_event("delete", _, socket) do
socket.assigns.container |> Containers.delete_container!()
{:noreply, socket |> push_redirect(to: Routes.container_index_path(socket, :index))}
end end
defp page_title(:show), do: "Show Container" defp page_title(:show), do: "Show Container"

View File

@ -0,0 +1,46 @@
<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">
<%= @container.name %>
</h1>
<%= if @container.desc do %>
<span class="rounded-lg title text-lg">
Description: <%= @container.desc %>
</span>
<% end %>
<span class="rounded-lg title text-lg">
Type: <%= @container.type %>
</span>
<%= if @container.location do %>
<span class="rounded-lg title text-lg">
Location: <%= @container.location %>
</span>
<% end %>
<div class="flex space-x-4 justify-center items-center text-primary-500">
<%= live_redirect("Back", to: Routes.container_index_path(@socket, :index), class: "link") %>
<%= live_patch("Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "link") %>
<%= link("Delete",
to: "#",
class: "link",
phx_click: "delete",
data: [confirm: "Are you sure you want to delete #{@container.name}?"]
) %>
</div>
<hr class="mb-4 w-full">
<p>No ammo groups in this container</p>
<%= if @live_action in [:edit] do %>
<%= live_modal(CanneryWeb.ContainerLive.FormComponent,
id: @container.id,
title: @page_title,
action: @live_action,
container: @container,
return_to: Routes.container_show_path(@socket, :show, @container)
) %>
<% end %>
</div>

View File

@ -1,37 +0,0 @@
<h1>Show Container</h1>
<%= if @live_action in [:edit] do %>
<%= live_modal CanneryWeb.ContainerLive.FormComponent,
id: @container.id,
title: @page_title,
action: @live_action,
container: @container,
return_to: Routes.container_show_path(@socket, :show, @container) %>
<% end %>
<ul>
<li>
<strong>Name:</strong>
<%= @container.name %>
</li>
<li>
<strong>Desc:</strong>
<%= @container.desc %>
</li>
<li>
<strong>Type:</strong>
<%= @container.type %>
</li>
<li>
<strong>Location:</strong>
<%= @container.location %>
</li>
</ul>
<span><%= live_patch "Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "button" %></span>
<span><%= live_redirect "Back", to: Routes.container_index_path(@socket, :index) %></span>