From cc7162d26711f6a3b8e639fd1d861bb8a093e262 Mon Sep 17 00:00:00 2001 From: shibao Date: Mon, 31 Jan 2022 21:56:02 -0500 Subject: [PATCH] add containers show page --- lib/cannery_web/live/container_live/show.ex | 18 ++++++-- .../live/container_live/show.html.heex | 46 +++++++++++++++++++ .../live/container_live/show.html.leex | 37 --------------- 3 files changed, 60 insertions(+), 41 deletions(-) create mode 100644 lib/cannery_web/live/container_live/show.html.heex delete mode 100644 lib/cannery_web/live/container_live/show.html.leex diff --git a/lib/cannery_web/live/container_live/show.ex b/lib/cannery_web/live/container_live/show.ex index b7c6aed..a390d20 100644 --- a/lib/cannery_web/live/container_live/show.ex +++ b/lib/cannery_web/live/container_live/show.ex @@ -14,10 +14,20 @@ defmodule CanneryWeb.ContainerLive.Show do @impl true def handle_params(%{"id" => id}, _, socket) do - {:noreply, - socket - |> assign(:page_title, page_title(socket.assigns.live_action)) - |> assign(:container, Containers.get_container!(id))} + socket = + socket + |> assign( + 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 defp page_title(:show), do: "Show Container" diff --git a/lib/cannery_web/live/container_live/show.html.heex b/lib/cannery_web/live/container_live/show.html.heex new file mode 100644 index 0000000..bf9f3a1 --- /dev/null +++ b/lib/cannery_web/live/container_live/show.html.heex @@ -0,0 +1,46 @@ +
+

+ <%= @container.name %> +

+ + <%= if @container.desc do %> + + Description: <%= @container.desc %> + + <% end %> + + + Type: <%= @container.type %> + + + <%= if @container.location do %> + + Location: <%= @container.location %> + + <% end %> + +
+ <%= 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}?"] + ) %> +
+ +
+ +

No ammo groups in this container

+ + <%= 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 %> +
diff --git a/lib/cannery_web/live/container_live/show.html.leex b/lib/cannery_web/live/container_live/show.html.leex deleted file mode 100644 index 2d39aa9..0000000 --- a/lib/cannery_web/live/container_live/show.html.leex +++ /dev/null @@ -1,37 +0,0 @@ -

Show Container

- -<%= 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 %> - - - -<%= live_patch "Edit", to: Routes.container_show_path(@socket, :edit, @container), class: "button" %> -<%= live_redirect "Back", to: Routes.container_index_path(@socket, :index) %>