mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 02:55:02 +03:00
0b7870dc4d
* first launch * dynamic children, wait for repo * remove wait_for_repo and app env manipulations * don't mention free trial in self-hosted pages * add changelog * assigns[:is_selfhost] -> @is_selfhost * better changelog wording * rm admin_user, admin_email, admin_pwd from app env * rm DISABLE_AUTH * redirect / to /login when not authenticated * remove TODO * Update lib/plausible_web/controllers/page_controller.ex Co-authored-by: Uku Taht <Uku.taht@gmail.com> * format Co-authored-by: Uku Taht <Uku.taht@gmail.com>
60 lines
1.8 KiB
Elixir
60 lines
1.8 KiB
Elixir
defmodule PlausibleWeb.AuthView do
|
|
use PlausibleWeb, :view
|
|
alias Plausible.Billing.Plans
|
|
|
|
def base_domain do
|
|
PlausibleWeb.Endpoint.host()
|
|
end
|
|
|
|
def plausible_url do
|
|
PlausibleWeb.Endpoint.url()
|
|
end
|
|
|
|
def subscription_quota(subscription) do
|
|
Plans.allowance(subscription) |> PlausibleWeb.StatsView.large_number_format()
|
|
end
|
|
|
|
def subscription_interval(subscription) do
|
|
Plans.subscription_interval(subscription)
|
|
end
|
|
|
|
def format_invoices(invoice_list) do
|
|
Enum.map(invoice_list, fn invoice ->
|
|
%{
|
|
date:
|
|
invoice["payout_date"] |> Date.from_iso8601!() |> Timex.format!("{Mshort} {D}, {YYYY}"),
|
|
amount: (invoice["amount"] / 1) |> :erlang.float_to_binary(decimals: 2),
|
|
currency: invoice["currency"] |> PlausibleWeb.BillingView.present_currency(),
|
|
url: invoice["receipt_url"]
|
|
}
|
|
end)
|
|
end
|
|
|
|
def delimit_integer(number) do
|
|
Integer.to_charlist(number)
|
|
|> :lists.reverse()
|
|
|> delimit_integer([])
|
|
|> String.Chars.to_string()
|
|
end
|
|
|
|
defp delimit_integer([a, b, c, d | tail], acc) do
|
|
delimit_integer([d | tail], [",", c, b, a | acc])
|
|
end
|
|
|
|
defp delimit_integer(list, acc) do
|
|
:lists.reverse(list) ++ acc
|
|
end
|
|
|
|
def present_subscription_status("active"), do: "Active"
|
|
def present_subscription_status("past_due"), do: "Past due"
|
|
def present_subscription_status("deleted"), do: "Cancelled"
|
|
def present_subscription_status("paused"), do: "Paused"
|
|
def present_subscription_status(status), do: status
|
|
|
|
def subscription_colors("active"), do: "bg-green-100 text-green-800"
|
|
def subscription_colors("past_due"), do: "bg-yellow-100 text-yellow-800"
|
|
def subscription_colors("paused"), do: "bg-red-100 text-red-800"
|
|
def subscription_colors("deleted"), do: "bg-red-100 text-red-800"
|
|
def subscription_colors(_), do: ""
|
|
end
|