mirror of
https://github.com/discourse/discourse.git
synced 2024-11-23 02:50:00 +08:00
FIX: Imported themes should set their color scheme automatically
This commit is contained in:
parent
b3a41878ec
commit
43f3bf71ba
|
@ -177,6 +177,7 @@ class RemoteTheme < ActiveRecord::Base
|
|||
|
||||
def update_theme_color_schemes(theme, schemes)
|
||||
missing_scheme_names = Hash[*theme.color_schemes.pluck(:name, :id).flatten]
|
||||
ordered_schemes = []
|
||||
|
||||
schemes&.each do |name, colors|
|
||||
missing_scheme_names.delete(name)
|
||||
|
@ -189,12 +190,14 @@ class RemoteTheme < ActiveRecord::Base
|
|||
theme.notify_color_change(c)
|
||||
end
|
||||
end
|
||||
ordered_schemes << existing
|
||||
else
|
||||
scheme = theme.color_schemes.build(name: name)
|
||||
ColorScheme.base.colors_hashes.each do |color|
|
||||
override = normalize_override(colors[color[:name]])
|
||||
scheme.color_scheme_colors << ColorSchemeColor.new(name: color[:name], hex: override || color[:hex])
|
||||
end
|
||||
ordered_schemes << scheme
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -202,6 +205,10 @@ class RemoteTheme < ActiveRecord::Base
|
|||
ColorScheme.where(id: missing_scheme_names.values).delete_all
|
||||
# we may have stuff pointed at the incorrect scheme?
|
||||
end
|
||||
|
||||
if theme.new_record?
|
||||
theme.color_scheme = ordered_schemes.first
|
||||
end
|
||||
end
|
||||
|
||||
def github_diff_link
|
||||
|
|
|
@ -102,6 +102,9 @@ describe RemoteTheme do
|
|||
expect(scheme.name).to eq("Amazing")
|
||||
expect(scheme.colors.find_by(name: 'love').hex).to eq('fafafa')
|
||||
|
||||
expect(@theme.color_scheme_id).to eq(scheme.id)
|
||||
@theme.update(color_scheme_id: nil)
|
||||
|
||||
File.write("#{initial_repo}/common/header.html", "I AM UPDATED")
|
||||
File.write("#{initial_repo}/about.json", about_json(love_color: "EAEAEA", about_url: "https://newsite.com/about"))
|
||||
|
||||
|
@ -125,6 +128,7 @@ describe RemoteTheme do
|
|||
scheme = ColorScheme.find_by(theme_id: @theme.id)
|
||||
expect(scheme.name).to eq("Amazing")
|
||||
expect(scheme.colors.find_by(name: 'love').hex).to eq('eaeaea')
|
||||
expect(@theme.color_scheme_id).to eq(nil) # Should only be set on first import
|
||||
|
||||
mapped = Hash[*@theme.theme_fields.map { |f| ["#{f.target_id}-#{f.name}", f.value] }.flatten]
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user