From d04677332812d1afea9ae130e247446b744cc9d0 Mon Sep 17 00:00:00 2001 From: Uku Taht Date: Fri, 6 Nov 2020 13:30:38 +0200 Subject: [PATCH] WIP --- assets/css/app.css | 10 +- assets/package-lock.json | 94 +++++++----- assets/package.json | 2 +- .../controllers/site_controller.ex | 18 ++- lib/plausible_web/router.ex | 3 +- .../templates/site/_settings_tab.html.eex | 5 + .../templates/site/settings.html.eex | 137 ++++++++++++++++++ .../templates/site/settings_goals.html.eex | 31 ++++ .../templates/site/settings_header.html.eex | 25 ++++ 9 files changed, 286 insertions(+), 39 deletions(-) create mode 100644 lib/plausible_web/templates/site/_settings_tab.html.eex create mode 100644 lib/plausible_web/templates/site/settings_goals.html.eex create mode 100644 lib/plausible_web/templates/site/settings_header.html.eex diff --git a/assets/css/app.css b/assets/css/app.css index 9b40219ef..990c187f1 100644 --- a/assets/css/app.css +++ b/assets/css/app.css @@ -7,15 +7,19 @@ @import "tooltip.css"; .button { - @apply inline-block bg-indigo-600 text-white text-center font-bold tracking-wide py-2 px-5 rounded no-underline; + @apply bg-indigo-600 border border-transparent rounded-md py-2 px-4 inline-flex justify-center text-sm leading-5 font-medium text-white transition-all duration-150 ease-in-out; } .button:hover { - @apply shadow; + @apply bg-gray-700; } .button:focus { - @apply outline-none; + @apply outline-none border-gray-900 shadow-outline-gray; +} + +.button:active { + @apply bg-gray-900; } .button-outline { diff --git a/assets/package-lock.json b/assets/package-lock.json index 78b1a6220..c82c27075 100644 --- a/assets/package-lock.json +++ b/assets/package-lock.json @@ -1160,11 +1160,6 @@ "postcss-selector-parser": "^6.0.2" } }, - "@types/color-name": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/@types/color-name/-/color-name-1.1.1.tgz", - "integrity": "sha512-rr+OQyAjxze7GgWrSaJwydHStIhHq2lvY3BOC2Mj7KnzI7XK0Uw1TOOdI9lDoajEbSWLiYgoo4f1R51erQfhPQ==" - }, "@types/d3": { "version": "3.5.38", "resolved": "https://registry.npmjs.org/@types/d3/-/d3-3.5.38.tgz", @@ -1369,9 +1364,9 @@ }, "dependencies": { "acorn": { - "version": "7.4.0", - "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.0.tgz", - "integrity": "sha512-+G7P8jJmCHr+S+cLfQxygbWhXy+8YTVGzAkpEbcLo2mLoL7tij/VG41QSHACSf5QgYRhMZYHuNc6drJaO0Da+w==" + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/acorn/-/acorn-7.4.1.tgz", + "integrity": "sha512-nQyp0o1/mNdbTO1PO6kHkwSrmgZ0MT/jCCpNiwbUjGoRN4dlBhqJtoQuCnEOKzgTVwg0ZWiCoQy6SxMebQVh8A==" } } }, @@ -4159,6 +4154,11 @@ "resolved": "https://registry.npmjs.org/html-comment-regex/-/html-comment-regex-1.1.2.tgz", "integrity": "sha512-P+M65QY2JQ5Y0G9KKdlDpo0zK+/OHptU5AaBwUfAIDJZk1MYf32Frm84EcOytfJE0t5JvkAnKlmjsXDnWzCJmQ==" }, + "html-tags": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/html-tags/-/html-tags-3.1.0.tgz", + "integrity": "sha512-1qYz89hW3lFDEazhjW0yVAV87lw8lVkrJocr72XmBkMKsoSVJCQx3W8BXsC7hO2qAt8BoVjYjtAcZ9perqGnNg==" + }, "https-browserify": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/https-browserify/-/https-browserify-1.0.0.tgz", @@ -5081,6 +5081,11 @@ } } }, + "object-hash": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.0.3.tgz", + "integrity": "sha512-JPKn0GMu+Fa3zt3Bmr66JhokJU5BaNBIh4ZeTlaCBzrBsOeXzwcKKAK1tbLiPKgvwmPXsDvvLHoWh5Bm7ofIYg==" + }, "object-inspect": { "version": "1.4.1", "resolved": "https://registry.npmjs.org/object-inspect/-/object-inspect-1.4.1.tgz", @@ -7108,7 +7113,7 @@ }, "pretty-hrtime": { "version": "1.0.3", - "resolved": "http://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", + "resolved": "https://registry.npmjs.org/pretty-hrtime/-/pretty-hrtime-1.0.3.tgz", "integrity": "sha1-t+PqQkNaTJsnWdmeDyAesZWALuE=" }, "process": { @@ -8193,9 +8198,9 @@ } }, "tailwindcss": { - "version": "1.6.2", - "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-1.6.2.tgz", - "integrity": "sha512-Cpa0kElG8Sg5sJSvTYi2frmIQZq0w37RLNNrYyy/W6HIWKspqSdTfb9tIN6X1gm4KV5a+TE/n7EKmn5Q9C7EUQ==", + "version": "1.9.6", + "resolved": "https://registry.npmjs.org/tailwindcss/-/tailwindcss-1.9.6.tgz", + "integrity": "sha512-nY8WYM/RLPqGsPEGEV2z63riyQPcHYZUJpAwdyBzVpxQHOHqHE+F/fvbCeXhdF1+TA5l72vSkZrtYCB9hRcwkQ==", "requires": { "@fullhuman/postcss-purgecss": "^2.1.2", "autoprefixer": "^9.4.5", @@ -8205,43 +8210,46 @@ "color": "^3.1.2", "detective": "^5.2.0", "fs-extra": "^8.0.0", - "lodash": "^4.17.15", + "html-tags": "^3.1.0", + "lodash": "^4.17.20", "node-emoji": "^1.8.1", "normalize.css": "^8.0.1", + "object-hash": "^2.0.3", "postcss": "^7.0.11", "postcss-functions": "^3.0.0", "postcss-js": "^2.0.0", "postcss-nested": "^4.1.1", "postcss-selector-parser": "^6.0.0", + "postcss-value-parser": "^4.1.0", "pretty-hrtime": "^1.0.3", "reduce-css-calc": "^2.1.6", "resolve": "^1.14.2" }, "dependencies": { "ansi-styles": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.2.1.tgz", - "integrity": "sha512-9VGjrMsG1vePxcSweQsN20KY/c4zN0h9fLjqAbwbPfahM3t+NL+M9HC8xeXG2I8pX5NoamTGNuomEUFI7fcUjA==", + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz", + "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==", "requires": { - "@types/color-name": "^1.1.1", "color-convert": "^2.0.1" } }, "browserslist": { - "version": "4.14.0", - "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.14.0.tgz", - "integrity": "sha512-pUsXKAF2lVwhmtpeA3LJrZ76jXuusrNyhduuQs7CDFf9foT4Y38aQOserd2lMe5DSSrjf3fx34oHwryuvxAUgQ==", + "version": "4.14.7", + "resolved": "https://registry.npmjs.org/browserslist/-/browserslist-4.14.7.tgz", + "integrity": "sha512-BSVRLCeG3Xt/j/1cCGj1019Wbty0H+Yvu2AOuZSuoaUWn3RatbL33Cxk+Q4jRMRAbOm0p7SLravLjpnT6s0vzQ==", "requires": { - "caniuse-lite": "^1.0.30001111", - "electron-to-chromium": "^1.3.523", - "escalade": "^3.0.2", - "node-releases": "^1.1.60" + "caniuse-lite": "^1.0.30001157", + "colorette": "^1.2.1", + "electron-to-chromium": "^1.3.591", + "escalade": "^3.1.1", + "node-releases": "^1.1.66" } }, "caniuse-lite": { - "version": "1.0.30001114", - "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001114.tgz", - "integrity": "sha512-ml/zTsfNBM+T1+mjglWRPgVsu2L76GAaADKX5f4t0pbhttEp0WMawJsHDYlFkVZkoA+89uvBRrVrEE4oqenzXQ==" + "version": "1.0.30001157", + "resolved": "https://registry.npmjs.org/caniuse-lite/-/caniuse-lite-1.0.30001157.tgz", + "integrity": "sha512-gOerH9Wz2IRZ2ZPdMfBvyOi3cjaz4O4dgNwPGzx8EhqAs4+2IL/O+fJsbt+znSigujoZG8bVcIAUM/I/E5K3MA==" }, "chalk": { "version": "4.1.0", @@ -8265,20 +8273,40 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "electron-to-chromium": { + "version": "1.3.593", + "resolved": "https://registry.npmjs.org/electron-to-chromium/-/electron-to-chromium-1.3.593.tgz", + "integrity": "sha512-GvO7G1ZxvffnMvPCr4A7+iQPVuvpyqMrx2VWSERAjG+pHK6tmO9XqYdBfMIq9corRyi4bNImSDEiDvIoDb8HrA==" + }, + "escalade": { + "version": "3.1.1", + "resolved": "https://registry.npmjs.org/escalade/-/escalade-3.1.1.tgz", + "integrity": "sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==" + }, "has-flag": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz", "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==" }, + "lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-PlhdFcillOINfeV7Ni6oF1TAEayyZBoZ8bcshTHqOYJYlrqzRK5hagpagky5o4HfCzzd1TRkXPMFq6cKk9rGmA==" + }, "node-releases": { - "version": "1.1.60", - "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.60.tgz", - "integrity": "sha512-gsO4vjEdQaTusZAEebUWp2a5d7dF5DYoIpDG7WySnk7BuZDW+GPpHXoXXuYawRBr/9t5q54tirPz79kFIWg4dA==" + "version": "1.1.66", + "resolved": "https://registry.npmjs.org/node-releases/-/node-releases-1.1.66.tgz", + "integrity": "sha512-JHEQ1iWPGK+38VLB2H9ef2otU4l8s3yAMt9Xf934r6+ojCYDMHPMqvCc9TnzfeFSP1QEOeU6YZEd3+De0LTCgg==" + }, + "postcss-value-parser": { + "version": "4.1.0", + "resolved": "https://registry.npmjs.org/postcss-value-parser/-/postcss-value-parser-4.1.0.tgz", + "integrity": "sha512-97DXOFbQJhk71ne5/Mt6cOu6yxsSfM0QGQyl0L25Gca4yGWEGJaig7l7gbCX623VqTBNGLRLaVUCnNkcedlRSQ==" }, "supports-color": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.1.0.tgz", - "integrity": "sha512-oRSIpR8pxT1Wr2FquTNnGet79b3BWljqOuoW/h4oBhxJ/HUbX5nX6JSruTkvXDCFMwDPvsaTTbvMLKZWSy0R5g==", + "version": "7.2.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz", + "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==", "requires": { "has-flag": "^4.0.0" } diff --git a/assets/package.json b/assets/package.json index d84ee5dae..ec550d909 100644 --- a/assets/package.json +++ b/assets/package.json @@ -29,7 +29,7 @@ "react-flip-move": "^3.0.4", "react-router-dom": "^5.2.0", "react-transition-group": "^4.4.1", - "tailwindcss": "^1.6.2", + "tailwindcss": "^1.9.6", "uglifyjs-webpack-plugin": "^2.2.0", "url-search-params-polyfill": "^8.0.0", "webpack": "4.39.2", diff --git a/lib/plausible_web/controllers/site_controller.ex b/lib/plausible_web/controllers/site_controller.ex index b040fa609..d39ffa937 100644 --- a/lib/plausible_web/controllers/site_controller.ex +++ b/lib/plausible_web/controllers/site_controller.ex @@ -87,6 +87,10 @@ defmodule PlausibleWeb.SiteController do end def settings(conn, %{"website" => website}) do + redirect(conn, to: "/#{URI.encode_www_form(website)}/settings/general") + end + + def settings_general(conn, %{"website" => website}) do site = Sites.get_for_user!(conn.assigns[:current_user].id, website) |> Repo.preload(:google_auth) @@ -99,8 +103,8 @@ defmodule PlausibleWeb.SiteController do weekly_report = Repo.get_by(Plausible.Site.WeeklyReport, site_id: site.id) monthly_report = Repo.get_by(Plausible.Site.MonthlyReport, site_id: site.id) - goals = Goals.for_site(site.domain) shared_links = Repo.all(from l in Plausible.Site.SharedLink, where: l.site_id == ^site.id) + goals = Goals.for_site(site.domain) conn |> assign(:skip_plausible_tracking, true) @@ -115,6 +119,18 @@ defmodule PlausibleWeb.SiteController do ) end + def settings_goals(conn, %{"website" => website}) do + site = Sites.get_for_user!(conn.assigns[:current_user].id, website) + goals = Goals.for_site(site.domain) + + conn + |> assign(:skip_plausible_tracking, true) + |> render("settings_goals.html", + site: site, + goals: goals + ) + end + def update_google_auth(conn, %{"website" => website, "google_auth" => attrs}) do site = Sites.get_for_user!(conn.assigns[:current_user].id, website) diff --git a/lib/plausible_web/router.ex b/lib/plausible_web/router.ex index 295f3c0cf..006ffba8c 100644 --- a/lib/plausible_web/router.ex +++ b/lib/plausible_web/router.ex @@ -145,7 +145,8 @@ defmodule PlausibleWeb.Router do get "/:website/snippet", SiteController, :add_snippet get "/:website/settings", SiteController, :settings - get "/:website/goals", SiteController, :goals + get "/:website/settings/general", SiteController, :settings_general + get "/:website/settings/goals", SiteController, :settings_goals get "/:website/goals/new", SiteController, :new_goal post "/:website/goals", SiteController, :create_goal delete "/:website/goals/:id", SiteController, :delete_goal diff --git a/lib/plausible_web/templates/site/_settings_tab.html.eex b/lib/plausible_web/templates/site/_settings_tab.html.eex new file mode 100644 index 000000000..896ac8d10 --- /dev/null +++ b/lib/plausible_web/templates/site/_settings_tab.html.eex @@ -0,0 +1,5 @@ +<%= if @current_tab == @this_tab do %> + "><%= @text %> +<% else %> + "><%= @text %> +<% end %> diff --git a/lib/plausible_web/templates/site/settings.html.eex b/lib/plausible_web/templates/site/settings.html.eex index 66ae79b7f..b2da611b4 100644 --- a/lib/plausible_web/templates/site/settings.html.eex +++ b/lib/plausible_web/templates/site/settings.html.eex @@ -1,3 +1,140 @@ +
+
+ <%= render("settings_header.html", tab: "general", site: @site) %> + +
+ <%= form_for @changeset, "/#{URI.encode_www_form(@site.domain)}/settings", fn f -> %> +
+
+
+

General information

+

Update your billing information. Please note that updating your location could affect your tax rates.

+
+ +
+
+ <%= label f, :domain, class: "block text-sm font-medium leading-5 text-gray-700" %> + <%= text_input f, :domain, class: "form-input mt-1 block w-full border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5", disabled: "disabled" %> +
+ +
+ <%= label f, :timezone, "Reporting Timezone", class: "block text-sm font-medium leading-5 text-gray-700" %> + <%= select f, :timezone, Plausible.Timezones.options(), class: "form-select mt-1 block w-full bg-white border border-gray-300 rounded-md shadow-sm py-2 px-3 focus:outline-none focus:shadow-outline-blue focus:border-blue-300 transition duration-150 ease-in-out sm:text-sm sm:leading-5" %> +
+
+
+
+ + <%= submit "Save", class: "bg-indigo-600 border border-transparent rounded-md py-2 px-4 inline-flex justify-center text-sm leading-5 font-medium text-white hover:bg-gray-700 focus:outline-none focus:border-gray-900 focus:shadow-outline-gray active:bg-gray-900 transition duration-150 ease-in-out" %> + +
+
+ <% end %> + +
+
+

Dashboard visibility

+

Share your stats publicly or keep them private

+
+ +
+
+ +
+
+ +
+ +
+ + +
+
+ +
+ +
+
+
+ +
+
+

Shared links

+

You can share your stats privately by generating a shared link. The links are impossible to guess and you can add password protection for extra security.

+
+ +
+ <%= for link <- @shared_links do %> +
+ + + <%= button(to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/#{link.slug}", method: :delete, class: "py-2 px-4 bg-gray-100 text-red-600 rounded-l-none", data: [confirm: "Are you sure you want to delete this shared link? The stats will not be accessible with this link anymore."]) do %> + + <% end %> +
+ <% end %> + + <%= link("+ New link", to: "/sites/#{URI.encode_www_form(@site.domain)}/shared-links/new", class: "button mt-4") %> +
+
+
+ +
+
+
+

Danger zone

+

Desctructive actions below can result in irrecoverable data loss. Be careful.

+
+
  • +
    +

    + Reset stats +

    +

    + Removes all pageviews but keeps the site configuration +

    +
    + <%= link("Reset #{@site.domain} stats", to: "/#{URI.encode_www_form(@site.domain)}/stats", method: :delete, class: "inline-block px-4 py-2 border border-gray-300 text-sm leading-5 font-medium rounded-md text-red-700 bg-white hover:text-red-500 focus:outline-none focus:border-blue-300 focus:shadow-outline-blue active:text-red-800 active:bg-gray-50 transition ease-in-out duration-150", data: [confirm: "Resetting the stats cannot be reversed. Are you sure?"]) %> +
  • +
    + +
  • +
    +

    + Delete site +

    +

    + Removes all stats along with the site configuration +

    +
    + <%= link "Delete #{@site.domain}", to: "/#{URI.encode_www_form(@site.domain)}", method: :delete, class: "inline-block px-4 py-2 border border-transparent font-medium rounded-md text-red-700 bg-red-100 hover:bg-red-50 focus:outline-none focus:border-red-300 focus:shadow-outline-red active:bg-red-200 transition ease-in-out duration-150 sm:text-sm sm:leading-5", data: [confirm: "Deleting the site data cannot be reversed. Are you sure?"] %> +
  • +
    +
    +
    +
    +
    +

    Settings for <%= @site.domain %>

    diff --git a/lib/plausible_web/templates/site/settings_goals.html.eex b/lib/plausible_web/templates/site/settings_goals.html.eex new file mode 100644 index 000000000..03ea7c197 --- /dev/null +++ b/lib/plausible_web/templates/site/settings_goals.html.eex @@ -0,0 +1,31 @@ +
    +
    + <%= render("settings_header.html", tab: "goals", site: @site) %> + +
    +
    +
    +

    Goals

    +

    Define actions that you want your users to take like visiting a certain page, submitting a form, etc.

    +
    + + <%= if Enum.count(@goals) > 0 do %> +
    + <%= for goal <- @goals do %> +
    + <%= goal_name(goal) %> + <%= button(to: "/#{URI.encode_www_form(@site.domain)}/goals/#{goal.id}", method: :delete, class: "text-sm text-red-600", data: [confirm: "Are you sure you want to remove goal #{goal_name(goal)}? This will just affect the UI, all of your analytics data will stay intact."]) do %> + + <% end %> +
    + <% end %> +
    + <% else %> +
    No goals configured for this site yet
    + <% end %> + + <%= link("+ Add goal", to: "/#{URI.encode_www_form(@site.domain)}/goals/new", class: "button mt-6") %> +
    +
    +
    +
    diff --git a/lib/plausible_web/templates/site/settings_header.html.eex b/lib/plausible_web/templates/site/settings_header.html.eex new file mode 100644 index 000000000..d412a5d3c --- /dev/null +++ b/lib/plausible_web/templates/site/settings_header.html.eex @@ -0,0 +1,25 @@ +
    +
    + +
    + +