Browse Source

feat: add lists untagged, special @ notes

main
Inhji Y. 8 months ago
parent
commit
6a42d8b43e
  1. 57
      lib/mirage/notes.ex
  2. 4
      lib/mirage_web/controllers/user_controller.ex
  3. 26
      lib/mirage_web/templates/user/index.html.eex

57
lib/mirage/notes.ex

@ -6,7 +6,7 @@ defmodule Mirage.Notes do
import Ecto.Query, warn: false
alias Mirage.Repo
alias Mirage.Notes.{Note, Topic, NoteNote, NoteLink}
alias Mirage.Notes.{Note, Topic, NoteNote, NoteLink, NoteTopic}
@note_preloads [:links, :topics, :backlinks]
@topic_preloads [notes: @note_preloads]
@ -21,19 +21,36 @@ defmodule Mirage.Notes do
"""
def list_notes do
Note
|> limit(10)
|> order_by(desc: :inserted_at)
|> Repo.all()
|> Repo.preload(@note_preloads)
q =
from n in Note,
limit: 10,
select: n,
order_by: :inserted_at,
preload: ^@note_preloads
Repo.all(q)
end
def list_notes(:at) do
q =
from n in Note,
where: like(n.title, "@%"),
limit: 3,
select: n,
preload: ^@note_preloads
Repo.all(q)
end
def list_notes(:last_edited) do
Note
|> limit(3)
|> order_by(desc: :updated_at)
|> Repo.all()
|> Repo.preload(@note_preloads)
q =
from n in Note,
limit: 3,
select: n,
order_by: [desc: n.updated_at],
preload: ^@note_preloads
Repo.all(q)
end
def list_notes(:unlinked) do
@ -47,9 +64,21 @@ defmodule Mirage.Notes do
limit: 3,
preload: ^@note_preloads
q
|> Repo.all()
|> Repo.preload(@note_preloads)
Repo.all(q)
end
def list_notes(:untagged) do
q =
from n in Note,
full_join: t in NoteTopic,
on: t.note_id == n.id,
where: not like(n.title, "@%"),
where: is_nil(t.id),
select: n,
limit: 3,
preload: ^@note_preloads
Repo.all(q)
end
@doc """

4
lib/mirage_web/controllers/user_controller.ex

@ -4,10 +4,14 @@ defmodule MirageWeb.UserController do
def index(conn, _params) do
last_edited = Mirage.Notes.list_notes(:last_edited)
unlinked = Mirage.Notes.list_notes(:unlinked)
untagged = Mirage.Notes.list_notes(:untagged)
at = Mirage.Notes.list_notes(:at)
render(conn, "index.html",
notes: %{
at: at,
last_edited: last_edited,
untagged: untagged,
unlinked: unlinked
}
)

26
lib/mirage_web/templates/user/index.html.eex

@ -30,6 +30,32 @@
</div>
</section>
<section class="bg-content width-full">
<h3>Untagged</h3>
<div class="grid">
<%= for note <- @notes.untagged do %>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<section class="bg-content width-full">
<h3>At-Notes</h3>
<div class="grid">
<%= for note <- @notes.at do %>
<%= link to: Routes.live_path(@conn, MirageWeb.ShowNoteLive, note), class: "col card" do %>
<strong><%= note.title %></strong>
<p><%= note.content |> String.slice(0..50) %></p>
<% end %>
<% end %>
</div>
</section>
<div class="buttons">
<%= link "Edit User", to: Routes.user_settings_path(@conn, :edit), class: "button" %>
</div>

Loading…
Cancel
Save