mirror of
https://github.com/plausible/analytics.git
synced 2024-12-26 19:15:03 +03:00
Add 7 days as an option
This commit is contained in:
parent
dc201f0b57
commit
f3985903b3
@ -51,6 +51,17 @@ defmodule Plausible.Stats.Query do
|
|||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def from(tz, %{"period" => "7d"}) do
|
||||||
|
end_date = today(tz)
|
||||||
|
start_date = end_date |> Timex.shift(days: -7)
|
||||||
|
|
||||||
|
%__MODULE__{
|
||||||
|
period: "7d",
|
||||||
|
date_range: Date.range(start_date, end_date),
|
||||||
|
step_type: "date"
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def from(_tz, %{"period" => "month", "date" => month_start}) do
|
def from(_tz, %{"period" => "month", "date" => month_start}) do
|
||||||
start_date = Date.from_iso8601!(month_start) |> Timex.beginning_of_month
|
start_date = Date.from_iso8601!(month_start) |> Timex.beginning_of_month
|
||||||
end_date = Timex.end_of_month(start_date)
|
end_date = Timex.end_of_month(start_date)
|
||||||
|
@ -308,7 +308,7 @@ defmodule PlausibleWeb.StatsController do
|
|||||||
|
|
||||||
defp fetch_period(conn, site) do
|
defp fetch_period(conn, site) do
|
||||||
case conn.params["period"] do
|
case conn.params["period"] do
|
||||||
p when p in ["day", "month", "3mo", "6mo"] ->
|
p when p in ["day", "month", "7d", "3mo", "6mo"] ->
|
||||||
saved_periods = get_session(conn, :saved_periods) || %{}
|
saved_periods = get_session(conn, :saved_periods) || %{}
|
||||||
{put_session(conn, :saved_periods, Map.merge(saved_periods, %{site.domain => p})), conn.params}
|
{put_session(conn, :saved_periods, Map.merge(saved_periods, %{site.domain => p})), conn.params}
|
||||||
_ ->
|
_ ->
|
||||||
|
@ -46,9 +46,10 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div data-dropdown style="top: 42px; right: 0px; width: 225px;" class="dropdown-content hidden absolute pin-r bg-white border border-grey-light rounded shadow z-10 font-bold text-sm text-grey-darker">
|
<div data-dropdown style="top: 42px; right: 0px; width: 225px;" class="dropdown-content hidden absolute pin-r bg-white border border-grey-light rounded shadow z-10 font-bold text-sm text-grey-darker">
|
||||||
<%= link("Today", to: "/#{@site.domain}?period=day&date=#{Timex.now(@site.timezone) |> Timex.format!("{ISOdate}")}", class: "block px-2 py-3 hover:bg-grey-lighter") %>
|
<%= link("Today", to: "/#{@site.domain}?period=day", class: "block p-2 hover:bg-grey-lighter") %>
|
||||||
<%= link("This month (#{this_month(@site) |> Timex.format!("{Mfull}")})", to: "/#{@site.domain}?period=month&date=#{this_month(@site) |> Timex.format!("{ISOdate}")}", class: "block p-2 hover:bg-grey-lighter") %>
|
<%= link("Last 7 days", to: "/#{@site.domain}?period=7d", class: "block px-2 py-3 hover:bg-grey-lighter") %>
|
||||||
<%= link("Last month (#{last_month(@site) |> Timex.format!("{Mfull}")})", to: "/#{@site.domain}?period=month&date=#{last_month(@site) |> Timex.format!("{ISOdate}")}", class: "block p-2 hover:bg-grey-lighter") %>
|
<%= link("This month", to: "/#{@site.domain}?period=month", class: "block p-2 hover:bg-grey-lighter") %>
|
||||||
|
<%= link("Last month", to: "/#{@site.domain}?period=month&date=#{last_month(@site) |> Timex.format!("{ISOdate}")}", class: "block p-2 hover:bg-grey-lighter") %>
|
||||||
<%= link("Last 3 months", to: "/#{@site.domain}?period=3mo", class: "block p-2 hover:bg-grey-lighter") %>
|
<%= link("Last 3 months", to: "/#{@site.domain}?period=3mo", class: "block p-2 hover:bg-grey-lighter") %>
|
||||||
<%= link("Last 6 months", to: "/#{@site.domain}?period=6mo", class: "block p-2 hover:bg-grey-lighter") %>
|
<%= link("Last 6 months", to: "/#{@site.domain}?period=6mo", class: "block p-2 hover:bg-grey-lighter") %>
|
||||||
</div>
|
</div>
|
||||||
|
@ -36,6 +36,8 @@ defmodule PlausibleWeb.StatsView do
|
|||||||
"on #{Timex.format!(query.date_range.first, "{Mfull} {D}")}"
|
"on #{Timex.format!(query.date_range.first, "{Mfull} {D}")}"
|
||||||
"month" ->
|
"month" ->
|
||||||
"in #{Timex.format!(query.date_range.first, "{Mfull} {YYYY}")}"
|
"in #{Timex.format!(query.date_range.first, "{Mfull} {YYYY}")}"
|
||||||
|
"7d" ->
|
||||||
|
"in the last 7 days"
|
||||||
"3mo" ->
|
"3mo" ->
|
||||||
"in the last 3 months"
|
"in the last 3 months"
|
||||||
"6mo" ->
|
"6mo" ->
|
||||||
@ -51,6 +53,8 @@ defmodule PlausibleWeb.StatsView do
|
|||||||
"month" ->
|
"month" ->
|
||||||
date = Date.to_iso8601(query.date_range.first)
|
date = Date.to_iso8601(query.date_range.first)
|
||||||
"?period=month&date=#{date}"
|
"?period=month&date=#{date}"
|
||||||
|
"7d" ->
|
||||||
|
"?period=7d"
|
||||||
"3mo" ->
|
"3mo" ->
|
||||||
"?period=3mo"
|
"?period=3mo"
|
||||||
"6mo" ->
|
"6mo" ->
|
||||||
@ -86,6 +90,8 @@ defmodule PlausibleWeb.StatsView do
|
|||||||
else
|
else
|
||||||
Timex.format!(query.date_range.first, "{Mfull} {YYYY}")
|
Timex.format!(query.date_range.first, "{Mfull} {YYYY}")
|
||||||
end
|
end
|
||||||
|
"7d" ->
|
||||||
|
"Last 7 days"
|
||||||
"day" ->
|
"day" ->
|
||||||
if query.date_range.first == today(site) do
|
if query.date_range.first == today(site) do
|
||||||
"Today"
|
"Today"
|
||||||
|
Loading…
Reference in New Issue
Block a user