Add language user setting (default: English)
This commit is contained in:
parent
1cfe306373
commit
61f803afe5
3 changed files with 45 additions and 1 deletions
|
|
@ -28,6 +28,7 @@ defmodule Towerops.Accounts.User do
|
|||
field :last_name, :string
|
||||
field :timezone, :string, default: "UTC"
|
||||
field :time_format, :string, default: "24h"
|
||||
field :language, :string, default: "en"
|
||||
field :totp_secret, :binary, redact: true
|
||||
field :totp_verified_at, :utc_datetime, virtual: true
|
||||
field :privacy_policy_consent, :boolean, virtual: true
|
||||
|
|
@ -110,11 +111,12 @@ defmodule Towerops.Accounts.User do
|
|||
"""
|
||||
def profile_changeset(user, attrs) do
|
||||
user
|
||||
|> cast(attrs, [:first_name, :last_name, :timezone, :time_format, :default_organization_id])
|
||||
|> cast(attrs, [:first_name, :last_name, :timezone, :time_format, :language, :default_organization_id])
|
||||
|> validate_length(:first_name, max: 100)
|
||||
|> validate_length(:last_name, max: 100)
|
||||
|> validate_length(:timezone, max: 100)
|
||||
|> validate_inclusion(:time_format, ["12h", "24h"])
|
||||
|> validate_inclusion(:language, ["en"])
|
||||
|> foreign_key_constraint(:default_organization_id)
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -288,6 +288,39 @@
|
|||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-span-full">
|
||||
<label
|
||||
for="language"
|
||||
class="block text-sm/6 font-medium text-gray-900 dark:text-white"
|
||||
>
|
||||
Language
|
||||
</label>
|
||||
<div class="mt-2 grid grid-cols-1">
|
||||
<select
|
||||
name={@profile_form[:language].name}
|
||||
id="language"
|
||||
class="col-start-1 row-start-1 w-full appearance-none rounded-md bg-white py-1.5 pr-8 pl-3 text-base text-gray-900 outline-1 -outline-offset-1 outline-gray-300 placeholder:text-gray-400 focus:outline-2 focus:-outline-offset-2 focus:outline-indigo-600 sm:text-sm/6 dark:bg-white/5 dark:text-white dark:outline-white/10 dark:*:bg-gray-800 dark:focus:outline-indigo-500"
|
||||
>
|
||||
<option value="en" selected={@profile_form[:language].value == "en"}>
|
||||
English
|
||||
</option>
|
||||
</select>
|
||||
<svg
|
||||
viewBox="0 0 16 16"
|
||||
fill="currentColor"
|
||||
data-slot="icon"
|
||||
aria-hidden="true"
|
||||
class="pointer-events-none col-start-1 row-start-1 mr-2 size-5 self-center justify-self-end text-gray-400 sm:size-4"
|
||||
>
|
||||
<path
|
||||
fill-rule="evenodd"
|
||||
d="M4.22 6.22a.75.75 0 0 1 1.06 0L8 8.94l2.72-2.72a.75.75 0 1 1 1.06 1.06l-3.25 3.25a.75.75 0 0 1-1.06 0L4.22 7.28a.75.75 0 0 1 0-1.06Z"
|
||||
clip-rule="evenodd"
|
||||
/>
|
||||
</svg>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div :if={@organizations != []} class="col-span-full">
|
||||
<label
|
||||
for="default_organization_id"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,9 @@
|
|||
defmodule Towerops.Repo.Migrations.AddLanguageToUsers do
|
||||
use Ecto.Migration
|
||||
|
||||
def change do
|
||||
alter table(:users) do
|
||||
add :language, :string, default: "en", null: false
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue