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