2 Commits

  1. 9
      CHANGELOG.md
  2. 57
      lib/mirage/notes.ex
  3. 4
      lib/mirage_web/controllers/user_controller.ex
  4. 26
      lib/mirage_web/templates/user/index.html.eex
  5. 2
      mix.exs

9
CHANGELOG.md

@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.26.0](https://git.inhji.de/inhji/mirage/compare/v0.25.0...v0.26.0) (2021-02-13)
### Features:
* add lists untagged, special @ notes
## [v0.25.0](https://git.inhji.de/inhji/mirage/compare/v0.24.0...v0.25.0) (2021-02-13)

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>

2
mix.exs

@ -1,7 +1,7 @@
defmodule Mirage.MixProject do
use Mix.Project
@version "0.25.0"
@version "0.26.0"
def project do
[

Loading…
Cancel
Save