diff --git a/config/dev.exs b/config/dev.exs index ffc8d46..c08a744 100644 --- a/config/dev.exs +++ b/config/dev.exs @@ -58,8 +58,8 @@ config :outlook, OutlookWeb.Endpoint, patterns: [ ~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$", ~r"priv/gettext/.*(po)$", - ~r"lib/outlook_web/(live|views|components)/.*(ex)$", - ~r"lib/outlook_web/templates/.*(eex)$" + ~r"lib/outlook_web/(live|controllers|components)/.*(ex)$", + ~r"lib/outlook_web/controllers/.*/.*(eex)$" ] ] diff --git a/lib/outlook/artikel.ex b/lib/outlook/artikel.ex new file mode 100644 index 0000000..bc842c8 --- /dev/null +++ b/lib/outlook/artikel.ex @@ -0,0 +1,21 @@ +defmodule Outlook.Artikel do + @moduledoc """ + The Artikel context. + """ + + alias Outlook.Translations.Translation + + import Ecto.Query, warn: false + alias Outlook.Repo + + def list_artikel do + Repo.all(from t in Translation, where: t.public == true) + |> Repo.preload([article: :author]) + end + + def get_artikel!(artikel) when is_struct(artikel), do: get_artikel!(artikel.id) + def get_artikel!(id) do + Repo.one(from t in Translation, where: t.id == ^id and t.public == true) + |> Repo.preload([article: :author]) + end +end diff --git a/lib/outlook/autoren.ex b/lib/outlook/autoren.ex new file mode 100644 index 0000000..f73ced7 --- /dev/null +++ b/lib/outlook/autoren.ex @@ -0,0 +1,34 @@ +defmodule Outlook.Autoren do + @moduledoc """ + The Autoren context. + """ + + import Ecto.Query, warn: false + alias Outlook.Repo + + alias Outlook.Articles.Article + alias Outlook.Translations.Translation + + alias Outlook.Authors.Author + + def list_autoren do + Repo.all(Author) + end + + def get_autor!(id) do + Repo.get!(Author, id) + |> Repo.preload([articles: [:translations]]) + end + + @doc "This is ugly" + def list_artikel(author) when is_struct(author), do: list_artikel(author.id) + def list_artikel(author_id) do + aids = Repo.all(from a in Article, + select: [:id], + where: a.author_id == ^author_id) + |> Enum.map(fn a -> a.id end) + Repo.all(from t in Translation, + select: [t.title, t.teaser, t.date, t.user_id], + where: t.article_id in ^aids and t.public == true) + end +end diff --git a/lib/outlook_web/controllers/artikel_controller.ex b/lib/outlook_web/controllers/artikel_controller.ex new file mode 100644 index 0000000..d3bd091 --- /dev/null +++ b/lib/outlook_web/controllers/artikel_controller.ex @@ -0,0 +1,15 @@ +defmodule OutlookWeb.ArtikelController do + use OutlookWeb, :controller + + alias Outlook.Artikel + + def index(conn, _params) do + artikel = Artikel.list_artikel() + render(conn, :index, artikel: artikel) + end + + def show(conn, %{"id" => id}) do + artikel = Artikel.get_artikel!(id) + render(conn, :show, artikel: artikel) + end +end diff --git a/lib/outlook_web/controllers/artikel_html.ex b/lib/outlook_web/controllers/artikel_html.ex new file mode 100644 index 0000000..1d0b594 --- /dev/null +++ b/lib/outlook_web/controllers/artikel_html.ex @@ -0,0 +1,5 @@ +defmodule OutlookWeb.ArtikelHTML do + use OutlookWeb, :html + + embed_templates "artikel_html/*" +end diff --git a/lib/outlook_web/controllers/artikel_html/index.html.heex b/lib/outlook_web/controllers/artikel_html/index.html.heex new file mode 100644 index 0000000..611af4a --- /dev/null +++ b/lib/outlook_web/controllers/artikel_html/index.html.heex @@ -0,0 +1,19 @@ +<.header> + Listing Artikel + <:actions> + + + +<.table id="artikel" rows={@artikel} row_click={&JS.navigate(~p"/artikel/#{&1}")}> + <:col :let={artikel} label="Title"><%= artikel.title %> + <:col :let={artikel} label="Teaser"><%= artikel.teaser %> + <%!-- <:col :let={artikel} label="Translator"><%= artikel.translator %> --%> + <:col :let={artikel} label="Unauthorized"><%= artikel.unauthorized %> + <:col :let={artikel} label="Public content"><%= artikel.public_content %> + <:col :let={artikel} label="Date"><%= Calendar.strftime(artikel.date, "%d.%m.%Y") %> + <:action :let={artikel}> +
+ <.link navigate={~p"/artikel/#{artikel}"}>Show +
+ + diff --git a/lib/outlook_web/controllers/artikel_html/show.html.heex b/lib/outlook_web/controllers/artikel_html/show.html.heex new file mode 100644 index 0000000..ff50bfc --- /dev/null +++ b/lib/outlook_web/controllers/artikel_html/show.html.heex @@ -0,0 +1,19 @@ +<.header> + <%= @artikel.title %> + <:subtitle><%= @artikel.article.author.name %> + <:actions> + <.link href={@artikel.article.url} > + <%= @artikel.article.title %> + <%= Calendar.strftime(@artikel.article.date, "%d.%m.%Y") %> + + + +<.list> + <:item title="Title"><%= @artikel.title %> + <%!-- <:item title="Translator"><%= @artikel.translator %> --%> + <:item title="Unauthorized"><%= @artikel.unauthorized %> + <:item title="Date"><%= Calendar.strftime(@artikel.date, "%d.%m.%Y") %> + +
<%= @artikel.public_content |> raw %>
+ +<.back navigate={~p"/autoren/#{@artikel.article.author}"}>Back to Autor diff --git a/lib/outlook_web/controllers/autor_controller.ex b/lib/outlook_web/controllers/autor_controller.ex new file mode 100644 index 0000000..2c5177f --- /dev/null +++ b/lib/outlook_web/controllers/autor_controller.ex @@ -0,0 +1,16 @@ +defmodule OutlookWeb.AutorController do + use OutlookWeb, :controller + + alias Outlook.Autoren + + def index(conn, _params) do + autoren = Autoren.list_autoren() + render(conn, :index, autoren: autoren) + end + + def show(conn, %{"id" => id}) do + autor = Autoren.get_autor!(id) + # artikel = Autoren.list_artikel(autor) + render(conn, :show, autor: autor) + end +end diff --git a/lib/outlook_web/controllers/autor_html.ex b/lib/outlook_web/controllers/autor_html.ex new file mode 100644 index 0000000..dd7159d --- /dev/null +++ b/lib/outlook_web/controllers/autor_html.ex @@ -0,0 +1,5 @@ +defmodule OutlookWeb.AutorHTML do + use OutlookWeb, :html + + embed_templates "autor_html/*" +end diff --git a/lib/outlook_web/controllers/autor_html/index.html.heex b/lib/outlook_web/controllers/autor_html/index.html.heex new file mode 100644 index 0000000..2cabc63 --- /dev/null +++ b/lib/outlook_web/controllers/autor_html/index.html.heex @@ -0,0 +1,20 @@ +<.header> + Listing Autoren + <:actions> + <.link href={~p"/autoren/new"}> + <.button>New Autor + + + + +<.table id="autoren" rows={@autoren} row_click={&JS.navigate(~p"/autoren/#{&1}")}> + <:col :let={autor} label="Name"><%= autor.name %> + <:col :let={autor} label="Description"><%= autor.description %> + <:col :let={autor} label="Homepage name"><%= autor.homepage_name %> + <:col :let={autor} label="Homepage url"><%= autor.homepage_url %> + <:action :let={autor}> +
+ <.link navigate={~p"/autoren/#{autor}"}>Show +
+ + diff --git a/lib/outlook_web/controllers/autor_html/show.html.heex b/lib/outlook_web/controllers/autor_html/show.html.heex new file mode 100644 index 0000000..ee6f30d --- /dev/null +++ b/lib/outlook_web/controllers/autor_html/show.html.heex @@ -0,0 +1,16 @@ +<.header> + <%= @autor.name %> + <:subtitle>
<%= @autor.description %>
+ <:subtitle><.link href={@autor.homepage_url}><%= @autor.homepage_name %> + + + + +<%= for article <- @autor.articles do %> +
+ <.link navigate={~p"/artikel/#{translation}"}>

<%= translation.title %>

+
<%= translation.teaser %>
+
+<% end %> + +<.back navigate={~p"/autoren"}>Back to autoren diff --git a/lib/outlook_web/router.ex b/lib/outlook_web/router.ex index d8fced0..c5a9424 100644 --- a/lib/outlook_web/router.ex +++ b/lib/outlook_web/router.ex @@ -110,5 +110,8 @@ defmodule OutlookWeb.Router do live "/users/confirm/:token", UserConfirmationLive, :edit live "/users/confirm", UserConfirmationInstructionsLive, :new end + + resources "/autoren", AutorController, only: [:index, :show] + resources "/artikel", ArtikelController, only: [:index, :show] end end