mirror of
https://github.com/Retrospring/retrospring.git
synced 2025-01-18 13:56:03 +01:00
Allow users to have multiple themes
This commit is contained in:
parent
92b0382022
commit
d38e96f53b
5 changed files with 25 additions and 7 deletions
|
@ -52,7 +52,7 @@ module ThemeHelper
|
|||
end
|
||||
|
||||
def theme_color
|
||||
theme = active_theme_user&.theme
|
||||
theme = active_theme_user&.active_theme
|
||||
if theme
|
||||
theme.theme_color
|
||||
else
|
||||
|
@ -61,7 +61,7 @@ module ThemeHelper
|
|||
end
|
||||
|
||||
def mobile_theme_color
|
||||
theme = active_theme_user&.theme
|
||||
theme = active_theme_user&.active_theme
|
||||
if theme
|
||||
theme.mobile_theme_color
|
||||
else
|
||||
|
@ -72,7 +72,7 @@ module ThemeHelper
|
|||
def active_theme_user
|
||||
user = @user || @answer&.user # rubocop:disable Rails/HelperInstanceVariable
|
||||
|
||||
if user&.theme.present? && should_show_foreign_theme?
|
||||
if user&.active_theme.present? && should_show_foreign_theme?
|
||||
user
|
||||
elsif user_signed_in?
|
||||
current_user
|
||||
|
|
|
@ -41,13 +41,14 @@ class User < ApplicationRecord
|
|||
has_many :list_memberships, class_name: "ListMember", dependent: :destroy_async
|
||||
has_many :mute_rules, dependent: :destroy_async
|
||||
has_many :anonymous_blocks, dependent: :destroy_async
|
||||
has_many :themes, dependent: :destroy
|
||||
|
||||
has_many :subscriptions, dependent: :destroy_async
|
||||
has_many :totp_recovery_codes, dependent: :destroy_async
|
||||
has_many :web_push_subscriptions, dependent: :destroy_async
|
||||
|
||||
has_one :profile, dependent: :destroy
|
||||
has_one :theme, dependent: :destroy
|
||||
has_one :active_theme, -> { where(active: true) }, class_name: "Theme"
|
||||
|
||||
has_many :bans, class_name: "UserBan", dependent: :destroy_async
|
||||
has_many :banned_users, class_name: "UserBan",
|
||||
|
|
|
@ -4,10 +4,10 @@
|
|||
%p.lead= t(".lead")
|
||||
= t(".body_html")
|
||||
|
||||
- if current_user.theme
|
||||
- if current_user.active_theme
|
||||
.pull-right
|
||||
= link_to t(".delete"), settings_theme_path, data: { turbo_confirm: t("voc.confirm"), turbo_method: :delete }, tabindex: -1, class: "btn btn-danger"
|
||||
= bootstrap_form_for(current_user.theme || Theme.new,
|
||||
= bootstrap_form_for(current_user.active_theme || Theme.new,
|
||||
html: { id: "update" },
|
||||
method: :patch,
|
||||
data: { turbo: false, controller: "theme", action: "theme#submit" }) do |f|
|
||||
|
|
14
db/migrate/20231220130817_allow_multiple_themes.rb
Normal file
14
db/migrate/20231220130817_allow_multiple_themes.rb
Normal file
|
@ -0,0 +1,14 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class AllowMultipleThemes < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
change_table :themes, bulk: true do |t|
|
||||
t.boolean :active, default: true, null: false
|
||||
t.string :name, null: true
|
||||
end
|
||||
|
||||
change_column :themes, :active, :boolean, default: false, null: false
|
||||
|
||||
add_index :themes, %i[user_id active]
|
||||
end
|
||||
end
|
|
@ -10,7 +10,7 @@
|
|||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_12_20_100445) do
|
||||
ActiveRecord::Schema[7.0].define(version: 2023_12_20_130817) do
|
||||
# These are extensions that must be enabled in order to support this database
|
||||
enable_extension "plpgsql"
|
||||
|
||||
|
@ -292,6 +292,9 @@ ActiveRecord::Schema[7.0].define(version: 2023_12_20_100445) do
|
|||
t.integer "input_placeholder", default: 7107965, null: false
|
||||
t.integer "raised_text", default: 0, null: false
|
||||
t.integer "raised_accent_text", default: 0, null: false
|
||||
t.boolean "active", default: false, null: false
|
||||
t.string "name"
|
||||
t.index ["user_id", "active"], name: "index_themes_on_user_id_and_active"
|
||||
t.index ["user_id"], name: "index_themes_on_user_id"
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue