Compare commits

...

6 Commits

  1. 15
      CHANGELOG.md
  2. 22
      lib/mirage/links/link.ex
  3. 6
      lib/mirage_web/live/link_live/form_component.html.leex
  4. 4
      lib/mirage_web/live/link_live/index.html.leex
  5. 18
      lib/mirage_web/live/link_live/show.html.leex
  6. 3
      lib/mirage_web/live/show_note_live.ex
  7. 2
      mix.exs
  8. 2
      mix.lock
  9. 10
      priv/repo/migrations/20210215182411_add_notes_links_join_table.exs
  10. 11
      priv/repo/migrations/20210215183316_migrate_links_to_join_table.exs
  11. 9
      priv/repo/migrations/20210215193839_add_domain_to_link.exs

15
CHANGELOG.md

@ -5,6 +5,21 @@ See [Conventional Commits](Https://conventionalcommits.org) for commit guideline
<!-- changelog -->
## [v0.37.0](https://git.inhji.de/inhji/mirage/compare/v0.36.3...v0.37.0) (2021-02-15)
### Features:
* prettier link pages
* add domain to link
### Bug Fixes:
* remove unused vars
## [v0.36.3](https://git.inhji.de/inhji/mirage/compare/v0.36.2...v0.36.3) (2021-02-15)

22
lib/mirage/links/link.ex

@ -6,6 +6,7 @@ defmodule Mirage.Links.Link do
schema "links" do
field :title, :string
field :url, :string
field :domain, :string
many_to_many :note, Note, join_through: "notes_links"
end
@ -13,7 +14,26 @@ defmodule Mirage.Links.Link do
@doc false
def changeset(link, attrs) do
link
|> cast(attrs, [:title, :url])
|> cast(attrs, [:title, :url, :domain])
|> validate_required([:url])
|> maybe_extract_domain()
end
defp maybe_extract_domain(changeset) do
case get_change(changeset, :url) do
nil ->
changeset
url ->
changeset
|> put_change(:url, String.trim(url))
|> put_change(:domain, do_extract_domain(url))
end
end
defp do_extract_domain(url) do
url
|> URI.parse()
|> Map.get(:host)
end
end

6
lib/mirage_web/live/link_live/form_component.html.leex

@ -19,9 +19,9 @@
</fieldset>
<fieldset>
<%= label f, :note_id %>
<%= text_input f, :note_id, readonly: true %>
<%= error_tag f, :note_id %>
<%= label f, :domain %>
<%= text_input f, :domain, readonly: true %>
<%= error_tag f, :domain %>
</fieldset>
<%= submit "Save", phx_disable_with: "Saving..." %>

4
lib/mirage_web/live/link_live/index.html.leex

@ -13,11 +13,9 @@
<section class="bg-content width-full grid cards wrap">
<%= for link <- @notes_links do %>
<%= live_redirect to: Routes.link_show_path(@socket, :show, link), class: "col card", id: "link-#{link.id}" do %>
<strong><%= link.title %></strong>
<p><%= link.url %></p>
<p><%= link.domain || link.url %></p>
<% end %>
<% end %>
</section>

18
lib/mirage_web/live/link_live/show.html.leex

@ -1,5 +1,5 @@
<header class="hero">
<h1>Show Note link</h1>
<h1><%= @link.title || @link.url %></h1>
</header>
<%= if @live_action in [:edit] do %>
@ -11,19 +11,9 @@
return_to: Routes.link_show_path(@socket, :show, @link) %>
<% end %>
<ul>
<li>
<strong>Title:</strong>
<%= @link.title %>
</li>
<li>
<strong>Url:</strong>
<%= @link.url %>
</li>
</ul>
<p>
<%= link @link.url, to: @link.url, target: "_blank" %>
</p>
<div class="buttons">
<%= live_patch "Edit", to: Routes.link_show_path(@socket, :edit, @link), class: "button", class: "button" %>

3
lib/mirage_web/live/show_note_live.ex

@ -2,7 +2,6 @@ defmodule MirageWeb.ShowNoteLive do
use MirageWeb, :live_view
alias Mirage.Notes
alias Mirage.Notes.NoteLink
alias Mirage.Links
alias Mirage.Links.Link
@ -40,7 +39,7 @@ defmodule MirageWeb.ShowNoteLive do
note_id = socket.assigns.note.id
with {:ok, link} <- Links.create_link(link),
{:ok, note_link} <- Notes.create_note_link(%{link_id: link.id, note_id: note_id}) do
{:ok, _note_link} <- Notes.create_note_link(%{link_id: link.id, note_id: note_id}) do
note =
note_id
|> Notes.get_note!()

2
mix.exs

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

2
mix.lock

@ -13,7 +13,7 @@
"earmark": {:hex, :earmark, "1.4.13", "2c6ce9768fc9fdbf4046f457e207df6360ee6c91ee1ecb8e9a139f96a4289d91", [:mix], [{:earmark_parser, ">= 1.4.12", [hex: :earmark_parser, repo: "hexpm", optional: false]}], "hexpm", "a0cf3ed88ef2b1964df408889b5ecb886d1a048edde53497fc935ccd15af3403"},
"earmark_parser": {:hex, :earmark_parser, "1.4.12", "b245e875ec0a311a342320da0551da407d9d2b65d98f7a9597ae078615af3449", [:mix], [], "hexpm", "711e2cc4d64abb7d566d43f54b78f7dc129308a63bc103fbd88550d2174b3160"},
"ecto": {:hex, :ecto, "3.5.7", "f440a476bf1be361173a43a4a18f04a2fdf4e6fac5b0457f03d8686e55f13f7e", [:mix], [{:decimal, "~> 1.6 or ~> 2.0", [hex: :decimal, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "04c4e69d4f1cc2bb085aa760d50389ba8ae3003f80c112fbde87d57f5ed75d39"},
"ecto_psql_extras": {:hex, :ecto_psql_extras, "0.6.2", "ff964dcfd80ee285797025734484742faa04b56c2674380014e7233851c5f8b2", [:mix], [{:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.15.7", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "7e7f88140f14a8aed4b82269aece28498086edd032cd94fac7d05059f9b09c7e"},
"ecto_psql_extras": {:hex, :ecto_psql_extras, "0.6.3", "2cc855c07144791e3dcab088b59057ea1675efe6f54e9e9c7d4a0cc87d5ae582", [:mix], [{:ecto_sql, "~> 3.4", [hex: :ecto_sql, repo: "hexpm", optional: false]}, {:postgrex, ">= 0.15.7", [hex: :postgrex, repo: "hexpm", optional: false]}, {:table_rex, "~> 3.0.0", [hex: :table_rex, repo: "hexpm", optional: false]}], "hexpm", "dd4914205ea0c5588639d7237abee9b0247b8ab38fa1930a205a5659483744b3"},
"ecto_sql": {:hex, :ecto_sql, "3.5.4", "a9e292c40bd79fff88885f95f1ecd7b2516e09aa99c7dd0201aa84c54d2358e4", [:mix], [{:db_connection, "~> 2.2", [hex: :db_connection, repo: "hexpm", optional: false]}, {:ecto, "~> 3.5.0", [hex: :ecto, repo: "hexpm", optional: false]}, {:myxql, "~> 0.3.0 or ~> 0.4.0", [hex: :myxql, repo: "hexpm", optional: true]}, {:postgrex, "~> 0.15.0 or ~> 1.0", [hex: :postgrex, repo: "hexpm", optional: true]}, {:tds, "~> 2.1.1", [hex: :tds, repo: "hexpm", optional: true]}, {:telemetry, "~> 0.4.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "1fff1a28a898d7bbef263f1f3ea425b04ba9f33816d843238c84eff883347343"},
"elixir_make": {:hex, :elixir_make, "0.6.2", "7dffacd77dec4c37b39af867cedaabb0b59f6a871f89722c25b28fcd4bd70530", [:mix], [], "hexpm", "03e49eadda22526a7e5279d53321d1cced6552f344ba4e03e619063de75348d9"},
"file_system": {:hex, :file_system, "0.2.10", "fb082005a9cd1711c05b5248710f8826b02d7d1784e7c3451f9c1231d4fc162d", [:mix], [], "hexpm", "41195edbfb562a593726eda3b3e8b103a309b733ad25f3d642ba49696bf715dc"},

10
priv/repo/migrations/20210215182411_add_notes_links_join_table.exs

@ -2,11 +2,11 @@ defmodule Mirage.Repo.Migrations.AddNotesLinksJoinTable do
use Ecto.Migration
def change do
rename table(:notes_links), to: table(:links)
rename table(:notes_links), to: table(:links)
create table(:notes_links) do
add :note_id, references(:notes, on_delete: :delete_all)
add :link_id, references(:links, on_delete: :delete_all)
end
create table(:notes_links) do
add :note_id, references(:notes, on_delete: :delete_all)
add :link_id, references(:links, on_delete: :delete_all)
end
end
end

11
priv/repo/migrations/20210215183316_migrate_links_to_join_table.exs

@ -3,17 +3,18 @@ defmodule Mirage.Repo.Migrations.MigrateLinksToJoinTable do
import Ecto.Query
def change do
execute(&link_join_up/0, &link_join_down/0)
execute(&link_join_up/0, &link_join_down/0)
end
def link_join_up() do
links = repo().all(from l in Mirage.Links.Link)
|> Enum.map(fn l -> %{note_id: l.note_id, link_id: l.id} end)
links =
repo().all(from(l in Mirage.Links.Link))
|> Enum.map(fn l -> %{note_id: l.note_id, link_id: l.id} end)
repo().insert_all("notes_links", links)
repo().insert_all("notes_links", links)
end
def link_join_down() do
repo().query!("DELETE FROM notes_links")
repo().query!("DELETE FROM notes_links")
end
end

9
priv/repo/migrations/20210215193839_add_domain_to_link.exs

@ -0,0 +1,9 @@
defmodule Mirage.Repo.Migrations.AddDomainToLink do
use Ecto.Migration
def change do
alter table(:links) do
add :domain, :string
end
end
end
Loading…
Cancel
Save