5 Commits

  1. 15
      CHANGELOG.md
  2. 12
      assets/css/app.scss
  3. 24
      lib/mirage/notes.ex
  4. 10
      lib/mirage_web/controllers/user_controller.ex
  5. 1
      lib/mirage_web/templates/shared/user_menu.html.eex
  6. 1
      lib/mirage_web/templates/topic/show.html.eex
  7. 28
      lib/mirage_web/templates/user/index.html.eex
  8. 2
      mix.exs
  9. 13
      test/mirage_web/controllers/note_controller_test.exs
  10. 18
      test/mirage_web/live/show_note_live_test.exs
  11. 18
      test/support/fixtures/note_fixtures.ex

15
CHANGELOG.md

@ -5,6 +5,21 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.25.0](https://git.inhji.de/inhji/mirage/compare/v0.24.0...v0.25.0) (2021-02-13)
### Features:
* list last edited and unlinked notes
* add card styles
### Bug Fixes:
* clean up
## [v0.24.0](https://git.inhji.de/inhji/mirage/compare/v0.23.0...v0.24.0) (2021-02-13)

12
assets/css/app.scss

@ -281,6 +281,18 @@ kbd {
}
.card {
border: 1px solid $border-base;
border-radius: 2px;
margin-right: 1rem;
padding: 0.5rem;
text-decoration: none;
&:last-child {
margin-right: 0;
}
}
/* === Forms === */
form {

24
lib/mirage/notes.ex

@ -28,6 +28,30 @@ defmodule Mirage.Notes do
|> Repo.preload(@note_preloads)
end
def list_notes(:last_edited) do
Note
|> limit(3)
|> order_by(desc: :updated_at)
|> Repo.all()
|> Repo.preload(@note_preloads)
end
def list_notes(:unlinked) do
q =
from n in Note,
full_join: nn in NoteNote,
on: nn.target_id == n.id or nn.source_id == n.id,
where: not like(n.title, "@%"),
where: is_nil(nn.target_id) or is_nil(nn.source_id),
select: n,
limit: 3,
preload: ^@note_preloads
q
|> Repo.all()
|> Repo.preload(@note_preloads)
end
@doc """
Gets a single note.

10
lib/mirage_web/controllers/user_controller.ex

@ -2,6 +2,14 @@ defmodule MirageWeb.UserController do
use MirageWeb, :controller
def index(conn, _params) do
render(conn, "index.html")
last_edited = Mirage.Notes.list_notes(:last_edited)
unlinked = Mirage.Notes.list_notes(:unlinked)
render(conn, "index.html",
notes: %{
last_edited: last_edited,
unlinked: unlinked
}
)
end
end

1
lib/mirage_web/templates/shared/user_menu.html.eex

@ -1,6 +1,5 @@
<aside class="menu">
<ul>
<li><%= link "User", to: Routes.user_path(@conn, :index) %></li>
<li><%= link "Settings", to: Routes.setting_path(@conn, :index) %></li>
</ul>
</aside>

1
lib/mirage_web/templates/topic/show.html.eex

@ -3,7 +3,6 @@
</section>
<section>
<% IO.inspect @topic %>
<%= for note <- @topic.notes do %>
<%= render MirageWeb.NoteView, "_note.html", assigns |> Map.put(:note, note) %>
<% end %>

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

@ -1,11 +1,33 @@
<%= render MirageWeb.SharedView, "user_menu.html", assigns %>
<div class="hero">
<h1>User</h1>
<h1>Hi <%= @current_user.email %></h1>
</div>
<section>
<p>hello world!</p>
<section class="bg-content width-full">
<h3>Last Edited</h3>
<div class="grid">
<%= for note <- @notes.last_edited 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>Unlinked</h3>
<div class="grid">
<%= for note <- @notes.unlinked 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">

2
mix.exs

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

13
test/mirage_web/controllers/note_controller_test.exs

@ -1,7 +1,6 @@
defmodule MirageWeb.NoteControllerTest do
use MirageWeb.ConnCase
alias Mirage.Notes
import Mirage.NoteFixtures
setup :register_and_log_in_user
@ -12,11 +11,6 @@ defmodule MirageWeb.NoteControllerTest do
}
@invalid_attrs %{content: nil}
def fixture(:note) do
{:ok, note} = Notes.create_note(@create_attrs)
note
end
describe "index" do
test "lists all notes", %{conn: conn} do
conn = get(conn, Routes.note_path(conn, :index))
@ -94,9 +88,4 @@ defmodule MirageWeb.NoteControllerTest do
end
end
end
defp create_note(_) do
note = fixture(:note)
%{note: note}
end
end

18
test/mirage_web/live/show_note_live_test.exs

@ -0,0 +1,18 @@
defmodule MirageWeb.ShowNoteLiveTest do
use MirageWeb.ConnCase
import Phoenix.LiveViewTest
import Mirage.NoteFixtures
describe "show note" do
setup [:create_note]
test "disconnected and connected render", %{conn: conn, note: note} do
{:ok, page_live, disconnected_html} = live(conn, "/notes/#{note.id}")
assert disconnected_html =~ note.title
assert disconnected_html =~ note.content
assert render(page_live) =~ note.title
assert render(page_live) =~ note.content
end
end
end

18
test/support/fixtures/note_fixtures.ex

@ -0,0 +1,18 @@
defmodule Mirage.NoteFixtures do
@moduledoc """
This module defines test helpers for creating
entities via the `Mirage.Notes` context.
"""
@create_attrs %{content: "some content", title: "some title", topic_string: "some tag"}
def fixture(:note) do
{:ok, note} = Mirage.Notes.create_note(@create_attrs)
note
end
def create_note(_) do
note = fixture(:note)
%{note: note}
end
end
Loading…
Cancel
Save