Skip to content

Commit

Permalink
Media UI v1 (#17)
Browse files Browse the repository at this point in the history
* Updated comments

* Added basic media tables to sources#show

* Adds a very basic listing and show page for media
  • Loading branch information
kieraneglin authored Feb 10, 2024
1 parent dabec62 commit 8bdd189
Show file tree
Hide file tree
Showing 8 changed files with 102 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/pinchflat/workers/media_indexing_worker.ex
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ defmodule Pinchflat.Workers.MediaIndexingWorker do

defp index_media_and_reschedule(source) do
SourceTasks.index_media_items(source)
# This method handles the case where a source is set to not download media
SourceTasks.enqueue_pending_media_downloads(source)

source
Expand Down
11 changes: 11 additions & 0 deletions lib/pinchflat_web/controllers/media/media_item_controller.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
defmodule PinchflatWeb.Media.MediaItemController do
use PinchflatWeb, :controller

alias Pinchflat.Media

def show(conn, %{"id" => id}) do
media_item = Media.get_media_item!(id)

render(conn, :show, media_item: media_item)
end
end
5 changes: 5 additions & 0 deletions lib/pinchflat_web/controllers/media/media_item_html.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
defmodule PinchflatWeb.Media.MediaItemHTML do
use PinchflatWeb, :html

embed_templates "media_item_html/*"
end
18 changes: 18 additions & 0 deletions lib/pinchflat_web/controllers/media/media_item_html/show.html.heex
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<div class="mb-6 flex gap-3 flex-row items-center justify-between">
<div class="flex gap-3 items-center">
<.link :if={@conn.params["source_id"]} navigate={~p"/sources/#{@media_item.source_id}"}>
<.icon name="hero-arrow-left" class="w-10 h-10 hover:dark:text-white" />
</.link>
<h2 class="text-title-md2 font-bold text-black dark:text-white ml-4">
Media Item #<%= @media_item.id %>
</h2>
</div>
</div>
<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">
<div class="max-w-full overflow-x-auto">
<div class="flex flex-col gap-10 dark:text-white">
<h3 class="font-bold text-xl">Attributes</h3>
<.list_items_from_map map={Map.from_struct(@media_item)} />
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ defmodule PinchflatWeb.MediaSources.SourceController do
use PinchflatWeb, :controller

alias Pinchflat.Repo
alias Pinchflat.Media
alias Pinchflat.Profiles
alias Pinchflat.MediaSource
alias Pinchflat.MediaSource.Source
Expand Down Expand Up @@ -36,7 +37,10 @@ defmodule PinchflatWeb.MediaSources.SourceController do
|> MediaSource.get_source!()
|> Repo.preload(:media_profile)

render(conn, :show, source: source)
pending_media = Media.list_pending_media_items_for(source)
downloaded_media = Media.list_downloaded_media_items_for(source)

render(conn, :show, source: source, pending_media: pending_media, downloaded_media: downloaded_media)
end

def edit(conn, %{"id" => id}) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,44 @@

<h3 class="font-bold text-xl">Attributes</h3>
<.list_items_from_map map={Map.from_struct(@source)} />

<h3 class="font-bold text-xl">Downloaded Media</h3>
<%= if length(@downloaded_media) > 0 do %>
<.table rows={@downloaded_media} table_class="text-black dark:text-white">
<:col :let={media_item} label="Title">
<%= String.slice(media_item.title, 0..50) %>...
</:col>
<:col :let={media_item} label="" class="flex place-content-evenly">
<.link
navigate={~p"/sources/#{@source.id}/media/#{media_item.id}"}
class="hover:text-secondary duration-200 ease-in-out mx-0.5"
>
<.icon name="hero-eye" />
</.link>
</:col>
</.table>
<% else %>
<p class="text-black dark:text-white">Nothing Here!</p>
<% end %>

<h3 class="font-bold text-xl">Pending Media</h3>
<%= if length(@pending_media) > 0 do %>
<.table rows={@pending_media} table_class="text-black dark:text-white">
<:col :let={media_item} label="Title">
<%= String.slice(media_item.title, 0..50) %>...
</:col>
<:col :let={media_item} label="" class="flex place-content-evenly">
<.link
navigate={~p"/sources/#{@source.id}/media/#{media_item.id}"}
class="hover:text-secondary duration-200 ease-in-out mx-0.5"
>
<.icon name="hero-eye" />
</.link>
</:col>
</.table>
<% else %>
<p class="text-black dark:text-white">Nothing Here!</p>
<% end %>
</div>
</div>
</div>
6 changes: 5 additions & 1 deletion lib/pinchflat_web/router.ex
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ defmodule PinchflatWeb.Router do
get "/", PageController, :home

resources "/media_profiles", MediaProfiles.MediaProfileController
resources "/sources", MediaSources.SourceController
resources "/media", Media.MediaItemController, only: [:show]

resources "/sources", MediaSources.SourceController do
resources "/media", Media.MediaItemController, only: [:show]
end
end

# Other scopes may use custom stacks.
Expand Down
19 changes: 19 additions & 0 deletions test/pinchflat_web/controllers/media_item_controller_test.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
defmodule PinchflatWeb.MediaItemControllerTest do
use PinchflatWeb.ConnCase

import Pinchflat.MediaFixtures

describe "show media" do
setup [:create_media_item]

test "renders the page", %{conn: conn, media_item: media_item} do
conn = get(conn, ~p"/media/#{media_item}")
assert html_response(conn, 200) =~ "Media Item ##{media_item.id}"
end
end

defp create_media_item(_) do
media_item = media_item_fixture()
%{media_item: media_item}
end
end

0 comments on commit 8bdd189

Please sign in to comment.