From 0f5388836a340e7ed0dd97e02ff6f783482827e0 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Sun, 18 Feb 2024 21:39:53 +0100 Subject: [PATCH] Revamp the user settings page --- assets/css/_user_edit.scss | 12 +- .../controllers/user_controller.ex | 6 +- .../templates/user/edit.html.eex | 161 ++++++++++++------ test/controllers/user_controller_test.exs | 6 +- 4 files changed, 125 insertions(+), 60 deletions(-) diff --git a/assets/css/_user_edit.scss b/assets/css/_user_edit.scss index df5c06cf6..a7cd07830 100644 --- a/assets/css/_user_edit.scss +++ b/assets/css/_user_edit.scss @@ -1,5 +1,15 @@ .c-user.a-edit { .user-form { - margin-bottom: 3em; + form { + margin-bottom: 2em; + } + } + + .install-ids { + margin: 2em 0; + + .revoked { + opacity: 0.7; + } } } diff --git a/lib/asciinema_web/controllers/user_controller.ex b/lib/asciinema_web/controllers/user_controller.ex index 62d3757bc..0dc35939c 100644 --- a/lib/asciinema_web/controllers/user_controller.ex +++ b/lib/asciinema_web/controllers/user_controller.ex @@ -107,10 +107,10 @@ defmodule AsciinemaWeb.UserController do user = conn.assigns.current_user case Accounts.update_user(user, user_params) do - {:ok, user} -> + {:ok, _user} -> conn - |> put_flash(:info, "Account settings saved.") - |> redirect(to: profile_path(conn, user)) + |> put_flash(:info, "Settings updated") + |> redirect(to: ~p"/user/edit") {:error, %Ecto.Changeset{} = changeset} -> render_edit_form(conn, user, changeset) diff --git a/lib/asciinema_web/templates/user/edit.html.eex b/lib/asciinema_web/templates/user/edit.html.eex index e1522d8b2..bf73e57ca 100644 --- a/lib/asciinema_web/templates/user/edit.html.eex +++ b/lib/asciinema_web/templates/user/edit.html.eex @@ -2,15 +2,7 @@
<%= form_for @changeset, Routes.user_path(@conn, :update), [class: "simple_form form-horizontal", novalidate: "novalidate", role: "form"], fn f -> %> - Account settings - -
- <%= label f, :username, class: "string optional col-form-label col-3" %> -
- <%= text_input f, :username, class: "string optional form-control" %> - <%= error_tag f, :username %> -
-
+ Account
-
- <%= label f, :name, "Full name", class: "string optional col-form-label col-3" %> +
+ +
+
+ <%= submit "Update", class: "btn btn-primary" %> +
+
+ <% end %> + + <%= form_for @changeset, Routes.user_path(@conn, :update), [class: "simple_form form-horizontal", novalidate: "novalidate", role: "form"], fn f -> %> + Profile + +
+ <%= label f, :username, class: "string optional col-form-label col-3" %>
- <%= text_input f, :name, class: "string optional form-control" %> - <%= error_tag f, :name %> + <%= text_input f, :username, class: "string optional form-control" %> + <%= error_tag f, :username %>
-
- <%= label f, :theme_name, "Default terminal theme", class: "col-3 select optional col-form-label" %> +
+ <%= label f, :name, "Display name", class: "string optional col-form-label col-3" %>
- <%= select f, :theme_name, theme_options(), class: "select optional form-control", prompt: "Default (asciinema)" %> - Applies to all your recordings that don't explicitly override this. + <%= text_input f, :name, class: "string optional form-control", placeholder: @changeset.data.username %> + <%= error_tag f, :name %>
- <%= label f, :terminal_font_family, "Default terminal font", class: "col-sm-4 col-md-3 col-form-label" %> -
- <%= select f, :terminal_font_family, font_family_options(), class: "form-control", prompt: "Default (#{default_font_display_name()})" %> - Applies to all your recordings that don't explicitly override this. + +
+
+ <%= submit "Update", class: "btn btn-primary" %>
+ <% end %> + + <%= form_for @changeset, Routes.user_path(@conn, :update), [class: "simple_form form-horizontal", novalidate: "novalidate", role: "form"], fn f -> %> + Defaults + +

+ The settings below control the defaults for your uploaded recordings. +
+
+

- <%= label f, :asciicasts_private_by_default, "New recording visibility", class: "col-3 radio_buttons optional col-form-label" %> + <%= label f, :asciicasts_private_by_default, "Recording visibility", class: "col-3 radio_buttons optional col-form-label" %>
<%= radio_button f, :asciicasts_private_by_default, false, class: "radio_buttons optional form-check-input" %> - <%= label f, :asciicasts_private_by_default, "public", for: "user_asciicasts_private_by_default_false", class: "form-check-label" %> + <%= label f, :asciicasts_private_by_default, "Public", for: "user_asciicasts_private_by_default_false", class: "form-check-label" %>
<%= radio_button f, :asciicasts_private_by_default, true, class: "radio_buttons optional form-check-input" %> - <%= label f, :asciicasts_private_by_default, "secret - unlisted, accessible via secret link", for: "user_asciicasts_private_by_default_true", class: "form-check-label" %> + <%= label f, :asciicasts_private_by_default, "Secret - unlisted, accessible via secret link", for: "user_asciicasts_private_by_default_true", class: "form-check-label" %>
- Applies to all *new* recordings + Applies to *new* uploads. Existing recordings are not affected by changes to this setting. +
+
+ +
+ <%= label f, :theme_name, "Terminal theme", class: "col-3 select optional col-form-label" %> +
+ <%= select f, :theme_name, theme_options(), class: "select optional form-control", prompt: "Default (asciinema)" %> + Applies to all your recordings that don't explicitly override this. +
+
+ +
+ <%= label f, :terminal_font_family, "Terminal font family", class: "col-sm-4 col-md-3 col-form-label" %> +
+ <%= select f, :terminal_font_family, font_family_options(), class: "form-control", prompt: "Default (#{default_font_display_name()})" %> + Applies to all your recordings that don't explicitly override this.
@@ -63,8 +93,7 @@

- <%= submit "Save", class: "btn btn-primary" %> - <%= link "Cancel", to: profile_path(@conn), class: "btn" %> + <%= submit "Update", class: "btn btn-primary" %>
<% end %> @@ -73,35 +102,61 @@
- Recorder tokens +
+ CLI - <%= if present?(@api_tokens) do %> -

- The following recorder tokens have been associated with your account: -

+

To associate the uploaded recordings with your account, you need to + authenticate asciinema CLI on every new system from which you upload.

-
    - <%= for t <- active_tokens(@api_tokens) do %> -
  • <%= t.token %> registered <%= time_tag(t.inserted_at) %> - <%= link "Revoke", to: Routes.api_token_path(@conn, :delete, t), method: "delete", data: [confirm: "Are you sure?"] %>
  • - <% end %> -
- -
    - <%= for t <- revoked_tokens(@api_tokens) do %> -
  • <%= t.token %> registered <%= time_ago_tag(t.inserted_at) %>, revoked <%= time_ago_tag(t.revoked_at) %> - <% end %> -
- <% else %> -

- If you want your recordings to be assigned to your profile - you have to register your local recorder token. -

+

Run asciinema auth to do this. For more information see the documentation.

-

- There is currently no recorder token associated with your account. - Run asciinema auth in your terminal to register one. -

- <% end %> + <%= if present?(@api_tokens) do %> +

+ The following asciinema CLI installations have been authenticated with your account: +

+ + + + + + + + + <%= for t <- active_tokens(@api_tokens) do %> + + + + + + <% end %> + + <%= for t <- revoked_tokens(@api_tokens) do %> + + + + + + <% end %> +
Installation IDRegistered at
+ <%= t.token %> + + <%= time_tag(t.inserted_at) %> + + <%= link "Revoke", to: Routes.api_token_path(@conn, :delete, t), class: "btn btn-danger btn-sm", method: "delete", data: [confirm: "Are you sure? This will prevent future uploads from that system."] %> +
+ <%= t.token %> + + <%= time_tag(t.inserted_at) %> + + Revoked <%= time_ago_tag(t.revoked_at) %> +
+ +

The installation ID of your local system is stored in the + $HOME/.config/asciinema/install-id file.

+ <% else %> +

There is currently no CLI authenticated with this account.

+ <% end %> +
diff --git a/test/controllers/user_controller_test.exs b/test/controllers/user_controller_test.exs index 918045ba2..93e411c87 100644 --- a/test/controllers/user_controller_test.exs +++ b/test/controllers/user_controller_test.exs @@ -94,7 +94,7 @@ defmodule Asciinema.UserControllerTest do user = insert(:user) conn = log_in(conn, user) conn = get(conn, "/user/edit") - assert html_response(conn, 200) =~ "Save" + assert html_response(conn, 200) =~ "Update" end test "update name", %{conn: conn} do @@ -102,9 +102,9 @@ defmodule Asciinema.UserControllerTest do conn = log_in(conn, user) conn = put conn, "/user", %{user: %{name: "Rick"}} location = List.first(get_resp_header(conn, "location")) - assert flash(conn, :info) =~ ~r/saved/i + assert flash(conn, :info) =~ ~r/updated/i assert response(conn, 302) - assert location == "/~#{user.username}" + assert location == "/user/edit" end end end