From 9784572b1743d12612501fb9bbc5a4e8c3103590 Mon Sep 17 00:00:00 2001 From: Inhji Date: Tue, 4 Jul 2023 07:13:49 +0200 Subject: [PATCH] add pagetitles for note pages --- lib/chiya_web/controllers/note_controller.ex | 49 +++++++++----------- lib/chiya_web/live/note_show_live.ex | 4 +- 2 files changed, 25 insertions(+), 28 deletions(-) diff --git a/lib/chiya_web/controllers/note_controller.ex b/lib/chiya_web/controllers/note_controller.ex index 48cdb4c..fd034c4 100644 --- a/lib/chiya_web/controllers/note_controller.ex +++ b/lib/chiya_web/controllers/note_controller.ex @@ -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 diff --git a/lib/chiya_web/live/note_show_live.ex b/lib/chiya_web/live/note_show_live.ex index d31b828..420edfa 100644 --- a/lib/chiya_web/live/note_show_live.ex +++ b/lib/chiya_web/live/note_show_live.ex @@ -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