Browse Source

clean up notes, order by inserted, improve templates

main
Inhji Y. 10 months ago
parent
commit
4824437faa
  1. 5
      lib/mirage/notes.ex
  2. 5
      lib/mirage_web/templates/note/_note_meta.html.eex
  3. 29
      lib/mirage_web/templates/note/index.html.eex
  4. 23
      lib/mirage_web/templates/note/show.html.eex
  5. 2
      test/mirage_web/controllers/note_controller_test.exs
  6. 4
      test/mirage_web/live/page_live_test.exs

5
lib/mirage/notes.ex

@ -18,7 +18,10 @@ defmodule Mirage.Notes do
"""
def list_notes do
Repo.all(Note)
Note
|> limit(10)
|> order_by(desc: :inserted_at)
|> Repo.all()
end
@doc """

5
lib/mirage_web/templates/note/_note_meta.html.eex

@ -0,0 +1,5 @@
<aside>
<%= link to: Routes.note_path(@conn, :show, @note) do %>
<time datetime="<%= @note.inserted_at %>"><%= @note.inserted_at %></time>
<% end %>
</aside>

29
lib/mirage_web/templates/note/index.html.eex

@ -1,26 +1,15 @@
<h1>Listing Notes</h1>
<table>
<thead>
<tr>
<th>Content</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for note <- @notes do %>
<tr>
<td><%= note.content %></td>
<article>
<p><%= note.content %></p>
<%= render "_note_meta.html", conn: @conn, note: note %>
</article>
<td>
<span><%= link "Show", to: Routes.note_path(@conn, :show, note) %></span>
<span><%= link "Edit", to: Routes.note_path(@conn, :edit, note) %></span>
<span><%= link "Delete", to: Routes.note_path(@conn, :delete, note), method: :delete, data: [confirm: "Are you sure?"] %></span>
</td>
</tr>
<hr>
<% end %>
</tbody>
</table>
<span><%= link "New Note", to: Routes.note_path(@conn, :new) %></span>
<%= if @current_user do %>
<span><%= link "New Note", to: Routes.note_path(@conn, :new) %></span>
<% end %>

23
lib/mirage_web/templates/note/show.html.eex

@ -1,13 +1,14 @@
<h1>Show Note</h1>
<ul>
<li>
<strong>Content:</strong>
<%= @note.content %>
</li>
</ul>
<span><%= link "Edit", to: Routes.note_path(@conn, :edit, @note) %></span>
<span><%= link "Back", to: Routes.note_path(@conn, :index) %></span>
<article>
<p><%= @note.content %></p>
<%= render "_note_meta.html", conn: @conn, note: @note %>
</article>
<hr>
<%= if @current_user do %>
<span><%= link "Edit", to: Routes.note_path(@conn, :edit, @note) %></span>
<span><%= link "Back", to: Routes.note_path(@conn, :index) %></span>
<span><%= link "Delete", to: Routes.note_path(@conn, :delete, @note), method: :delete, data: [confirm: "Are you sure?"] %></span>
<% end %>

2
test/mirage_web/controllers/note_controller_test.exs

@ -2,8 +2,6 @@ defmodule MirageWeb.NoteControllerTest do
use MirageWeb.ConnCase
alias Mirage.Notes
alias Mirage.Accounts
import Mirage.AccountsFixtures
setup :register_and_log_in_user

4
test/mirage_web/live/page_live_test.exs

@ -5,7 +5,7 @@ defmodule MirageWeb.PageLiveTest do
test "disconnected and connected render", %{conn: conn} do
{:ok, page_live, disconnected_html} = live(conn, "/")
assert disconnected_html =~ "Welcome to Phoenix!"
assert render(page_live) =~ "Welcome to Phoenix!"
assert disconnected_html =~ "Hello my name is Inhji!"
assert render(page_live) =~ "Hello my name is Inhji!"
end
end

Loading…
Cancel
Save