add pagetitles for note pages

This commit is contained in:
Inhji 2023-07-04 07:13:49 +02:00
parent faa7acd064
commit 9784572b17
2 changed files with 25 additions and 28 deletions

View file

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

View file

@ -110,13 +110,15 @@ defmodule ChiyaWeb.NoteShowLive do
@impl true @impl true
def mount(%{"id" => note_id}, _session, socket) do def mount(%{"id" => note_id}, _session, socket) do
image_changeset = Notes.change_note_image(%NoteImage{}) image_changeset = Notes.change_note_image(%NoteImage{})
note = Notes.get_note_preloaded!(note_id)
{:ok, {:ok,
socket socket
|> assign(:note, Notes.get_note_preloaded!(note_id)) |> assign(:note, note)
|> assign(:uploaded_files, []) |> assign(:uploaded_files, [])
|> assign(:image_edit_form, to_form(image_changeset)) |> assign(:image_edit_form, to_form(image_changeset))
|> assign(:image_form, to_form(image_changeset)) |> assign(:image_form, to_form(image_changeset))
|> assign(:page_title, note.name)
|> allow_upload(:note_images, |> allow_upload(:note_images,
accept: @accepted_extensions, accept: @accepted_extensions,
max_entries: 100 max_entries: 100