From 3d5d899094ecf389ce6cf31a6f33dcf1894e662d Mon Sep 17 00:00:00 2001 From: Thibaut Girka Date: Mon, 8 Oct 2018 15:00:27 +0200 Subject: [PATCH] Allow selecting both default flavour and theme Fixes #672 --- app/controllers/admin/settings_controller.rb | 9 ++++++++- app/lib/themes.rb | 6 ++++++ app/models/form/admin_settings.rb | 4 ++++ app/views/admin/settings/edit.html.haml | 2 +- 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/app/controllers/admin/settings_controller.rb b/app/controllers/admin/settings_controller.rb index 46e9b2c0752..fe2720c4859 100644 --- a/app/controllers/admin/settings_controller.rb +++ b/app/controllers/admin/settings_controller.rb @@ -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) diff --git a/app/lib/themes.rb b/app/lib/themes.rb index 55824a5c4ee..2147904e4e4 100644 --- a/app/lib/themes.rb +++ b/app/lib/themes.rb @@ -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 diff --git a/app/models/form/admin_settings.rb b/app/models/form/admin_settings.rb index 9ea4ed3224b..8a39e09b7a5 100644 --- a/app/models/form/admin_settings.rb +++ b/app/models/form/admin_settings.rb @@ -48,4 +48,8 @@ class Form::AdminSettings :custom_css=, to: Setting ) + + def flavour_and_skin + "#{Setting.flavour}/#{Setting.skin}" + end end diff --git a/app/views/admin/settings/edit.html.haml b/app/views/admin/settings/edit.html.haml index 361e249e070..b8255553449 100644 --- a/app/views/admin/settings/edit.html.haml +++ b/app/views/admin/settings/edit.html.haml @@ -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