[Enhancement] Add option to use existing Media Profile as template for new profile (#466)
* Add option to use existing Media Profile as template for new profile * Forgot to commit the edit form too * Reset deletion mark on Source controller * Add test for new preload profile feature * mix check
This commit is contained in:
parent
a02f71f304
commit
4c8c0461be
8 changed files with 37 additions and 6 deletions
|
|
@ -17,10 +17,24 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
|||
render(conn, :index, media_profiles: media_profiles)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Profiles.change_media_profile(%MediaProfile{})
|
||||
def new(conn, params) do
|
||||
# Preload an existing media profile for faster creation
|
||||
cs_struct =
|
||||
case to_string(params["template_id"]) do
|
||||
"" -> %MediaProfile{}
|
||||
template_id -> Repo.get(MediaProfile, template_id) || %MediaProfile{}
|
||||
end
|
||||
|
||||
render(conn, :new, changeset: changeset, layout: get_onboarding_layout())
|
||||
render(conn, :new,
|
||||
layout: get_onboarding_layout(),
|
||||
changeset:
|
||||
Profiles.change_media_profile(%MediaProfile{
|
||||
cs_struct
|
||||
| id: nil,
|
||||
name: nil,
|
||||
marked_for_deletion_at: nil
|
||||
})
|
||||
)
|
||||
end
|
||||
|
||||
def create(conn, %{"media_profile" => media_profile_params}) do
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
|||
"""
|
||||
attr :changeset, Ecto.Changeset, required: true
|
||||
attr :action, :string, required: true
|
||||
attr :method, :string, required: true
|
||||
|
||||
def media_profile_form(assigns)
|
||||
|
||||
|
|
|
|||
|
|
@ -11,6 +11,11 @@
|
|||
<span x-show="copied" x-transition.duration.150ms><.icon name="hero-check" class="ml-2 h-4 w-4" /></span>
|
||||
</span>
|
||||
</:option>
|
||||
<:option>
|
||||
<.link href={~p"/media_profiles/new?template_id=#{@media_profile}"} method="get">
|
||||
Use as Template
|
||||
</.link>
|
||||
</:option>
|
||||
<:option>
|
||||
<div class="h-px w-full bg-bodydark2"></div>
|
||||
</:option>
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
<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">
|
||||
<div class="flex flex-col gap-10">
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles/#{@media_profile}"} />
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles/#{@media_profile}"} method="patch" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
:let={f}
|
||||
for={@changeset}
|
||||
action={@action}
|
||||
method={@method}
|
||||
x-data="{ advancedMode: !!JSON.parse(localStorage.getItem('advancedMode')) }"
|
||||
x-init="$watch('advancedMode', value => localStorage.setItem('advancedMode', JSON.stringify(value)))"
|
||||
>
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@
|
|||
<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">
|
||||
<div class="flex flex-col gap-10">
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles"} />
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles"} method="post" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -67,7 +67,8 @@ defmodule PinchflatWeb.Sources.SourceController do
|
|||
collection_name: nil,
|
||||
collection_id: nil,
|
||||
collection_type: nil,
|
||||
original_url: nil
|
||||
original_url: nil,
|
||||
marked_for_deletion_at: nil
|
||||
})
|
||||
)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -79,6 +79,15 @@ defmodule PinchflatWeb.MediaProfileControllerTest do
|
|||
|
||||
refute html_response(conn, 200) =~ "MENU"
|
||||
end
|
||||
|
||||
test "preloads some attributes when using a template", %{conn: conn} do
|
||||
profile = media_profile_fixture(name: "My first profile", download_subs: true, sub_langs: "de")
|
||||
|
||||
conn = get(conn, ~p"/media_profiles/new", %{"template_id" => profile.id})
|
||||
assert html_response(conn, 200) =~ "New Media Profile"
|
||||
assert html_response(conn, 200) =~ profile.sub_langs
|
||||
refute html_response(conn, 200) =~ profile.name
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit media_profile" do
|
||||
|
|
|
|||
Loading…
Reference in a new issue