2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.LayoutView do
|
|
|
|
use PlausibleWeb, :view
|
2019-09-11 19:04:37 +03:00
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
def base_domain do
|
|
|
|
PlausibleWeb.Endpoint.host()
|
|
|
|
end
|
|
|
|
|
|
|
|
def plausible_url do
|
2020-10-05 15:01:54 +03:00
|
|
|
PlausibleWeb.Endpoint.url()
|
2020-05-26 16:09:34 +03:00
|
|
|
end
|
|
|
|
|
2020-03-31 16:23:46 +03:00
|
|
|
def home_dest(conn) do
|
|
|
|
if conn.assigns[:current_user] do
|
|
|
|
"/sites"
|
|
|
|
else
|
|
|
|
"/"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-16 15:00:07 +03:00
|
|
|
def settings_tabs(conn) do
|
2020-11-20 12:57:33 +03:00
|
|
|
[
|
|
|
|
[key: "General", value: "general"],
|
2021-06-16 15:00:07 +03:00
|
|
|
[key: "People", value: "people"],
|
2020-11-20 12:57:33 +03:00
|
|
|
[key: "Visibility", value: "visibility"],
|
|
|
|
[key: "Goals", value: "goals"],
|
2023-06-22 10:00:07 +03:00
|
|
|
if Plausible.Funnels.enabled_for?(conn.assigns[:current_user]) do
|
|
|
|
[key: "Funnels", value: "funnels"]
|
|
|
|
end,
|
2020-11-20 12:57:33 +03:00
|
|
|
[key: "Search Console", value: "search-console"],
|
|
|
|
[key: "Email reports", value: "email-reports"],
|
2021-06-17 10:51:58 +03:00
|
|
|
if !is_selfhost() && conn.assigns[:site].custom_domain do
|
2021-01-15 11:12:00 +03:00
|
|
|
[key: "Custom domain", value: "custom-domain"]
|
|
|
|
end,
|
2021-06-16 15:00:07 +03:00
|
|
|
if conn.assigns[:current_user_role] == :owner do
|
|
|
|
[key: "Danger zone", value: "danger-zone"]
|
|
|
|
end
|
2020-11-20 12:57:33 +03:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-09-11 19:04:37 +03:00
|
|
|
def trial_notificaton(user) do
|
|
|
|
case Plausible.Billing.trial_days_left(user) do
|
|
|
|
days when days > 1 ->
|
|
|
|
"#{days} trial days left"
|
2020-06-08 10:35:13 +03:00
|
|
|
|
2019-09-11 19:04:37 +03:00
|
|
|
days when days == 1 ->
|
|
|
|
"Trial ends tomorrow"
|
2020-06-08 10:35:13 +03:00
|
|
|
|
2019-09-11 19:04:37 +03:00
|
|
|
days when days == 0 ->
|
|
|
|
"Trial ends today"
|
|
|
|
end
|
|
|
|
end
|
2020-11-16 16:38:44 +03:00
|
|
|
|
2022-09-20 11:46:28 +03:00
|
|
|
def grace_period_end(%{grace_period: %{end_date: %Date{} = date}}) do
|
|
|
|
case Timex.diff(date, Timex.today(), :days) do
|
2021-11-04 12:46:41 +03:00
|
|
|
0 -> "today"
|
|
|
|
1 -> "tomorrow"
|
|
|
|
n -> "within #{n} days"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-09-20 11:46:28 +03:00
|
|
|
def grace_period_end(_user), do: "in the following days"
|
|
|
|
|
2020-11-16 16:38:44 +03:00
|
|
|
@doc "http://blog.plataformatec.com.br/2018/05/nested-layouts-with-phoenix/"
|
|
|
|
def render_layout(layout, assigns, do: content) do
|
|
|
|
render(layout, Map.put(assigns, :inner_layout, content))
|
|
|
|
end
|
|
|
|
|
|
|
|
def is_current_tab(conn, tab) do
|
|
|
|
List.last(conn.path_info) == tab
|
|
|
|
end
|
2021-01-15 11:12:00 +03:00
|
|
|
|
|
|
|
defp is_selfhost() do
|
|
|
|
Application.get_env(:plausible, :is_selfhost)
|
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|