Skip to content

Commit 659d153

Browse files
committed
Adds a very basic listing and show page for media
1 parent 1a868f8 commit 659d153

File tree

6 files changed

+66
-3
lines changed

6 files changed

+66
-3
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
defmodule PinchflatWeb.Media.MediaItemController do
2+
use PinchflatWeb, :controller
3+
4+
alias Pinchflat.Media
5+
6+
def show(conn, %{"id" => id}) do
7+
media_item = Media.get_media_item!(id)
8+
9+
render(conn, :show, media_item: media_item)
10+
end
11+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
defmodule PinchflatWeb.Media.MediaItemHTML do
2+
use PinchflatWeb, :html
3+
4+
embed_templates "media_item_html/*"
5+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
2+
<div class="flex gap-3 items-center">
3+
<.link :if={@conn.params["source_id"]} navigate={~p"/sources/#{@media_item.source_id}"}>
4+
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
5+
</.link>
6+
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
7+
Media Item #<%= @media_item.id %>
8+
</h2>
9+
</div>
10+
</div>
11+
<div class="rounded-sm border border-stroke bg-white px-5 pb-2.5 pt-6 shadow-default dark:border-strokedark dark:bg-boxdark sm:px-7.5 xl:pb-1">
12+
<div class="max-w-full overflow-x-auto">
13+
<div class="flex flex-col gap-10 dark:text-white">
14+
<h3 class="font-bold text-xl">Attributes</h3>
15+
<.list_items_from_map map={Map.from_struct(@media_item)} />
16+
</div>
17+
</div>
18+
</div>

lib/pinchflat_web/controllers/media_sources/source_html/show.html.heex

+8-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@
4141
<%= String.slice(media_item.title, 0..50) %>...
4242
</:col>
4343
<:col :let={media_item} label="" class="flex place-content-evenly">
44-
<.link navigate={~p"/media/#{media_item.id}"} class="hover:text-secondary duration-200 ease-in-out mx-0.5">
44+
<.link
45+
navigate={~p"/sources/#{@source.id}/media/#{media_item.id}"}
46+
class="hover:text-secondary duration-200 ease-in-out mx-0.5"
47+
>
4548
<.icon name="hero-eye" />
4649
</.link>
4750
</:col>
@@ -57,7 +60,10 @@
5760
<%= String.slice(media_item.title, 0..50) %>...
5861
</:col>
5962
<:col :let={media_item} label="" class="flex place-content-evenly">
60-
<.link navigate={~p"/media/#{media_item.id}"} class="hover:text-secondary duration-200 ease-in-out mx-0.5">
63+
<.link
64+
navigate={~p"/sources/#{@source.id}/media/#{media_item.id}"}
65+
class="hover:text-secondary duration-200 ease-in-out mx-0.5"
66+
>
6167
<.icon name="hero-eye" />
6268
</.link>
6369
</:col>

lib/pinchflat_web/router.ex

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,11 @@ defmodule PinchflatWeb.Router do
2020
get "/", PageController, :home
2121

2222
resources "/media_profiles", MediaProfiles.MediaProfileController
23-
resources "/sources", MediaSources.SourceController
23+
resources "/media", Media.MediaItemController, only: [:show]
24+
25+
resources "/sources", MediaSources.SourceController do
26+
resources "/media", Media.MediaItemController, only: [:show]
27+
end
2428
end
2529

2630
# Other scopes may use custom stacks.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
defmodule PinchflatWeb.MediaItemControllerTest do
2+
use PinchflatWeb.ConnCase
3+
4+
import Pinchflat.MediaFixtures
5+
6+
describe "show media" do
7+
setup [:create_media_item]
8+
9+
test "renders the page", %{conn: conn, media_item: media_item} do
10+
conn = get(conn, ~p"/media/#{media_item}")
11+
assert html_response(conn, 200) =~ "Media Item ##{media_item.id}"
12+
end
13+
end
14+
15+
defp create_media_item(_) do
16+
media_item = media_item_fixture()
17+
%{media_item: media_item}
18+
end
19+
end

0 commit comments

Comments
 (0)