Merge pull request 'apply default layout on note creation' (#136) from devel into main
Reviewed-on: #136
This commit is contained in:
commit
f76da91071
7 changed files with 23 additions and 13 deletions
|
@ -68,10 +68,12 @@ defmodule Chiya.Notes.Note do
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(note, attrs) do
|
def changeset(note, attrs) do
|
||||||
|
# if you need to have a preloaded note here,
|
||||||
|
# do it yourself before you come here. now GET OUT.
|
||||||
|
|
||||||
note
|
note
|
||||||
|> Chiya.Notes.preload_note()
|
|
||||||
|> cast(attrs, [:name, :content, :slug, :published_at, :kind, :url])
|
|> cast(attrs, [:name, :content, :slug, :published_at, :kind, :url])
|
||||||
|> put_assoc(:channels, attrs["channels"] || [])
|
|> put_assoc(:channels, attrs["channels"] || attrs[:channels] || [])
|
||||||
|> NoteSlug.maybe_generate_slug()
|
|> NoteSlug.maybe_generate_slug()
|
||||||
|> NoteSlug.unique_constraint()
|
|> NoteSlug.unique_constraint()
|
||||||
|> validate_required([:name, :content, :slug, :kind])
|
|> validate_required([:name, :content, :slug, :kind])
|
||||||
|
|
|
@ -7,7 +7,7 @@ defmodule Chiya.Site do
|
||||||
alias Chiya.Repo
|
alias Chiya.Repo
|
||||||
alias Chiya.Site.Setting
|
alias Chiya.Site.Setting
|
||||||
|
|
||||||
@preloads [:home_channel, :default_channel]
|
@preloads [:home_channel, :default_channel, :micropub_channel]
|
||||||
@default_settings %{
|
@default_settings %{
|
||||||
title: "Site Title",
|
title: "Site Title",
|
||||||
subtitle: "Subtitle",
|
subtitle: "Subtitle",
|
||||||
|
|
|
@ -850,5 +850,4 @@ defmodule ChiyaWeb.CoreComponents do
|
||||||
defp upload_error_to_string(:too_large), do: "Too large"
|
defp upload_error_to_string(:too_large), do: "Too large"
|
||||||
defp upload_error_to_string(:too_many_files), do: "You have selected too many files"
|
defp upload_error_to_string(:too_many_files), do: "You have selected too many files"
|
||||||
defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
defp upload_error_to_string(:not_accepted), do: "You have selected an unacceptable file type"
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -23,7 +23,11 @@ defmodule ChiyaWeb.NoteController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(conn, _params) do
|
def new(conn, _params) do
|
||||||
changeset = Notes.change_note(%Note{})
|
settings = Chiya.Site.get_settings()
|
||||||
|
|
||||||
|
changeset =
|
||||||
|
%Note{channels: [settings.default_channel]}
|
||||||
|
|> Notes.change_note()
|
||||||
|
|
||||||
render(conn, :new,
|
render(conn, :new,
|
||||||
changeset: changeset,
|
changeset: changeset,
|
||||||
|
@ -33,6 +37,7 @@ defmodule ChiyaWeb.NoteController do
|
||||||
end
|
end
|
||||||
|
|
||||||
def create(conn, %{"note" => note_params}) do
|
def create(conn, %{"note" => note_params}) do
|
||||||
|
IO.inspect(note_params)
|
||||||
note_params = from_channel_ids(note_params)
|
note_params = from_channel_ids(note_params)
|
||||||
|
|
||||||
case Notes.create_note(note_params) do
|
case Notes.create_note(note_params) do
|
||||||
|
@ -42,7 +47,7 @@ defmodule ChiyaWeb.NoteController do
|
||||||
|> redirect(to: ~p"/admin/notes/#{note}")
|
|> redirect(to: ~p"/admin/notes/#{note}")
|
||||||
|
|
||||||
{:error, %Ecto.Changeset{} = changeset} ->
|
{:error, %Ecto.Changeset{} = changeset} ->
|
||||||
render(conn, :new, changeset: changeset, channels: to_channel_options())
|
render(conn, :new, changeset: changeset, channels: to_channel_options(), tags: [])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,19 +1,20 @@
|
||||||
defmodule ChiyaWeb.NoteHTML do
|
defmodule ChiyaWeb.NoteHTML do
|
||||||
use ChiyaWeb, :html
|
use ChiyaWeb, :html
|
||||||
|
|
||||||
embed_templates "note_html/*"
|
embed_templates("note_html/*")
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Renders a note form.
|
Renders a note form.
|
||||||
"""
|
"""
|
||||||
attr :changeset, Ecto.Changeset, required: true
|
attr(:changeset, Ecto.Changeset, required: true)
|
||||||
attr :action, :string, required: true
|
attr(:action, :string, required: true)
|
||||||
attr :channels, :list, required: true
|
attr(:channels, :list, required: true)
|
||||||
attr :tags, :list, required: true
|
attr(:tags, :list, required: true)
|
||||||
|
|
||||||
def note_form(assigns)
|
def note_form(assigns)
|
||||||
|
|
||||||
def selected_channels(changeset), do: Enum.map(changeset.data.channels, fn c -> c.id end)
|
def selected_channels(changeset),
|
||||||
|
do: Enum.map(changeset.data.channels, fn c -> c.id end)
|
||||||
|
|
||||||
def tags_to_string(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
def tags_to_string(tags), do: Enum.map_join(tags, ", ", fn t -> t.name end)
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,5 +37,8 @@
|
||||||
<:item title="Default Channel">
|
<:item title="Default Channel">
|
||||||
<%= if @setting.default_channel, do: @setting.default_channel.name %>
|
<%= if @setting.default_channel, do: @setting.default_channel.name %>
|
||||||
</:item>
|
</:item>
|
||||||
|
<:item title="Micropub Default Channel">
|
||||||
|
<%= if @setting.micropub_channel, do: @setting.micropub_channel.name %>
|
||||||
|
</:item>
|
||||||
</.list>
|
</.list>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
Loading…
Reference in a new issue