Add autoren and artikel for public viewing
This commit is contained in:
21
lib/outlook/artikel.ex
Normal file
21
lib/outlook/artikel.ex
Normal file
@ -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
|
||||
34
lib/outlook/autoren.ex
Normal file
34
lib/outlook/autoren.ex
Normal file
@ -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
|
||||
15
lib/outlook_web/controllers/artikel_controller.ex
Normal file
15
lib/outlook_web/controllers/artikel_controller.ex
Normal file
@ -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
|
||||
5
lib/outlook_web/controllers/artikel_html.ex
Normal file
5
lib/outlook_web/controllers/artikel_html.ex
Normal file
@ -0,0 +1,5 @@
|
||||
defmodule OutlookWeb.ArtikelHTML do
|
||||
use OutlookWeb, :html
|
||||
|
||||
embed_templates "artikel_html/*"
|
||||
end
|
||||
19
lib/outlook_web/controllers/artikel_html/index.html.heex
Normal file
19
lib/outlook_web/controllers/artikel_html/index.html.heex
Normal file
@ -0,0 +1,19 @@
|
||||
<.header>
|
||||
Listing Artikel
|
||||
<:actions>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.table id="artikel" rows={@artikel} row_click={&JS.navigate(~p"/artikel/#{&1}")}>
|
||||
<:col :let={artikel} label="Title"><%= artikel.title %></:col>
|
||||
<:col :let={artikel} label="Teaser"><%= artikel.teaser %></:col>
|
||||
<%!-- <:col :let={artikel} label="Translator"><%= artikel.translator %></:col> --%>
|
||||
<:col :let={artikel} label="Unauthorized"><%= artikel.unauthorized %></:col>
|
||||
<:col :let={artikel} label="Public content"><%= artikel.public_content %></:col>
|
||||
<:col :let={artikel} label="Date"><%= Calendar.strftime(artikel.date, "%d.%m.%Y") %></:col>
|
||||
<:action :let={artikel}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/artikel/#{artikel}"}>Show</.link>
|
||||
</div>
|
||||
</:action>
|
||||
</.table>
|
||||
19
lib/outlook_web/controllers/artikel_html/show.html.heex
Normal file
19
lib/outlook_web/controllers/artikel_html/show.html.heex
Normal file
@ -0,0 +1,19 @@
|
||||
<.header>
|
||||
<%= @artikel.title %>
|
||||
<:subtitle><%= @artikel.article.author.name %></:subtitle>
|
||||
<:actions>
|
||||
<.link href={@artikel.article.url} >
|
||||
<%= @artikel.article.title %>
|
||||
</.link> <%= Calendar.strftime(@artikel.article.date, "%d.%m.%Y") %>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.list>
|
||||
<:item title="Title"><%= @artikel.title %></:item>
|
||||
<%!-- <:item title="Translator"><%= @artikel.translator %></:item> --%>
|
||||
<:item title="Unauthorized"><%= @artikel.unauthorized %></:item>
|
||||
<:item title="Date"><%= Calendar.strftime(@artikel.date, "%d.%m.%Y") %></:item>
|
||||
</.list>
|
||||
<div class="article"><%= @artikel.public_content |> raw %></div>
|
||||
|
||||
<.back navigate={~p"/autoren/#{@artikel.article.author}"}>Back to Autor</.back>
|
||||
16
lib/outlook_web/controllers/autor_controller.ex
Normal file
16
lib/outlook_web/controllers/autor_controller.ex
Normal file
@ -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
|
||||
5
lib/outlook_web/controllers/autor_html.ex
Normal file
5
lib/outlook_web/controllers/autor_html.ex
Normal file
@ -0,0 +1,5 @@
|
||||
defmodule OutlookWeb.AutorHTML do
|
||||
use OutlookWeb, :html
|
||||
|
||||
embed_templates "autor_html/*"
|
||||
end
|
||||
20
lib/outlook_web/controllers/autor_html/index.html.heex
Normal file
20
lib/outlook_web/controllers/autor_html/index.html.heex
Normal file
@ -0,0 +1,20 @@
|
||||
<.header>
|
||||
Listing Autoren
|
||||
<:actions>
|
||||
<.link href={~p"/autoren/new"}>
|
||||
<.button>New Autor</.button>
|
||||
</.link>
|
||||
</:actions>
|
||||
</.header>
|
||||
|
||||
<.table id="autoren" rows={@autoren} row_click={&JS.navigate(~p"/autoren/#{&1}")}>
|
||||
<:col :let={autor} label="Name"><%= autor.name %></:col>
|
||||
<:col :let={autor} label="Description"><%= autor.description %></:col>
|
||||
<:col :let={autor} label="Homepage name"><%= autor.homepage_name %></:col>
|
||||
<:col :let={autor} label="Homepage url"><%= autor.homepage_url %></:col>
|
||||
<:action :let={autor}>
|
||||
<div class="sr-only">
|
||||
<.link navigate={~p"/autoren/#{autor}"}>Show</.link>
|
||||
</div>
|
||||
</:action>
|
||||
</.table>
|
||||
16
lib/outlook_web/controllers/autor_html/show.html.heex
Normal file
16
lib/outlook_web/controllers/autor_html/show.html.heex
Normal file
@ -0,0 +1,16 @@
|
||||
<.header>
|
||||
<%= @autor.name %>
|
||||
<:subtitle><div class="text-lg mb-2"><%= @autor.description %></div></:subtitle>
|
||||
<:subtitle><.link href={@autor.homepage_url}><%= @autor.homepage_name %></.link></:subtitle>
|
||||
</.header>
|
||||
|
||||
|
||||
|
||||
<%= for article <- @autor.articles do %>
|
||||
<div :for={translation <- article.translations} class="my-2 px-2 rounded border-2 border-solid border-gray-300">
|
||||
<.link navigate={~p"/artikel/#{translation}"}><h4 class="font-bold py-2"><%= translation.title %></h4></.link>
|
||||
<div><%= translation.teaser %></div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<.back navigate={~p"/autoren"}>Back to autoren</.back>
|
||||
@ -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
|
||||
|
||||
Reference in New Issue
Block a user