2024-07-29 18:07:44 +05:00
|
|
|
|
defmodule ComfycampWeb.NotesEditorHTML do
|
|
|
|
|
use ComfycampWeb, :html
|
|
|
|
|
|
2024-08-25 23:58:22 +05:00
|
|
|
|
def index(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<div>
|
2024-08-31 17:06:02 +05:00
|
|
|
|
<h3>Заметки</h3>
|
2024-08-25 23:58:22 +05:00
|
|
|
|
<.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>
|
|
|
|
|
<h3><%= @note.title %></h3>
|
2024-08-31 17:06:02 +05:00
|
|
|
|
<.back navigate={~p"/admin/notes"}>Назад</.back>
|
2024-08-25 23:58:22 +05:00
|
|
|
|
|
|
|
|
|
<.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>
|
2024-08-31 17:06:02 +05:00
|
|
|
|
<h3>Новая заметка</h3>
|
2024-08-25 23:58:22 +05:00
|
|
|
|
<.note_form changeset={@changeset} action={~p"/admin/notes"} />
|
|
|
|
|
</div>
|
|
|
|
|
"""
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
def edit(assigns) do
|
|
|
|
|
~H"""
|
|
|
|
|
<div>
|
2024-08-31 17:06:02 +05:00
|
|
|
|
<h3>Редактировать заметку</h3>
|
2024-08-25 23:58:22 +05:00
|
|
|
|
<.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
|
2024-07-29 18:07:44 +05:00
|
|
|
|
end
|