add layout to channels

This commit is contained in:
Inhji 2023-04-07 22:01:43 +02:00
parent 3cf4e0163a
commit 9e1a315b99
3 changed files with 19 additions and 2 deletions

View file

@ -9,6 +9,7 @@ defmodule Chiya.Channels.Channel do
field :name, :string
field :slug, ChannelSlug.Type
field :visibility, Ecto.Enum, values: [:public, :private, :unlisted]
field :layout, Ecto.Enum, values: [:default, :gallery]
many_to_many :notes, Chiya.Notes.Note,
join_through: "channels_notes",
@ -20,10 +21,10 @@ defmodule Chiya.Channels.Channel do
@doc false
def changeset(channel, attrs) do
channel
|> cast(attrs, [:name, :content, :visibility, :slug])
|> cast(attrs, [:name, :content, :visibility, :slug, :layout])
|> ChannelSlug.maybe_generate_slug()
|> ChannelSlug.unique_constraint()
|> validate_required([:name, :content, :visibility, :slug])
|> validate_required([:name, :content, :visibility, :slug, :layout])
|> validate_exclusion(:slug, ~w(admin user dev))
end
end

View file

@ -11,6 +11,13 @@
prompt="Choose a value"
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" />
<:actions>
<.button>Save Channel</.button>

View file

@ -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