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

Reviewed-on: #52
This commit is contained in:
inhji 2023-04-08 11:41:52 +02:00
commit 6326acbbdf
3 changed files with 31 additions and 1 deletions

View file

@ -26,6 +26,15 @@ defmodule Chiya.Notes do
|> Repo.preload(@preloads)
end
def list_notes_by_channel(%Chiya.Channels.Channel{} = channel) do
Note
|> join(:inner, [n], c in assoc(n, :channels))
|> where([n, c], c.id == ^channel.id)
|> order_by([n], desc: n.updated_at, desc: n.published_at)
|> Repo.all()
|> Repo.preload(@preloads)
end
@doc """
Preloads a note

View file

@ -4,9 +4,23 @@ defmodule ChiyaWeb.NoteController do
alias Chiya.Notes
alias Chiya.Notes.{Note, NoteImport}
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)
notes = Notes.list_notes_by_channel(channel)
render(conn, :index, notes: notes, channels: channels)
end
def index(conn, _params) do
channels =
Chiya.Channels.list_channels()
|> Chiya.Channels.preload_channel()
notes = Notes.list_notes()
render(conn, :index, notes: notes)
render(conn, :index, notes: notes, channels: channels)
end
def new(conn, _params) do

View file

@ -11,6 +11,13 @@
</:actions>
</.header>
<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>
<%= 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>
<% end %>
</section>
<.table id="notes" rows={@notes} row_click={&JS.navigate(~p"/admin/notes/#{&1}")}>
<:col :let={note} label="Name"><%= note.name %></:col>
<:col :let={note} label="Updated at"><%= from_now(note.updated_at) %></:col>