Simplify theme and color scheme seeding (#10872)

Now that we have support for user-selectable color schemes, it makes sense
to simplify seeding and theme updates in the wizard. 

We now:

- seed only one theme, named "Default" (previously "Light")
- seed a user-selectable Dark color scheme
- rename the "Themes" wizard step to "Colors"
- update the default theme's color scheme if a default is set
(a new theme is created if there is no default)
This commit is contained in:
Penar Musaraj
2020-10-14 10:18:02 -04:00
committed by GitHub
parent d77e31b7e9
commit 74de7a49f5
8 changed files with 35 additions and 40 deletions

View File

@ -181,26 +181,22 @@ class Wizard
next unless scheme_name.present? && ColorScheme.is_base?(scheme_name)
name = I18n.t("color_schemes.#{scheme_name.downcase.gsub(' ', '_')}_theme_name")
theme = nil
scheme = ColorScheme.find_by(base_scheme_id: scheme_name, via_wizard: true)
is_light_theme = (scheme_name == ColorScheme::LIGHT_THEME_ID)
scheme ||= ColorScheme.create_from_base(name: name, via_wizard: true, base_scheme_id: scheme_name)
themes = Theme.where(color_scheme_id: scheme.id).order(:id).to_a
if is_light_theme
themes = (themes || []).concat(Theme.where(color_scheme_id: nil).order(:id).to_a)
themes.sort_by(&:id)
if default_theme
default_theme.color_scheme_id = scheme.id
default_theme.save!
else
theme = Theme.create!(
name: name,
user_id: @wizard.user.id,
color_scheme_id: scheme.id
)
theme.set_default!
end
theme = themes.find(&:default?)
theme ||= themes.first
theme ||= Theme.create!(
name: name,
user_id: @wizard.user.id,
color_scheme_id: scheme.id
)
theme.set_default!
end
end