add publish unpublish actions
This commit is contained in:
parent
cf8677cc95
commit
d6fb14bb38
3 changed files with 51 additions and 0 deletions
|
@ -104,6 +104,46 @@ defmodule ChiyaWeb.NoteController do
|
||||||
|> text(raw_note)
|
|> text(raw_note)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def publish(conn, %{"id" => id}) do
|
||||||
|
note_params = %{published_at: NaiveDateTime.local_now()}
|
||||||
|
note = Notes.get_note_preloaded!(id)
|
||||||
|
|
||||||
|
case Notes.update_note(note, note_params) do
|
||||||
|
{:ok, note} ->
|
||||||
|
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
|
||||||
|
|
||||||
|
def unpublish(conn, %{"id" => id}) do
|
||||||
|
note_params = %{published_at: nil}
|
||||||
|
note = Notes.get_note_preloaded!(id)
|
||||||
|
|
||||||
|
case Notes.update_note(note, note_params) do
|
||||||
|
{:ok, note} ->
|
||||||
|
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
|
||||||
|
|
||||||
def edit_image(conn, %{"image_id" => id}) do
|
def edit_image(conn, %{"image_id" => id}) do
|
||||||
image = Notes.get_note_image!(id)
|
image = Notes.get_note_image!(id)
|
||||||
changeset = Notes.change_note_image(image)
|
changeset = Notes.change_note_image(image)
|
||||||
|
|
|
@ -25,6 +25,15 @@ defmodule ChiyaWeb.NoteShowLive do
|
||||||
<.link href={~p"/admin/notes/#{@note}/raw"}>
|
<.link href={~p"/admin/notes/#{@note}/raw"}>
|
||||||
<.button>Raw</.button>
|
<.button>Raw</.button>
|
||||||
</.link>
|
</.link>
|
||||||
|
<%= if is_nil(@note.published_at) do %>
|
||||||
|
<.link href={~p"/admin/notes/#{@note}/publish"}>
|
||||||
|
<.button>Publish</.button>
|
||||||
|
</.link>
|
||||||
|
<% else %>
|
||||||
|
<.link href={~p"/admin/notes/#{@note}/unpublish"}>
|
||||||
|
<.button>Un-Publish</.button>
|
||||||
|
</.link>
|
||||||
|
<% end %>
|
||||||
</:actions>
|
</:actions>
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
|
|
|
@ -67,6 +67,8 @@ defmodule ChiyaWeb.Router do
|
||||||
|
|
||||||
live "/notes/:id", NoteShowLive, :show
|
live "/notes/:id", NoteShowLive, :show
|
||||||
get "/notes/:id/raw", NoteController, :raw
|
get "/notes/:id/raw", NoteController, :raw
|
||||||
|
get "/notes/:id/publish", NoteController, :publish
|
||||||
|
get "/notes/:id/unpublish", NoteController, :unpublish
|
||||||
|
|
||||||
get "/notes/:id/image/:image_id", NoteController, :edit_image
|
get "/notes/:id/image/:image_id", NoteController, :edit_image
|
||||||
put "/notes/:id/image/:image_id", NoteController, :update_image
|
put "/notes/:id/image/:image_id", NoteController, :update_image
|
||||||
|
|
Loading…
Reference in a new issue