mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-27 21:47:59 +01:00
show forum list
This commit is contained in:
parent
d91346c9b1
commit
a22b397fc4
3 changed files with 29 additions and 0 deletions
24
lib/philomena_web/plugs/forum_list_plug.ex
Normal file
24
lib/philomena_web/plugs/forum_list_plug.ex
Normal file
|
@ -0,0 +1,24 @@
|
||||||
|
defmodule PhilomenaWeb.ForumListPlug do
|
||||||
|
alias Plug.Conn
|
||||||
|
|
||||||
|
alias Philomena.Forums.Forum
|
||||||
|
alias Philomena.Repo
|
||||||
|
alias Canada.Can
|
||||||
|
import Ecto.Query
|
||||||
|
|
||||||
|
def init(opts), do: opts
|
||||||
|
|
||||||
|
def call(conn, _opts) do
|
||||||
|
forums = lookup_visible_forums(conn.assigns.current_user)
|
||||||
|
|
||||||
|
conn
|
||||||
|
|> Conn.assign(:forums, forums)
|
||||||
|
end
|
||||||
|
|
||||||
|
# fixme: add caching!
|
||||||
|
defp lookup_visible_forums(user) do
|
||||||
|
Forum
|
||||||
|
|> Repo.all()
|
||||||
|
|> Enum.filter(&Can.can?(user, :show, &1))
|
||||||
|
end
|
||||||
|
end
|
|
@ -16,6 +16,7 @@ defmodule PhilomenaWeb.Router do
|
||||||
plug PhilomenaWeb.CurrentBanPlug
|
plug PhilomenaWeb.CurrentBanPlug
|
||||||
plug PhilomenaWeb.NotificationCountPlug
|
plug PhilomenaWeb.NotificationCountPlug
|
||||||
plug PhilomenaWeb.SiteNoticePlug
|
plug PhilomenaWeb.SiteNoticePlug
|
||||||
|
plug PhilomenaWeb.ForumListPlug
|
||||||
plug PhilomenaWeb.FilterSelectPlug
|
plug PhilomenaWeb.FilterSelectPlug
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,10 @@
|
||||||
span data-click-preventdefault="true"
|
span data-click-preventdefault="true"
|
||||||
i.fa.fa-caret-down<
|
i.fa.fa-caret-down<
|
||||||
.dropdown__content
|
.dropdown__content
|
||||||
|
= for forum <- @conn.assigns.forums do
|
||||||
|
a.header__link href=Routes.forum_path(@conn, :show, forum)
|
||||||
|
= forum.name
|
||||||
|
|
||||||
a.header__link href='/posts'
|
a.header__link href='/posts'
|
||||||
i.fa.fa-fw.fa-search>
|
i.fa.fa-fw.fa-search>
|
||||||
| Post Search
|
| Post Search
|
||||||
|
|
Loading…
Reference in a new issue