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
|
|
|
|
|
2024-02-23 14:35:22 +03:00
|
|
|
def logo_path(filename) do
|
2024-04-29 09:05:33 +03:00
|
|
|
if ee?() do
|
2024-02-23 14:35:22 +03:00
|
|
|
Path.join("/images/ee/", filename)
|
|
|
|
else
|
|
|
|
Path.join("/images/ce/", filename)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-06-16 15:00:07 +03:00
|
|
|
def settings_tabs(conn) do
|
2020-11-20 12:57:33 +03:00
|
|
|
[
|
2024-02-27 14:08:13 +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},
|
2024-04-29 09:05:33 +03:00
|
|
|
on_ee do
|
2024-02-27 14:08:13 +03:00
|
|
|
%{key: "Funnels", value: "funnels", icon: :funnel}
|
2023-11-20 14:52:20 +03:00
|
|
|
end,
|
2024-02-27 14:08:13 +03:00
|
|
|
%{key: "Custom Properties", value: "properties", icon: :document_text},
|
|
|
|
%{key: "Integrations", value: "integrations", icon: :arrow_path_rounded_square},
|
2024-05-09 11:09:24 +03:00
|
|
|
%{key: "Imports & Exports", value: "imports-exports", icon: :arrows_up_down},
|
2024-02-27 14:08:13 +03:00
|
|
|
%{
|
|
|
|
key: "Shields",
|
|
|
|
icon: :shield_exclamation,
|
2024-03-25 12:36:22 +03:00
|
|
|
value:
|
|
|
|
[
|
|
|
|
%{key: "IP Addresses", value: "shields/ip_addresses"},
|
|
|
|
%{key: "Countries", value: "shields/countries"},
|
2024-04-16 21:30:20 +03:00
|
|
|
%{key: "Pages", value: "shields/pages"},
|
2024-04-18 21:18:38 +03:00
|
|
|
%{key: "Hostnames", value: "shields/hostnames"}
|
2024-03-25 12:36:22 +03:00
|
|
|
]
|
|
|
|
|> Enum.reject(&is_nil/1)
|
2024-02-27 14:08:13 +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-02-27 14:08:13 +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
|
|
|
]
|
2024-02-27 14:08:13 +03:00
|
|
|
|> Enum.reject(&is_nil/1)
|
|
|
|
end
|
|
|
|
|
|
|
|
def flat_settings_options(conn) do
|
|
|
|
conn
|
|
|
|
|> settings_tabs()
|
|
|
|
|> Enum.map(fn
|
|
|
|
%{value: value, key: key} when is_binary(value) ->
|
|
|
|
{key, value}
|
|
|
|
|
|
|
|
%{value: submenu_items, key: parent_key} when is_list(submenu_items) ->
|
|
|
|
Enum.map(submenu_items, fn submenu_item ->
|
|
|
|
{"#{parent_key}: #{submenu_item.key}", submenu_item.value}
|
|
|
|
end)
|
|
|
|
end)
|
|
|
|
|> List.flatten()
|
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
|
|
|
|
|
2024-02-27 14:08:13 +03:00
|
|
|
def is_current_tab(_, nil) do
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2020-11-16 16:38:44 +03:00
|
|
|
def is_current_tab(conn, tab) do
|
2024-02-27 14:08:13 +03:00
|
|
|
String.ends_with?(Enum.join(conn.path_info, "/"), tab)
|
2020-11-16 16:38:44 +03:00
|
|
|
end
|
2019-09-02 14:29:19 +03:00
|
|
|
end
|