Merge pull request 'devel' (#167) from devel into main

Reviewed-on: #167
This commit is contained in:
inhji 2023-07-04 07:14:41 +02:00
commit 19682bab21
6 changed files with 83 additions and 82 deletions

View file

@ -11,7 +11,7 @@ defmodule ChiyaWeb.NoteController do
conn
|> with_channels()
|> render(:index, notes: notes)
|> render(:index, notes: notes, page_title: "Notes")
end
def index(conn, _params) do
@ -19,7 +19,7 @@ defmodule ChiyaWeb.NoteController do
conn
|> with_channels()
|> render(:index, notes: notes)
|> render(:index, notes: notes, page_title: "Notes")
end
def new(conn, _params) do
@ -34,7 +34,8 @@ defmodule ChiyaWeb.NoteController do
changeset: changeset,
channels: to_channel_options(),
selected_channels: default_channels,
tags: []
tags: [],
page_title: "New Note"
)
end
@ -54,14 +55,13 @@ defmodule ChiyaWeb.NoteController do
changeset: changeset,
channels: to_channel_options(),
selected_channels: nil,
tags: []
tags: [],
page_title: "New Note"
)
end
end
def show(conn, %{"id" => id}) do
# note = Notes.get_note!(id)
# render(conn, :show, note: note)
live_render(conn, NoteShowLive, session: %{"note_id" => id})
end
@ -75,7 +75,8 @@ defmodule ChiyaWeb.NoteController do
changeset: changeset,
channels: to_channel_options(),
selected_channels: selected_channels,
tags: note.tags
tags: note.tags,
page_title: "EDIT #{note.name}"
)
end
@ -97,7 +98,8 @@ defmodule ChiyaWeb.NoteController do
changeset: changeset,
channels: to_channel_options(),
selected_channels: nil,
tags: note.tags
tags: note.tags,
page_title: "EDIT #{note.name}"
)
end
end
@ -130,14 +132,6 @@ defmodule ChiyaWeb.NoteController do
conn
|> put_flash(:info, "Note published successfully.")
|> redirect(to: ~p"/admin/notes/#{note}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit,
note: note,
changeset: changeset,
channels: to_channel_options(),
tags: note.tags
)
end
end
@ -149,14 +143,6 @@ defmodule ChiyaWeb.NoteController do
conn
|> put_flash(:info, "Note un-published successfully.")
|> redirect(to: ~p"/admin/notes/#{note}")
{:error, %Ecto.Changeset{} = changeset} ->
render(conn, :edit,
note: note,
changeset: changeset,
channels: to_channel_options(),
tags: note.tags
)
end
end
@ -181,7 +167,10 @@ defmodule ChiyaWeb.NoteController do
end
def import_prepare(conn, _params) do
render(conn, :import, changeset: NoteImport.change_note_import(%{}))
render(conn, :import,
changeset: NoteImport.change_note_import(%{}),
page_title: "Import Note"
)
end
def import_run(conn, %{
@ -211,14 +200,20 @@ defmodule ChiyaWeb.NoteController do
end
_ ->
render(conn, :import, changeset: NoteImport.change_note_import(%{}))
render(conn, :import,
changeset: NoteImport.change_note_import(%{}),
page_title: "Import Note"
)
end
end
def import_run(conn, _params) do
conn
|> put_flash(:error, "Error while importing.")
|> redirect(to: ~p"/admin/notes")
|> render(:import,
changeset: NoteImport.change_note_import(%{}),
page_title: "Import Note"
)
end
defp with_channels(conn) do

View file

@ -3,15 +3,15 @@
<:subtitle>Notes are the content, the heart of your site.</:subtitle>
<:actions>
<.link href={~p"/admin/notes/new"}>
<.button>New Note</.button>
<.button><.icon name="hero-plus-small" /> New Note</.button>
</.link>
<.link href={~p"/admin/notes/import"}>
<.button>Import Note</.button>
<.button><.icon name="hero-arrow-down-tray" /> Import Note</.button>
</.link>
</:actions>
</.header>
<section class="flex flex-row flex-wrap mt-4 -mb-6 gap-3">
<section class="flex flex-row flex-wrap mt-6 -mb-6 gap-3">
<a
href={~p"/admin/notes"}
class="text-sm dark:text-gray-300 rounded-full bg-gray-100 hover:bg-gray-200 dark:bg-gray-800 dark:hover:bg-gray-700 px-2 py-1 border border-gray-300 dark:border-gray-600 shadow-sm transition"

View file

@ -3,40 +3,40 @@
<h1 class="mt-16 lg:text-5xl md:text-4xl text-3xl font-bold text-theme-base | p-name">
<%= @note.name %>
</h1>
<p class="mt-2 leading-6 text-theme-base">
<%= if @note.published_at do %>
<span>Published</span>
<% else %>
<span>Unpublished</span>
<% end %>
<time class="font-semibold | dt-published"><%= pretty_date(@note.published_at) %></time>
<.dot />
<span>Last Updated</span>
<time class="font-semibold" datetime={datetime(@note.updated_at)}><%= pretty_date(@note.updated_at) %></time>
<%= if not Enum.empty?(@note.tags) do %>
<.dot />
<span>Tags</span>
<span>
<%= for tag <- @note.tags do %>
<a href={~p"/tagged-with/#{tag.slug}"} class="underline-link font-semibold">
<%= tag.name %>
</a>
<% end %>
</span>
<% end %>
<%= if @current_user do %>
<.dot />
<a href={~p"/admin/notes/#{@note}"} class="underline-link font-semibold">Show in Admin</a>
<% end %>
</p>
</header>
<section class="mx-auto mt-8 prose prose-gruvbox md:prose-lg lg:prose-xl | p-summary e-content">
<section class="mx-auto mt-8 prose prose-gruvbox md:prose-lg lg:prose-xl | p-summary e-content">
<%= Markdown.render(@note.content) |> raw %>
</section>
<footer class="mt-8 mx-auto max-w-2xl">
<a href={~p"/note/#{@note.slug}"} class="text-theme-base underline-link font-semibold | u-url u-uid">Permalink</a>
<footer class="mt-8 mx-auto max-w-2xl text-theme-base">
<%= if @note.published_at do %>
<span>Published</span>
<% else %>
<span>Unpublished</span>
<% end %>
<time class="font-semibold | dt-published"><%= pretty_date(@note.published_at) %></time>
<.dot />
<span>Last Updated</span>
<time class="font-semibold" datetime={datetime(@note.updated_at)}><%= pretty_date(@note.updated_at) %></time>
<%= if not Enum.empty?(@note.tags) do %>
<.dot />
<span>Tags</span>
<span class="inline-flex flex-row gap-1">
<%= for tag <- @note.tags do %>
<a href={~p"/tagged-with/#{tag.slug}"} class="underline-link font-semibold | p-category">
<%= tag.name %>
</a>
<% end %>
</span>
<% end %>
<%= if @current_user do %>
<.dot />
<a href={~p"/admin/notes/#{@note}"} class="underline-link font-semibold">Show in Admin</a>
<% end %>
<a href={~p"/about"} class="hidden | u-author">Inhji</a>
<a href={~p"/note/#{@note.slug}"} class="hidden | u-url u-uid"><%= @note.name %></a>
</footer>
<section class="mt-8 mx-auto max-w-2xl">

View file

@ -30,14 +30,18 @@ defmodule ChiyaWeb.AdminHomeLive do
|> Map.put_new("published_at", NaiveDateTime.local_now())
case Chiya.Notes.create_note(params) do
{:ok, _note} ->
{:noreply, socket |> put_flash(:info, "Note created!")}
{:ok, note} ->
{:noreply, socket
|> put_flash(:info, "Note created!")
|> push_navigate(to: ~p"/note/#{note.slug}")}
{:error, %Ecto.Changeset{} = changeset} ->
IO.inspect(changeset)
{:noreply,
socket |> put_flash(:error, "Could not create note!") |> assign(form: to_form(changeset))}
socket
|> put_flash(:error, "Could not create note!")
|> assign(form: to_form(changeset))}
end
end
@ -51,14 +55,6 @@ defmodule ChiyaWeb.AdminHomeLive do
<.link href={~p"/user"}>
<.button>Profile</.button>
</.link>
<.link
href={~p"/user/log_out"}
method="delete"
data-confirm="Do you want to logout?"
class="text-sm leading-6 text-gray-900 dark:text-gray-100 dark:hover:text-gray-300 hover:text-gray-700"
>
<.button>Log out</.button>
</.link>
</:actions>
</.header>
@ -66,7 +62,7 @@ defmodule ChiyaWeb.AdminHomeLive do
<.simple_form for={@form} phx-change="validate" phx-submit="save">
<.input field={@form[:content]} type="textarea" />
<:actions>
<.button>Save</.button>
<.button>Publish</.button>
</:actions>
</.simple_form>
</section>

View file

@ -16,26 +16,26 @@ defmodule ChiyaWeb.NoteShowLive do
<%= @note.name %>
<:actions>
<.link href={~p"/admin/notes/#{@note}/edit"}>
<.button>Edit</.button>
<.button><.icon name="hero-pencil" /> Edit</.button>
</.link>
<.link href={~p"/note/#{@note.slug}"}>
<.button>Preview</.button>
</.link>
<.link href={~p"/admin/notes/#{@note}/raw"}>
<.button>Raw</.button>
</.link>
<.link href={~p"/admin/notes/#{@note}"} method="delete" data-confirm="Are you sure?">
<.button>Delete</.button>
<.button><.icon name="hero-eye" /> Preview</.button>
</.link>
<%= if is_nil(@note.published_at) do %>
<.link href={~p"/admin/notes/#{@note}/publish"}>
<.button>Publish</.button>
<.button><.icon name="hero-newspaper" /> Publish</.button>
</.link>
<% else %>
<.link href={~p"/admin/notes/#{@note}/unpublish"}>
<.button>Un-Publish</.button>
<.button><.icon name="hero-newspaper" /> Un-Publish</.button>
</.link>
<% end %>
<.link href={~p"/admin/notes/#{@note}/raw"}>
<.button><.icon name="hero-code-bracket" /> Raw</.button>
</.link>
<.link href={~p"/admin/notes/#{@note}"} method="delete" data-confirm="Are you sure?">
<.button><.icon name="hero-trash" /> Delete</.button>
</.link>
</:actions>
</.header>
@ -110,13 +110,15 @@ defmodule ChiyaWeb.NoteShowLive do
@impl true
def mount(%{"id" => note_id}, _session, socket) do
image_changeset = Notes.change_note_image(%NoteImage{})
note = Notes.get_note_preloaded!(note_id)
{:ok,
socket
|> assign(:note, Notes.get_note_preloaded!(note_id))
|> assign(:note, note)
|> assign(:uploaded_files, [])
|> assign(:image_edit_form, to_form(image_changeset))
|> assign(:image_form, to_form(image_changeset))
|> assign(:page_title, note.name)
|> allow_upload(:note_images,
accept: @accepted_extensions,
max_entries: 100

View file

@ -9,6 +9,14 @@ defmodule ChiyaWeb.UserProfileLive do
<.link href={~p"/user/settings"}>
<.button>Edit User</.button>
</.link>
<.link
href={~p"/user/log_out"}
method="delete"
data-confirm="Do you want to logout?"
class="text-sm leading-6 text-gray-900 dark:text-gray-100 dark:hover:text-gray-300 hover:text-gray-700"
>
<.button>Log out</.button>
</.link>
</:actions>
</.header>