2019-09-02 14:29:19 +03:00
|
|
|
defmodule PlausibleWeb.LayoutView do
|
|
|
|
use PlausibleWeb, :view
|
2023-11-20 14:52:20 +03:00
|
|
|
use Plausible
|
2024-01-15 17:59:56 +03:00
|
|
|
alias PlausibleWeb.Components.Billing.Notice
|
2023-11-20 14:52:20 +03:00
|
|
|
|
2020-05-26 16:09:34 +03:00
|
|
|
def plausible_url do
|
2020-10-05 15:01:54 +03:00
|
|
|
PlausibleWeb.Endpoint.url()
|
2020-05-26 16:09:34 +03:00
|
|
|
end
|
|
|
|
|
2023-06-27 14:37:21 +03:00
|
|
|
def websocket_url() do
|
|
|
|
PlausibleWeb.Endpoint.websocket_url()
|
|
|
|
end
|
|
|
|
|
2023-10-17 12:01:27 +03:00
|
|
|
defmodule JWT do
|
|
|
|
use Joken.Config
|
|
|
|
end
|
|
|
|
|
|
|
|
def feedback_link(user) do
|
|
|
|
token_params = %{
|
|
|
|
"id" => user.id,
|
|
|
|
"email" => user.email,
|
|
|
|
"name" => user.name,
|
|
|
|
"imageUrl" => Plausible.Auth.User.profile_img_url(user)
|
|
|
|
}
|
|
|
|
|
|
|
|
case JWT.generate_and_sign(token_params) do
|
|
|
|
{:ok, token, _claims} ->
|
|
|
|
"https://feedback.plausible.io/sso/#{token}?returnUrl=https://feedback.plausible.io"
|
|
|
|
|
|
|
|
_ ->
|
|
|
|
"https://feedback.plausible.io"
|
|
|
|
end
|
|
|
|
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
|
|
|
[
|
2024-01-22 14:14:47 +03:00
|
|
|
[key: "General", value: "general", icon: :rocket_launch],
|
|
|
|
[key: "People", value: "people", icon: :users],
|
|
|
|
[key: "Visibility", value: "visibility", icon: :eye],
|
|
|
|
[key: "Goals", value: "goals", icon: :check_circle],
|
2023-11-20 14:52:20 +03:00
|
|
|
on_full_build do
|
2024-01-22 14:14:47 +03:00
|
|
|
[key: "Funnels", value: "funnels", icon: :funnel]
|
2023-11-20 14:52:20 +03:00
|
|
|
end,
|
2024-01-22 14:14:47 +03:00
|
|
|
[key: "Custom Properties", value: "properties", icon: :document_text],
|
|
|
|
[key: "Integrations", value: "integrations", icon: :arrow_path_rounded_square],
|
2024-02-12 17:22:06 +03:00
|
|
|
if FunWithFlags.enabled?(:shields, for: conn.assigns[:current_user]) do
|
|
|
|
[key: "Shields", value: "shields", icon: :shield_exclamation]
|
|
|
|
end,
|
2024-01-22 14:14:47 +03:00
|
|
|
[key: "Email Reports", value: "email-reports", icon: :envelope],
|
2021-06-16 15:00:07 +03:00
|
|
|
if conn.assigns[:current_user_role] == :owner do
|
2024-01-22 14:14:47 +03:00
|
|
|
[key: "Danger Zone", value: "danger-zone", icon: :exclamation_triangle]
|
2021-06-16 15:00:07 +03:00
|
|
|
end
|
2020-11-20 12:57:33 +03:00
|
|
|
]
|
|
|
|
end
|
|
|
|
|
2019-09-11 19:04:37 +03:00
|
|
|
def trial_notificaton(user) do
|
2024-02-01 10:15:04 +03:00
|
|
|
case Plausible.Users.trial_days_left(user) do
|
2019-09-11 19:04:37 +03:00
|
|
|
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
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|