Allow selecting both default flavour and theme

Fixes #672
pull/779/head
Thibaut Girka 2018-10-08 15:00:27 +02:00 committed by ThibG
parent fac529975b
commit 3d5d899094
4 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,7 @@ module Admin
bootstrap_timeline_accounts
flavour
skin
flavour_and_skin
thumbnail
hero
mascot
@ -54,7 +55,13 @@ module Admin
def update
authorize :settings, :update?
settings_params.each do |key, value|
settings = settings_params
flavours_and_skin = settings.delete('flavour_and_skin')
if flavours_and_skin
settings['flavour'], settings['skin'] = flavours_and_skin.split('/', 2)
end
settings.each do |key, value|
if UPLOAD_SETTINGS.include?(key)
upload = SiteUpload.where(var: key).first_or_initialize(var: key)
upload.update(file: value)

View File

@ -80,4 +80,10 @@ class Themes
def skins_for(name)
@conf[name]['skin'].keys
end
def flavours_and_skins
flavours.map do |flavour|
[flavour, skins_for(flavour).map{ |skin| [flavour, skin] }]
end
end
end

View File

@ -48,4 +48,8 @@ class Form::AdminSettings
:custom_css=,
to: Setting
)
def flavour_and_skin
"#{Setting.flavour}/#{Setting.skin}"
end
end

View File

@ -7,7 +7,7 @@
= f.input :site_title, wrapper: :with_label, label: t('admin.settings.site_title')
.fields-group
= f.input :flavour, collection: Themes.instance.flavours, label_method: lambda { |flavour| I18n.t("flavours.#{flavour}.name", default: flavour) }, wrapper: :with_label, include_blank: false
= f.input :flavour_and_skin, collection: Themes.instance.flavours_and_skins, group_label_method: lambda { |(flavour, _)| I18n.t("flavours.#{flavour}.name", default: flavour) }, wrapper: :with_label, include_blank: false, as: :grouped_select, label_method: :last, value_method: lambda { |value| value.join('/') }, group_method: :last
.fields-row
.fields-row__column.fields-row__column-6.fields-group