mirror of
https://github.com/philomena-dev/philomena.git
synced 2024-11-23 20:18:00 +01:00
read site notices
This commit is contained in:
parent
bd0711730e
commit
2f4ba6d96d
5 changed files with 43 additions and 3 deletions
|
@ -17,8 +17,13 @@ defmodule Philomena.SiteNotices do
|
|||
[%SiteNotice{}, ...]
|
||||
|
||||
"""
|
||||
def list_site_notices do
|
||||
Repo.all(SiteNotice)
|
||||
def active_site_notices do
|
||||
now = DateTime.utc_now()
|
||||
|
||||
SiteNotice
|
||||
|> where([n], n.start_date < ^now and n.finish_date > ^now)
|
||||
|> order_by(desc: :start_date)
|
||||
|> Repo.all()
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
|
|
@ -15,7 +15,7 @@ defmodule Philomena.SiteNotices.SiteNotice do
|
|||
field :start_date, :naive_datetime
|
||||
field :finish_date, :naive_datetime
|
||||
|
||||
timestamps(inserted_at: :created_At)
|
||||
timestamps(inserted_at: :created_at)
|
||||
end
|
||||
|
||||
@doc false
|
||||
|
|
25
lib/philomena_web/plugs/site_notice_plug.ex
Normal file
25
lib/philomena_web/plugs/site_notice_plug.ex
Normal file
|
@ -0,0 +1,25 @@
|
|||
defmodule PhilomenaWeb.SiteNoticePlug do
|
||||
@moduledoc """
|
||||
This plug stores the current site-wide notices.
|
||||
|
||||
## Example
|
||||
|
||||
plug PhilomenaWeb.SiteNoticePlug
|
||||
"""
|
||||
|
||||
alias Plug.Conn
|
||||
alias Philomena.SiteNotices
|
||||
|
||||
@doc false
|
||||
@spec init(any()) :: any()
|
||||
def init(opts), do: opts
|
||||
|
||||
@doc false
|
||||
@spec call(Plug.Conn.t(), any()) :: Plug.Conn.t()
|
||||
def call(conn, _opts) do
|
||||
notices = SiteNotices.active_site_notices()
|
||||
|
||||
conn
|
||||
|> Conn.assign(:site_notices, notices)
|
||||
end
|
||||
end
|
|
@ -15,6 +15,7 @@ defmodule PhilomenaWeb.Router do
|
|||
plug PhilomenaWeb.EnsureUserEnabledPlug
|
||||
plug PhilomenaWeb.CurrentBanPlug
|
||||
plug PhilomenaWeb.NotificationCountPlug
|
||||
plug PhilomenaWeb.SiteNoticePlug
|
||||
plug PhilomenaWeb.FilterSelectPlug
|
||||
end
|
||||
|
||||
|
|
|
@ -1,3 +1,12 @@
|
|||
= for notice <- @conn.assigns.site_notices do
|
||||
.flash.flash--site-notice
|
||||
strong>
|
||||
= notice.title
|
||||
=> notice.text
|
||||
= if notice.link not in [nil, ""] do
|
||||
a href=notice.link
|
||||
= notice.link_text
|
||||
|
||||
noscript.flash.flash--warning
|
||||
strong You don't appear to have Javascript enabled
|
||||
' If you're using an add-on like NoScript, please allow
|
||||
|
|
Loading…
Reference in a new issue