Ran html generator for mediaprofile model - leaving as-is for now
This commit is contained in:
parent
b3def0d88c
commit
b29dec7294
14 changed files with 467 additions and 0 deletions
104
lib/pinchflat/profiles.ex
Normal file
104
lib/pinchflat/profiles.ex
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
defmodule Pinchflat.Profiles do
|
||||
@moduledoc """
|
||||
The Profiles context.
|
||||
"""
|
||||
|
||||
import Ecto.Query, warn: false
|
||||
alias Pinchflat.Repo
|
||||
|
||||
alias Pinchflat.Profiles.MediaProfile
|
||||
|
||||
@doc """
|
||||
Returns the list of media_profiles.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> list_media_profiles()
|
||||
[%MediaProfile{}, ...]
|
||||
|
||||
"""
|
||||
def list_media_profiles do
|
||||
Repo.all(MediaProfile)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Gets a single media_profile.
|
||||
|
||||
Raises `Ecto.NoResultsError` if the Media profile does not exist.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> get_media_profile!(123)
|
||||
%MediaProfile{}
|
||||
|
||||
iex> get_media_profile!(456)
|
||||
** (Ecto.NoResultsError)
|
||||
|
||||
"""
|
||||
def get_media_profile!(id), do: Repo.get!(MediaProfile, id)
|
||||
|
||||
@doc """
|
||||
Creates a media_profile.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> create_media_profile(%{field: value})
|
||||
{:ok, %MediaProfile{}}
|
||||
|
||||
iex> create_media_profile(%{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def create_media_profile(attrs \\ %{}) do
|
||||
%MediaProfile{}
|
||||
|> MediaProfile.changeset(attrs)
|
||||
|> Repo.insert()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Updates a media_profile.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> update_media_profile(media_profile, %{field: new_value})
|
||||
{:ok, %MediaProfile{}}
|
||||
|
||||
iex> update_media_profile(media_profile, %{field: bad_value})
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def update_media_profile(%MediaProfile{} = media_profile, attrs) do
|
||||
media_profile
|
||||
|> MediaProfile.changeset(attrs)
|
||||
|> Repo.update()
|
||||
end
|
||||
|
||||
@doc """
|
||||
Deletes a media_profile.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> delete_media_profile(media_profile)
|
||||
{:ok, %MediaProfile{}}
|
||||
|
||||
iex> delete_media_profile(media_profile)
|
||||
{:error, %Ecto.Changeset{}}
|
||||
|
||||
"""
|
||||
def delete_media_profile(%MediaProfile{} = media_profile) do
|
||||
Repo.delete(media_profile)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns an `%Ecto.Changeset{}` for tracking media_profile changes.
|
||||
|
||||
## Examples
|
||||
|
||||
iex> change_media_profile(media_profile)
|
||||
%Ecto.Changeset{data: %MediaProfile{}}
|
||||
|
||||
"""
|
||||
def change_media_profile(%MediaProfile{} = media_profile, attrs \\ %{}) do
|
||||
MediaProfile.changeset(media_profile, attrs)
|
||||
end
|
||||
end
|
||||
19
lib/pinchflat/profiles/media_profile.ex
Normal file
19
lib/pinchflat/profiles/media_profile.ex
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
defmodule Pinchflat.Profiles.MediaProfile do
|
||||
use Ecto.Schema
|
||||
import Ecto.Changeset
|
||||
|
||||
schema "media_profiles" do
|
||||
field :name, :string
|
||||
field :output_path_template, :string
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
@doc false
|
||||
def changeset(media_profile, attrs) do
|
||||
media_profile
|
||||
|> cast(attrs, [:name, :output_path_template])
|
||||
|> validate_required([:name, :output_path_template])
|
||||
|> unique_constraint(:name)
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,62 @@
|
|||
defmodule PinchflatWeb.MediaProfiles.MediaProfileController do
|
||||
use PinchflatWeb, :controller
|
||||
|
||||
alias Pinchflat.Profiles
|
||||
alias Pinchflat.Profiles.MediaProfile
|
||||
|
||||
def index(conn, _params) do
|
||||
media_profiles = Profiles.list_media_profiles()
|
||||
render(conn, :index, media_profiles: media_profiles)
|
||||
end
|
||||
|
||||
def new(conn, _params) do
|
||||
changeset = Profiles.change_media_profile(%MediaProfile{})
|
||||
render(conn, :new, changeset: changeset)
|
||||
end
|
||||
|
||||
def create(conn, %{"media_profile" => media_profile_params}) do
|
||||
case Profiles.create_media_profile(media_profile_params) do
|
||||
{:ok, media_profile} ->
|
||||
conn
|
||||
|> put_flash(:info, "Media profile created successfully.")
|
||||
|> redirect(to: ~p"/media_profiles/#{media_profile}")
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, :new, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def show(conn, %{"id" => id}) do
|
||||
media_profile = Profiles.get_media_profile!(id)
|
||||
render(conn, :show, media_profile: media_profile)
|
||||
end
|
||||
|
||||
def edit(conn, %{"id" => id}) do
|
||||
media_profile = Profiles.get_media_profile!(id)
|
||||
changeset = Profiles.change_media_profile(media_profile)
|
||||
render(conn, :edit, media_profile: media_profile, changeset: changeset)
|
||||
end
|
||||
|
||||
def update(conn, %{"id" => id, "media_profile" => media_profile_params}) do
|
||||
media_profile = Profiles.get_media_profile!(id)
|
||||
|
||||
case Profiles.update_media_profile(media_profile, media_profile_params) do
|
||||
{:ok, media_profile} ->
|
||||
conn
|
||||
|> put_flash(:info, "Media profile updated successfully.")
|
||||
|> redirect(to: ~p"/media_profiles/#{media_profile}")
|
||||
|
||||
{:error, %Ecto.Changeset{} = changeset} ->
|
||||
render(conn, :edit, media_profile: media_profile, changeset: changeset)
|
||||
end
|
||||
end
|
||||
|
||||
def delete(conn, %{"id" => id}) do
|
||||
media_profile = Profiles.get_media_profile!(id)
|
||||
{:ok, _media_profile} = Profiles.delete_media_profile(media_profile)
|
||||
|
||||
conn
|
||||
|> put_flash(:info, "Media profile deleted successfully.")
|
||||
|> redirect(to: ~p"/media_profiles")
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,13 @@
|
|||
defmodule PinchflatWeb.MediaProfiles.MediaProfileHTML do
|
||||
use PinchflatWeb, :html
|
||||
|
||||
embed_templates "media_profile_html/*"
|
||||
|
||||
@doc """
|
||||
Renders a media_profile form.
|
||||
"""
|
||||
attr :changeset, Ecto.Changeset, required: true
|
||||
attr :action, :string, required: true
|
||||
|
||||
def media_profile_form(assigns)
|
||||
end
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<.header>
|
||||
Edit Media profile <%= @media_profile.id %>
|
||||
<:subtitle>Use this form to manage media_profile records in your database.</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles/#{@media_profile}"} />
|
||||
|
||||
<.back navigate={~p"/media_profiles"}>Back to media_profiles</.back>
|
||||
|
|
@ -0,0 +1,30 @@
|
|||
<.header>
|
||||
Listing Media profiles
|
||||
<:actions>
|
||||
<.link href={~p"/media_profiles/new"}>
|
||||
<.button>New Media profile</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.table
|
||||
id="media_profiles"
|
||||
rows={@media_profiles}
|
||||
row_click={&JS.navigate(~p"/media_profiles/#{&1}")}
|
||||
>
|
||||
<:col :let={media_profile} label="Name"><%= media_profile.name %></:col>
|
||||
<:col :let={media_profile} label="Output path template">
|
||||
<%= media_profile.output_path_template %>
|
||||
</:col>
|
||||
<:action :let={media_profile}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/media_profiles/#{media_profile}"}>Show</.link>
|
||||
</div>
|
||||
<.link navigate={~p"/media_profiles/#{media_profile}/edit"}>Edit</.link>
|
||||
</:action>
|
||||
<:action :let={media_profile}>
|
||||
<.link href={~p"/media_profiles/#{media_profile}"} method="delete" data-confirm="Are you sure?">
|
||||
Delete
|
||||
</.link>
|
||||
</:action>
|
||||
</.table>
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
<.simple_form :let={f} for={@changeset} action={@action}>
|
||||
<.error :if={@changeset.action}>
|
||||
Oops, something went wrong! Please check the errors below.
|
||||
</.error>
|
||||
<.input field={f[:name]} type="text" label="Name" />
|
||||
<.input field={f[:output_path_template]} type="text" label="Output path template" />
|
||||
<:actions>
|
||||
<.button>Save Media profile</.button>
|
||||
</:actions>
|
||||
</.simple_form>
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
<.header>
|
||||
New Media profile
|
||||
<:subtitle>Use this form to manage media_profile records in your database.</:subtitle>
|
||||
</.header>
|
||||
|
||||
<.media_profile_form changeset={@changeset} action={~p"/media_profiles"} />
|
||||
|
||||
<.back navigate={~p"/media_profiles"}>Back to media_profiles</.back>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
<.header>
|
||||
Media profile <%= @media_profile.id %>
|
||||
<:subtitle>This is a media_profile record from your database.</:subtitle>
|
||||
<:actions>
|
||||
<.link href={~p"/media_profiles/#{@media_profile}/edit"}>
|
||||
<.button>Edit media_profile</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.list>
|
||||
<:item title="Name"><%= @media_profile.name %></:item>
|
||||
<:item title="Output path template"><%= @media_profile.output_path_template %></:item>
|
||||
</.list>
|
||||
|
||||
<.back navigate={~p"/media_profiles"}>Back to media_profiles</.back>
|
||||
|
|
@ -18,6 +18,8 @@ defmodule PinchflatWeb.Router do
|
|||
pipe_through :browser
|
||||
|
||||
get "/", PageController, :home
|
||||
|
||||
resources "/media_profiles", MediaProfiles.MediaProfileController
|
||||
end
|
||||
|
||||
# Other scopes may use custom stacks.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
defmodule Pinchflat.Repo.Migrations.CreateMediaProfiles do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
create table(:media_profiles) do
|
||||
add :name, :string, null: false
|
||||
add :output_path_template, :string, null: false
|
||||
|
||||
timestamps(type: :utc_datetime)
|
||||
end
|
||||
|
||||
create unique_index(:media_profiles, [:name])
|
||||
end
|
||||
end
|
||||
70
test/pinchflat/profiles_test.exs
Normal file
70
test/pinchflat/profiles_test.exs
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
defmodule Pinchflat.ProfilesTest do
|
||||
use Pinchflat.DataCase
|
||||
|
||||
alias Pinchflat.Profiles
|
||||
|
||||
describe "media_profiles" do
|
||||
alias Pinchflat.Profiles.MediaProfile
|
||||
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
@invalid_attrs %{name: nil, output_path_template: nil}
|
||||
|
||||
test "list_media_profiles/0 returns all media_profiles" do
|
||||
media_profile = media_profile_fixture()
|
||||
assert Profiles.list_media_profiles() == [media_profile]
|
||||
end
|
||||
|
||||
test "get_media_profile!/1 returns the media_profile with given id" do
|
||||
media_profile = media_profile_fixture()
|
||||
assert Profiles.get_media_profile!(media_profile.id) == media_profile
|
||||
end
|
||||
|
||||
test "create_media_profile/1 with valid data creates a media_profile" do
|
||||
valid_attrs = %{name: "some name", output_path_template: "some output_path_template"}
|
||||
|
||||
assert {:ok, %MediaProfile{} = media_profile} = Profiles.create_media_profile(valid_attrs)
|
||||
assert media_profile.name == "some name"
|
||||
assert media_profile.output_path_template == "some output_path_template"
|
||||
end
|
||||
|
||||
test "create_media_profile/1 with invalid data returns error changeset" do
|
||||
assert {:error, %Ecto.Changeset{}} = Profiles.create_media_profile(@invalid_attrs)
|
||||
end
|
||||
|
||||
test "update_media_profile/2 with valid data updates the media_profile" do
|
||||
media_profile = media_profile_fixture()
|
||||
|
||||
update_attrs = %{
|
||||
name: "some updated name",
|
||||
output_path_template: "some updated output_path_template"
|
||||
}
|
||||
|
||||
assert {:ok, %MediaProfile{} = media_profile} =
|
||||
Profiles.update_media_profile(media_profile, update_attrs)
|
||||
|
||||
assert media_profile.name == "some updated name"
|
||||
assert media_profile.output_path_template == "some updated output_path_template"
|
||||
end
|
||||
|
||||
test "update_media_profile/2 with invalid data returns error changeset" do
|
||||
media_profile = media_profile_fixture()
|
||||
|
||||
assert {:error, %Ecto.Changeset{}} =
|
||||
Profiles.update_media_profile(media_profile, @invalid_attrs)
|
||||
|
||||
assert media_profile == Profiles.get_media_profile!(media_profile.id)
|
||||
end
|
||||
|
||||
test "delete_media_profile/1 deletes the media_profile" do
|
||||
media_profile = media_profile_fixture()
|
||||
assert {:ok, %MediaProfile{}} = Profiles.delete_media_profile(media_profile)
|
||||
assert_raise Ecto.NoResultsError, fn -> Profiles.get_media_profile!(media_profile.id) end
|
||||
end
|
||||
|
||||
test "change_media_profile/1 returns a media_profile changeset" do
|
||||
media_profile = media_profile_fixture()
|
||||
assert %Ecto.Changeset{} = Profiles.change_media_profile(media_profile)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
defmodule PinchflatWeb.MediaProfileControllerTest do
|
||||
use PinchflatWeb.ConnCase
|
||||
|
||||
import Pinchflat.ProfilesFixtures
|
||||
|
||||
@create_attrs %{name: "some name", output_path_template: "some output_path_template"}
|
||||
@update_attrs %{
|
||||
name: "some updated name",
|
||||
output_path_template: "some updated output_path_template"
|
||||
}
|
||||
@invalid_attrs %{name: nil, output_path_template: nil}
|
||||
|
||||
describe "index" do
|
||||
test "lists all media_profiles", %{conn: conn} do
|
||||
conn = get(conn, ~p"/media_profiles")
|
||||
assert html_response(conn, 200) =~ "Listing Media profiles"
|
||||
end
|
||||
end
|
||||
|
||||
describe "new media_profile" do
|
||||
test "renders form", %{conn: conn} do
|
||||
conn = get(conn, ~p"/media_profiles/new")
|
||||
assert html_response(conn, 200) =~ "New Media profile"
|
||||
end
|
||||
end
|
||||
|
||||
describe "create media_profile" do
|
||||
test "redirects to show when data is valid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @create_attrs)
|
||||
|
||||
assert %{id: id} = redirected_params(conn)
|
||||
assert redirected_to(conn) == ~p"/media_profiles/#{id}"
|
||||
|
||||
conn = get(conn, ~p"/media_profiles/#{id}")
|
||||
assert html_response(conn, 200) =~ "Media profile #{id}"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn} do
|
||||
conn = post(conn, ~p"/media_profiles", media_profile: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "New Media profile"
|
||||
end
|
||||
end
|
||||
|
||||
describe "edit media_profile" do
|
||||
setup [:create_media_profile]
|
||||
|
||||
test "renders form for editing chosen media_profile", %{
|
||||
conn: conn,
|
||||
media_profile: media_profile
|
||||
} do
|
||||
conn = get(conn, ~p"/media_profiles/#{media_profile}/edit")
|
||||
assert html_response(conn, 200) =~ "Edit Media profile"
|
||||
end
|
||||
end
|
||||
|
||||
describe "update media_profile" do
|
||||
setup [:create_media_profile]
|
||||
|
||||
test "redirects when data is valid", %{conn: conn, media_profile: media_profile} do
|
||||
conn = put(conn, ~p"/media_profiles/#{media_profile}", media_profile: @update_attrs)
|
||||
assert redirected_to(conn) == ~p"/media_profiles/#{media_profile}"
|
||||
|
||||
conn = get(conn, ~p"/media_profiles/#{media_profile}")
|
||||
assert html_response(conn, 200) =~ "some updated name"
|
||||
end
|
||||
|
||||
test "renders errors when data is invalid", %{conn: conn, media_profile: media_profile} do
|
||||
conn = put(conn, ~p"/media_profiles/#{media_profile}", media_profile: @invalid_attrs)
|
||||
assert html_response(conn, 200) =~ "Edit Media profile"
|
||||
end
|
||||
end
|
||||
|
||||
describe "delete media_profile" do
|
||||
setup [:create_media_profile]
|
||||
|
||||
test "deletes chosen media_profile", %{conn: conn, media_profile: media_profile} do
|
||||
conn = delete(conn, ~p"/media_profiles/#{media_profile}")
|
||||
assert redirected_to(conn) == ~p"/media_profiles"
|
||||
|
||||
assert_error_sent 404, fn ->
|
||||
get(conn, ~p"/media_profiles/#{media_profile}")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
defp create_media_profile(_) do
|
||||
media_profile = media_profile_fixture()
|
||||
%{media_profile: media_profile}
|
||||
end
|
||||
end
|
||||
21
test/support/fixtures/profiles_fixtures.ex
Normal file
21
test/support/fixtures/profiles_fixtures.ex
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
defmodule Pinchflat.ProfilesFixtures do
|
||||
@moduledoc """
|
||||
This module defines test helpers for creating
|
||||
entities via the `Pinchflat.Profiles` context.
|
||||
"""
|
||||
|
||||
@doc """
|
||||
Generate a media_profile.
|
||||
"""
|
||||
def media_profile_fixture(attrs \\ %{}) do
|
||||
{:ok, media_profile} =
|
||||
attrs
|
||||
|> Enum.into(%{
|
||||
name: "some name",
|
||||
output_path_template: "some output_path_template"
|
||||
})
|
||||
|> Pinchflat.Profiles.create_media_profile()
|
||||
|
||||
media_profile
|
||||
end
|
||||
end
|
||||
Loading…
Reference in a new issue