analytics/lib/plausible_web/views/layout_view.ex
hq1 a4b9c3b8ba
Remove custom domains support + update build options (#3559)
* Disable super-admin checks on small build

* Mute a test writing to stdout

* Move sampling outside of small build

* Convert waiting_first_pageview to heex and stop relying on env vars

* Set site limit unlimited on small build

* Stop relying on app env to get trial expiry

* Remove custom domains - including migration

* Remove is_selfhosted from layout view

* Quota fixup

* Stop relying on app env for self hosted registration

* Stop relying on app env for pass reset success

* Apply on_trial? check only on full build

* Update templates relying on app env

* Adjusts auth controller tests for small build

* Trial fixup

* Fixup

* Stop relying on app env

* Rest of the fsckn owl

* Update typespecs

* Fix dialyzer warning

* Remove unused module

* Credo + format

* GeoIP is not, for full build

* Use `small_build?()` where applicable

* Implement bypassing FirstLaunchPlug without insertions

* Get Marko's patch de58a18a85

* Test is-dbip=false presence

* Fix typespec

* Remove future hardcodes

* Handle `nil` from `Plausible.Geo.database_type()`

* Remove XXX marker

* Use one typespec for two clauses

* Introduce `MIX_ENV=small_dev`

* Revert "Use one typespec for two clauses"

This reverts commit 8d8cd21764.
2023-11-29 11:04:54 +01:00

124 lines
3.1 KiB
Elixir

defmodule PlausibleWeb.LayoutView do
use PlausibleWeb, :view
use Plausible
import PlausibleWeb.Components.Billing
def base_domain do
PlausibleWeb.Endpoint.host()
end
def plausible_url do
PlausibleWeb.Endpoint.url()
end
def websocket_url() do
PlausibleWeb.Endpoint.websocket_url()
end
def dogfood_script_url() do
if Application.get_env(:plausible, :environment) in ["prod", "staging"] do
"#{plausible_url()}/js/script.manual.pageview-props.tagged-events.js"
else
"#{plausible_url()}/js/script.local.manual.pageview-props.tagged-events.js"
end
end
def dogfood_domain(conn) do
if conn.assigns[:embedded] do
"embed." <> base_domain()
else
base_domain()
end
end
@doc """
Temporary override to do more testing of the new ingest.plausible.io endpoint for accepting events. In staging and locally
will fall back to staging.plausible.io/api/event and localhost:8000/api/event respectively.
"""
def dogfood_api_destination() do
if Application.get_env(:plausible, :environment) == "prod" do
"https://ingest.plausible.io/api/event"
end
end
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
def home_dest(conn) do
if conn.assigns[:current_user] do
"/sites"
else
"/"
end
end
def settings_tabs(conn) do
[
[key: "General", value: "general"],
[key: "People", value: "people"],
[key: "Visibility", value: "visibility"],
[key: "Goals", value: "goals"],
on_full_build do
[key: "Funnels", value: "funnels"]
end,
[key: "Custom Properties", value: "properties"],
[key: "Integrations", value: "integrations"],
[key: "Email Reports", value: "email-reports"],
if conn.assigns[:current_user_role] == :owner do
[key: "Danger zone", value: "danger-zone"]
end
]
end
def trial_notificaton(user) do
case Plausible.Billing.trial_days_left(user) do
days when days > 1 ->
"#{days} trial days left"
days when days == 1 ->
"Trial ends tomorrow"
days when days == 0 ->
"Trial ends today"
end
end
def grace_period_end(%{grace_period: %{end_date: %Date{} = date}}) do
case Timex.diff(date, Timex.today(), :days) do
0 -> "today"
1 -> "tomorrow"
n -> "within #{n} days"
end
end
def grace_period_end(_user), do: "in the following days"
@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
end