84 lines
1.9 KiB
Elixir
84 lines
1.9 KiB
Elixir
defmodule ComfycampWeb.NotesEditorHTML do
|
|
use ComfycampWeb, :html
|
|
|
|
def index(assigns) do
|
|
~H"""
|
|
<div>
|
|
<.link href={~p"/admin/notes/new"}>
|
|
Создать заметку
|
|
</.link>
|
|
|
|
<ul>
|
|
<%= for note <- @notes do %>
|
|
<li>
|
|
<.link href={~p"/admin/notes/#{note}"}>
|
|
<%= note.title %>
|
|
</.link>
|
|
|
|
<%= note.updated_at %>
|
|
</li>
|
|
<% end %>
|
|
</ul>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def show(assigns) do
|
|
~H"""
|
|
<div>
|
|
<.back navigate={~p"/admin/notes"}>Назад</.back>
|
|
<h3><%= @note.title %></h3>
|
|
|
|
<.link href={~p"/admin/notes/#{@note}/edit"}>
|
|
Редактировать
|
|
</.link>
|
|
|
|
<p>Создана: <%= @note.inserted_at %></p>
|
|
<p>Обновлена: <%= @note.updated_at %></p>
|
|
|
|
<pre><%= @note.markdown %></pre>
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def new(assigns) do
|
|
~H"""
|
|
<div>
|
|
<h2>Новая заметка</h2>
|
|
<.note_form changeset={@changeset} action={~p"/admin/notes"} />
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def edit(assigns) do
|
|
~H"""
|
|
<div>
|
|
<h2>Редактировать заметку</h2>
|
|
<.note_form changeset={@changeset} action={~p"/admin/notes/#{@changeset.data.id}"} />
|
|
</div>
|
|
"""
|
|
end
|
|
|
|
def note_form(assigns) do
|
|
~H"""
|
|
<.simple_form :let={f} for={@changeset} action={@action}>
|
|
<.input field={f[:title]} type="text" label="Заголовок" />
|
|
<.input field={f[:markdown]} type="textarea" label="Содержание (markdown)" />
|
|
|
|
<:actions>
|
|
<.button>Сохранить</.button>
|
|
</:actions>
|
|
</.simple_form>
|
|
|
|
<%= if @changeset.data.id do %>
|
|
<.link
|
|
href={~p"/admin/notes/#{@changeset.data}"}
|
|
method="DELETE"
|
|
data-confirm="Вы уверены?"
|
|
>
|
|
Удалить
|
|
</.link>
|
|
<% end %>
|
|
"""
|
|
end
|
|
end
|