From b5eae4ca76eca67ec9603dc7249229de9538dd30 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 25 Nov 2020 14:54:23 +0200 Subject: [PATCH 1/4] Add nicer grid list for sites --- lib/plausible/stats/clickhouse.ex | 13 ++++++ .../controllers/site_controller.ex | 3 +- .../templates/site/index.html.eex | 46 +++++++++++-------- 3 files changed, 41 insertions(+), 21 deletions(-) diff --git a/lib/plausible/stats/clickhouse.ex b/lib/plausible/stats/clickhouse.ex index ae7f22d41..37dfad3c9 100644 --- a/lib/plausible/stats/clickhouse.ex +++ b/lib/plausible/stats/clickhouse.ex @@ -762,6 +762,19 @@ defmodule Plausible.Stats.Clickhouse do end) end + def last_24h_visitors(sites) do + domains = Enum.map(sites, & &1.domain) + + ClickhouseRepo.all( + from e in "events", + group_by: e.domain, + where: fragment("? IN tuple(?)", e.domain, ^domains), + where: e.timestamp > fragment("now() - INTERVAL 24 HOUR"), + select: {e.domain, fragment("uniq(user_id)")} + ) + |> Enum.into(%{}) + end + def goal_conversions(site, %Query{filters: %{"goal" => goal}} = query) when is_binary(goal) do ClickhouseRepo.all( from e in base_query_w_sessions(site, query), diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index 063428fc5..d9c10af62 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -7,7 +7,8 @@ defmodule PlausibleWeb.SiteController do def index(conn, _params) do user = conn.assigns[:current_user] |> Repo.preload(:sites) - render(conn, "index.html", sites: user.sites) + visitors = Plausible.Stats.Clickhouse.last_24h_visitors(user.sites) + render(conn, "index.html", sites: user.sites, visitors: visitors) end def new(conn, _params) do diff --git a/lib/plausible_web/templates/site/index.html.eex b/lib/plausible_web/templates/site/index.html.eex index 0c307a556..3a174f501 100644 --- a/lib/plausible_web/templates/site/index.html.eex +++ b/lib/plausible_web/templates/site/index.html.eex @@ -1,25 +1,31 @@ -
-
-
-

My websites

+
+
+

+ My sites +

+ Add a website
-
-
- <%= for site <- @sites do %> -
- - -

<%= site.domain %>

-
- <%= link(to: "/#{URI.encode_www_form(site.domain)}/settings", class: "flex absolute hover:bg-gray-100 transition rounded py-2 px-5", style: "top: 12px; right: 6px;") do %> -
- + +
    + <%= for site <- @sites do %> + <%= link(to: "/" <> URI.encode_www_form(site.domain)) do %> +
  • +
    + +
    +

    <%= site.domain %>

    -

    Settings

    - <% end %> -
    +
+
+ + + <%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %> + visitors in last 24h + + +
+ <% end %> -
-
+ <% end %> +
From d8eb994eff7141912bda55b0166a9473c4077053 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 25 Nov 2020 15:13:34 +0200 Subject: [PATCH 2/4] Add changelog entry --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cbfb54a7c..6aa7dd21f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -16,6 +16,7 @@ All notable changes to this project will be documented in this file. - Ignore consecutive pageviews on same pathname plausible/analytics#417 - Validate domain format on site creation plausible/analytics#427 - Improve settings UX and design plausible/analytics#412 +- Improve site listing UX and design plausible/analytics#438 ### Fixed - Do not error when activating an already activated account plausible/analytics#370 From 8369f8d94fd13c0b13bcfd846f0503fdf79fc287 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Wed, 25 Nov 2020 15:29:08 +0200 Subject: [PATCH 3/4] Add settings links on hover --- .../templates/site/index.html.eex | 38 +++++++++++-------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/lib/plausible_web/templates/site/index.html.eex b/lib/plausible_web/templates/site/index.html.eex index 3a174f501..034cdf810 100644 --- a/lib/plausible_web/templates/site/index.html.eex +++ b/lib/plausible_web/templates/site/index.html.eex @@ -8,24 +8,30 @@
    <%= for site <- @sites do %> - <%= link(to: "/" <> URI.encode_www_form(site.domain)) do %> -
  • -
    - -
    -

    <%= site.domain %>

    +
    + <%= link(to: "/" <> URI.encode_www_form(site.domain)) do %> +
  • +
    + +
    +

    <%= site.domain %>

    +
    -
-
- - - <%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %> - visitors in last 24h +
+ + + <%= PlausibleWeb.StatsView.large_number_format(Map.get(@visitors, site.domain, 0)) %> + visitors in last 24h + - -
- - <% end %> +
+ + <% end %> + + <%= link(to: "/" <> URI.encode_www_form(site.domain) <> "/settings", class: "absolute top-0 right-0 p-4 mt-1") do %> + + <% end %> +
<% end %>
From 472889083d1ed88884fc298dc04359b27bf78753 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Thu, 26 Nov 2020 10:19:26 +0200 Subject: [PATCH 4/4] Order sites alphabetically --- lib/plausible_web/controllers/site_controller.ex | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index d9c10af62..37474a3a4 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -6,9 +6,16 @@ defmodule PlausibleWeb.SiteController do plug PlausibleWeb.RequireAccountPlug def index(conn, _params) do - user = conn.assigns[:current_user] |> Repo.preload(:sites) - visitors = Plausible.Stats.Clickhouse.last_24h_visitors(user.sites) - render(conn, "index.html", sites: user.sites, visitors: visitors) + user = conn.assigns[:current_user] + sites = Repo.all( + from s in Plausible.Site, + join: sm in Plausible.Site.Membership, on: sm.site_id == s.id, + where: sm.user_id == ^user.id, + order_by: s.domain + ) + + visitors = Plausible.Stats.Clickhouse.last_24h_visitors(sites) + render(conn, "index.html", sites: sites, visitors: visitors) end def new(conn, _params) do