Add server setting for default theme color (#41153)
This commit is contained in:
1 parent
e7f05132c0
commit
3778dd6bc6
5 files changed
+35
-10
No files matched your search
@@ -81,7 +81,8 @@ module ThemeHelper
|
||||
user_color = current_user&.setting_theme_color
|
||||
return user_color if user_color && available_colors.include?(user_color)
|
||||
|
||||
# TODO: server setting
|
||||
color = Setting.theme_color
|
||||
return color if color && available_colors.include?(color)
|
||||
|
||||
available_colors.first
|
||||
end
|
||||
|
||||
@@ -185,7 +185,9 @@ async function loaded() {
|
||||
);
|
||||
|
||||
updateThemeColorsFromTheme(
|
||||
document.querySelector('#user_settings_attributes_theme'),
|
||||
document.querySelector(
|
||||
'#user_settings_attributes_theme, #form_admin_settings_theme',
|
||||
),
|
||||
);
|
||||
|
||||
truncateRuleHints();
|
||||
@@ -491,12 +493,18 @@ const updateThemeColorsFromTheme = (themeSelect: EventTarget | null) => {
|
||||
>;
|
||||
|
||||
const themeColorDiv = themeSelect.form.querySelector<HTMLDivElement>(
|
||||
'.user_settings_web\\.theme_color .label_input__wrapper',
|
||||
'.user_settings_web\\.theme_color .label_input__wrapper, .form_admin_settings_theme_color .label_input__wrapper',
|
||||
);
|
||||
if (!themeColorDiv) return;
|
||||
|
||||
const hiddenInput =
|
||||
themeColorDiv.querySelector<HTMLInputElement>('input[type=hidden]');
|
||||
if (!hiddenInput) return;
|
||||
|
||||
const inputName = hiddenInput.name;
|
||||
|
||||
const selectedColor = themeSelect.form.querySelector<HTMLInputElement>(
|
||||
'input[name="user[settings_attributes][web.theme_color]"]:checked',
|
||||
`input[name="${inputName}"]:checked`,
|
||||
)?.value;
|
||||
|
||||
// Remove existing fields
|
||||
@@ -519,7 +527,7 @@ const updateThemeColorsFromTheme = (themeSelect: EventTarget | null) => {
|
||||
newInputElement.className = 'radio_buttons optional';
|
||||
newInputElement.type = 'radio';
|
||||
newInputElement.value = color;
|
||||
newInputElement.name = 'user[settings_attributes][web.theme_color]';
|
||||
newInputElement.name = inputName;
|
||||
newInputElement.id = `user_settings_attributes_web.theme_color_${color}`;
|
||||
newInputElement.checked = color === selectedColor;
|
||||
|
||||
@@ -541,9 +549,13 @@ const updateThemeColorsFromTheme = (themeSelect: EventTarget | null) => {
|
||||
}
|
||||
};
|
||||
|
||||
on('change', '#user_settings_attributes_theme', ({ target }) => {
|
||||
updateThemeColorsFromTheme(target);
|
||||
});
|
||||
on(
|
||||
'change',
|
||||
'#user_settings_attributes_theme, #form_admin_settings_theme',
|
||||
({ target }) => {
|
||||
updateThemeColorsFromTheme(target);
|
||||
},
|
||||
);
|
||||
|
||||
const updateDefaultQuotePrivacyFromSplitPrivacy = () => {
|
||||
const privacySelect = document.querySelector<HTMLSelectElement>(
|
||||
|
||||
@@ -50,6 +50,7 @@ class Form::AdminSettings
|
||||
opt_in_server_directory
|
||||
opt_in_server_recommendation
|
||||
postpone_confirmation_emails
|
||||
theme_color
|
||||
).freeze
|
||||
|
||||
INTEGER_KEYS = %i(
|
||||
|
||||
@@ -12,11 +12,21 @@
|
||||
|
||||
.fields-group
|
||||
= f.input :theme,
|
||||
collection: Themes.instance.names,
|
||||
collection: themes_select_collection,
|
||||
include_blank: false,
|
||||
label_method: ->(theme) { I18n.t("themes.#{theme}", default: theme) },
|
||||
wrapper: :with_label
|
||||
|
||||
.input.horizontal-options
|
||||
= f.input :theme_color,
|
||||
as: :radio_buttons,
|
||||
collection: available_theme_colors(f.object.theme),
|
||||
hint: false,
|
||||
include_blank: false,
|
||||
label_method: ->(color) { I18n.t("color_theme.#{color}", default: color) },
|
||||
label: I18n.t('simple_form.labels.defaults.setting_theme_color'),
|
||||
wrapper: :with_label,
|
||||
required: false
|
||||
|
||||
.fields-group
|
||||
= f.input :custom_css,
|
||||
as: :text,
|
||||
|
||||
@@ -21,6 +21,7 @@ defaults: &defaults
|
||||
preview_sensitive_media: false
|
||||
noindex: false
|
||||
theme: 'default'
|
||||
theme_color: 'indigo'
|
||||
thumbnail_description: ''
|
||||
trends: true
|
||||
trendable_by_default: false
|
||||
|
||||
Reference in new issue
Block a user