commit
cc81014236
2 changed files with 21 additions and 12 deletions
|
@ -1,26 +1,25 @@
|
||||||
defmodule ChiyaWeb.NoteController do
|
defmodule ChiyaWeb.NoteController do
|
||||||
use ChiyaWeb, :controller
|
use ChiyaWeb, :controller
|
||||||
|
import Plug.Conn, only: [assign: 3]
|
||||||
|
|
||||||
alias Chiya.Notes
|
alias Chiya.Notes
|
||||||
alias Chiya.Notes.{Note, NoteImport}
|
alias Chiya.Notes.{Note, NoteImport}
|
||||||
|
|
||||||
def index(conn, %{"channel" => channel_slug}) do
|
def index(conn, %{"channel" => channel_slug}) do
|
||||||
channels =
|
|
||||||
Chiya.Channels.list_channels()
|
|
||||||
|> Chiya.Channels.preload_channel()
|
|
||||||
|
|
||||||
channel = Chiya.Channels.get_channel_by_slug!(channel_slug)
|
channel = Chiya.Channels.get_channel_by_slug!(channel_slug)
|
||||||
notes = Notes.list_notes_by_channel(channel)
|
notes = Notes.list_notes_by_channel(channel)
|
||||||
render(conn, :index, notes: notes, channels: channels)
|
|
||||||
|
conn
|
||||||
|
|> with_channels()
|
||||||
|
|> render(:index, notes: notes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def index(conn, _params) do
|
def index(conn, _params) do
|
||||||
channels =
|
|
||||||
Chiya.Channels.list_channels()
|
|
||||||
|> Chiya.Channels.preload_channel()
|
|
||||||
|
|
||||||
notes = Notes.list_notes()
|
notes = Notes.list_notes()
|
||||||
render(conn, :index, notes: notes, channels: channels)
|
|
||||||
|
conn
|
||||||
|
|> with_channels()
|
||||||
|
|> render(:index, notes: notes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def new(conn, _params) do
|
def new(conn, _params) do
|
||||||
|
@ -150,6 +149,16 @@ defmodule ChiyaWeb.NoteController do
|
||||||
|> redirect(to: ~p"/admin/notes")
|
|> redirect(to: ~p"/admin/notes")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
defp with_channels(conn) do
|
||||||
|
assign(
|
||||||
|
conn,
|
||||||
|
:channels,
|
||||||
|
Chiya.Channels.list_channels()
|
||||||
|
|> Chiya.Channels.preload_channel()
|
||||||
|
|> Enum.filter(fn c -> not Enum.empty?(c.notes) end)
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
defp from_channel_ids(note_params) do
|
defp from_channel_ids(note_params) do
|
||||||
selected_ids = Enum.map(note_params["channels"] || [], &String.to_integer/1)
|
selected_ids = Enum.map(note_params["channels"] || [], &String.to_integer/1)
|
||||||
|
|
||||||
|
|
|
@ -12,9 +12,9 @@
|
||||||
</.header>
|
</.header>
|
||||||
|
|
||||||
<section class="flex flex-row flex-wrap mt-4 gap-3">
|
<section class="flex flex-row flex-wrap mt-4 gap-3">
|
||||||
<a href={~p"/admin/notes"} class="text-sm rounded-full bg-gray-300 hover:bg-gray-400 px-2 py-1">All</a>
|
<a href={~p"/admin/notes"} class="text-sm dark:text-gray-300 rounded-full bg-gray-300 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 px-2 py-1">All</a>
|
||||||
<%= for channel <- @channels do %>
|
<%= for channel <- @channels do %>
|
||||||
<a href={~p"/admin/notes?channel=#{channel.slug}"} class="text-sm rounded-full bg-gray-300 hover:bg-gray-400 px-2 py-1"><%= channel.name %> <span class="text-gray-600">(<%= Enum.count(channel.notes) %>)</span></a>
|
<a href={~p"/admin/notes?channel=#{channel.slug}"} class="text-sm dark:text-gray-300 rounded-full bg-gray-300 hover:bg-gray-400 dark:bg-gray-700 dark:hover:bg-gray-600 px-2 py-1"><%= channel.name %> <span class="text-gray-600 dark:text-gray-500">(<%= Enum.count(channel.notes) %>)</span></a>
|
||||||
<% end %>
|
<% end %>
|
||||||
</section>
|
</section>
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue