4 Commits

  1. 9
      CHANGELOG.md
  2. 10
      assets/css/app.scss
  3. 4
      lib/mirage/markdown.ex
  4. 4
      lib/mirage/notes.ex
  5. 3
      lib/mirage_web/templates/layout/_header.html.eex
  6. 38
      lib/mirage_web/templates/topic/index.html.eex
  7. 12
      lib/mirage_web/templates/topic/show.html.eex
  8. 2
      mix.exs
  9. 6
      test/mirage/notes_test.exs
  10. 4
      test/mirage_web/controllers/topic_controller_test.exs

9
CHANGELOG.md

@ -5,6 +5,15 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.18.0](https://git.inhji.de/inhji/mirage/compare/v0.17.0...v0.18.0) (2021-02-07)
### Features:
* add topics link, style topic pages
## [v0.17.0](https://git.inhji.de/inhji/mirage/compare/v0.16.0...v0.17.0) (2021-02-07)

10
assets/css/app.scss

@ -207,9 +207,19 @@ kbd {
padding: 0 0.3rem;
border-radius: 5px;
border: 1px solid $border-base;
margin-right: 5px;
a { text-decoration: none; }
}
@for $i from 1 through 30 {
.tag.count-#{$i} {
font-size: 100% + percentage(($i*5) / 100);
}
}
}
/* === Forms === */
form {

4
lib/mirage/markdown.ex

@ -32,7 +32,7 @@ defmodule Mirage.Markdown do
end
def replace_with_link([note_id, title], markdown) do
case Mirage.Notes.get_note(note_id) do
case Mirage.Notes.get_note(note_id) do
nil ->
markdown
@ -52,6 +52,6 @@ defmodule Mirage.Markdown do
end
def get_link(id, title) do
link(title, to: "/notes/#{id}") |> safe_to_string()
link(title, to: "/notes/#{id}") |> safe_to_string()
end
end

4
lib/mirage/notes.ex

@ -9,6 +9,7 @@ defmodule Mirage.Notes do
alias Mirage.Notes.{Note, Topic}
@note_preloads [:links, :topics]
@topic_preloads [:notes]
@doc """
Returns the list of notes.
@ -123,6 +124,7 @@ defmodule Mirage.Notes do
"""
def list_topics do
Repo.all(Topic)
|> Repo.preload(@topic_preloads)
end
@doc """
@ -141,6 +143,8 @@ defmodule Mirage.Notes do
"""
def get_topic!(id), do: Repo.get!(Topic, id)
def preload_topic(topic), do: Repo.preload(topic, @topic_preloads)
@doc """
Creates a topic.

3
lib/mirage_web/templates/layout/_header.html.eex

@ -7,6 +7,9 @@
<li>
<a href="/notes">Notes</a>
</li>
<li>
<a href="/topics">Topics</a>
</li>
<li class="spacer"></li>
<%= render "_user_menu.html", assigns %>
</ul>

38
lib/mirage_web/templates/topic/index.html.eex

@ -1,26 +1,14 @@
<h1>Listing Note topics</h1>
<div class="hero">
<h1>Listing Topics</h1>
</div>
<div class="tags width-full bg-content">
<%= for topic <- @topics do %>
<span class="tag count-<%= Enum.count(topic.notes) %>">
<%= link to: Routes.topic_path(@conn, :show, topic) do %>
<%= topic.text %> (<%= Enum.count(topic.notes) %>)
<% end %>
</span>
<% end %>
</div>
<table>
<thead>
<tr>
<th>Text</th>
<th></th>
</tr>
</thead>
<tbody>
<%= for topic <- @topics do %>
<tr>
<td><%= topic.text %></td>
<td>
<span><%= link "Show", to: Routes.topic_path(@conn, :show, topic) %></span>
<span><%= link "Edit", to: Routes.topic_path(@conn, :edit, topic) %></span>
<span><%= link "Delete", to: Routes.topic_path(@conn, :delete, topic), method: :delete, data: [confirm: "Are you sure?"] %></span>
</td>
</tr>
<% end %>
</tbody>
</table>
<span><%= link "New Note topic", to: Routes.topic_path(@conn, :new) %></span>

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

@ -1,13 +1,7 @@
<h1>Show Note topic</h1>
<div class="hero">
<h1>Topic <%= @topic.text %></h1>
</div>
<ul>
<li>
<strong>Text:</strong>
<%= @topic.text %>
</li>
</ul>
<span><%= link "Edit", to: Routes.topic_path(@conn, :edit, @topic) %></span>
<span><%= link "Back", to: Routes.topic_path(@conn, :index) %></span>

2
mix.exs

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

6
test/mirage/notes_test.exs

@ -83,7 +83,9 @@ defmodule Mirage.NotesTest do
assert {:ok, %Note{} = note} = Notes.update_note(note, attrs)
assert note.content ==
"some updated content with a reference [[#{note.id}|Link to myself]] [[#{note.id + 1}]]"
"some updated content with a reference [[#{note.id}|Link to myself]] [[#{
note.id + 1
}]]"
assert note.content_html =~ "Link to myself"
end
@ -123,7 +125,7 @@ defmodule Mirage.NotesTest do
end
test "list_topics/0 returns all topics" do
topic = topic_fixture()
topic = topic_fixture() |> Notes.preload_topic()
assert Notes.list_topics() == [topic]
end

4
test/mirage_web/controllers/topic_controller_test.exs

@ -17,7 +17,7 @@ defmodule MirageWeb.TopicControllerTest do
describe "index" do
test "lists all topics", %{conn: conn} do
conn = get(conn, Routes.topic_path(conn, :index))
assert html_response(conn, 200) =~ "Listing Note topics"
assert html_response(conn, 200) =~ "Listing Topics"
end
end
@ -36,7 +36,7 @@ defmodule MirageWeb.TopicControllerTest do
assert redirected_to(conn) == Routes.topic_path(conn, :show, id)
conn = get(conn, Routes.topic_path(conn, :show, id))
assert html_response(conn, 200) =~ "Show Note topic"
assert html_response(conn, 200) =~ "Topic some text"
end
test "renders errors when data is invalid", %{conn: conn} do

Loading…
Cancel
Save