add layout to channels
This commit is contained in:
parent
3cf4e0163a
commit
9e1a315b99
3 changed files with 19 additions and 2 deletions
|
@ -9,6 +9,7 @@ defmodule Chiya.Channels.Channel do
|
||||||
field :name, :string
|
field :name, :string
|
||||||
field :slug, ChannelSlug.Type
|
field :slug, ChannelSlug.Type
|
||||||
field :visibility, Ecto.Enum, values: [:public, :private, :unlisted]
|
field :visibility, Ecto.Enum, values: [:public, :private, :unlisted]
|
||||||
|
field :layout, Ecto.Enum, values: [:default, :gallery]
|
||||||
|
|
||||||
many_to_many :notes, Chiya.Notes.Note,
|
many_to_many :notes, Chiya.Notes.Note,
|
||||||
join_through: "channels_notes",
|
join_through: "channels_notes",
|
||||||
|
@ -20,10 +21,10 @@ defmodule Chiya.Channels.Channel do
|
||||||
@doc false
|
@doc false
|
||||||
def changeset(channel, attrs) do
|
def changeset(channel, attrs) do
|
||||||
channel
|
channel
|
||||||
|> cast(attrs, [:name, :content, :visibility, :slug])
|
|> cast(attrs, [:name, :content, :visibility, :slug, :layout])
|
||||||
|> ChannelSlug.maybe_generate_slug()
|
|> ChannelSlug.maybe_generate_slug()
|
||||||
|> ChannelSlug.unique_constraint()
|
|> ChannelSlug.unique_constraint()
|
||||||
|> validate_required([:name, :content, :visibility, :slug])
|
|> validate_required([:name, :content, :visibility, :slug, :layout])
|
||||||
|> validate_exclusion(:slug, ~w(admin user dev))
|
|> validate_exclusion(:slug, ~w(admin user dev))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -11,6 +11,13 @@
|
||||||
prompt="Choose a value"
|
prompt="Choose a value"
|
||||||
options={Ecto.Enum.values(Chiya.Channels.Channel, :visibility)}
|
options={Ecto.Enum.values(Chiya.Channels.Channel, :visibility)}
|
||||||
/>
|
/>
|
||||||
|
<.input
|
||||||
|
field={f[:layout]}
|
||||||
|
type="select"
|
||||||
|
label="Layout"
|
||||||
|
prompt="Choose a value"
|
||||||
|
options={Ecto.Enum.values(Chiya.Channels.Channel, :layout)}
|
||||||
|
/>
|
||||||
<.input field={f[:slug]} type="text" label="Slug" />
|
<.input field={f[:slug]} type="text" label="Slug" />
|
||||||
<:actions>
|
<:actions>
|
||||||
<.button>Save Channel</.button>
|
<.button>Save Channel</.button>
|
||||||
|
|
|
@ -0,0 +1,9 @@
|
||||||
|
defmodule Chiya.Repo.Migrations.AddLayoutToChannel do
|
||||||
|
use Ecto.Migration
|
||||||
|
|
||||||
|
def change do
|
||||||
|
alter table(:channels) do
|
||||||
|
add :layout, :string, default: "default"
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Reference in a new issue