]> git.openstreetmap.org Git - rails.git/commitdiff
Make a generic preferred color scheme method
authorAnton Khorev <tony29@yandex.ru>
Sun, 1 Dec 2024 00:04:09 +0000 (03:04 +0300)
committerAnton Khorev <tony29@yandex.ru>
Sun, 1 Dec 2024 01:58:00 +0000 (04:58 +0300)
app/controllers/application_controller.rb
app/views/layouts/_head.html.erb
app/views/layouts/site.html.erb
app/views/preferences/edit.html.erb
app/views/preferences/show.html.erb

index 56d9a6763e0a4c3d3b59378bdcddd40d46f4dac0..5bfec4ab62f219ac3cad9d114ee8d4606d84e6ae 100644 (file)
@@ -281,15 +281,15 @@ class ApplicationController < ActionController::Base
     end
   end
 
     end
   end
 
-  def preferred_site_color_scheme
+  def preferred_color_scheme(subject)
     if current_user
     if current_user
-      current_user.preferences.find_by(:k => "site.color_scheme")&.v || "auto"
+      current_user.preferences.find_by(:k => "#{subject}.color_scheme")&.v || "auto"
     else
       "auto"
     end
   end
 
     else
       "auto"
     end
   end
 
-  helper_method :preferred_editor, :preferred_site_color_scheme
+  helper_method :preferred_editor, :preferred_color_scheme
 
   def update_totp
     if Settings.key?(:totp_key)
 
   def update_totp
     if Settings.key?(:totp_key)
index 8cab522236d4b20cc921f796cb40aff33a92847b..bab19c217191fb089bc1681a5e93851c3df965dd 100644 (file)
@@ -5,7 +5,7 @@
   <%= javascript_include_tag "turbo", :type => "module" %>
   <%= javascript_include_tag "application" %>
   <%= javascript_include_tag "i18n/#{I18n.locale}" %>
   <%= javascript_include_tag "turbo", :type => "module" %>
   <%= javascript_include_tag "application" %>
   <%= javascript_include_tag "i18n/#{I18n.locale}" %>
-  <% if preferred_site_color_scheme == "auto" %>
+  <% if preferred_color_scheme(:site) == "auto" %>
     <%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %>
   <% else %>
     <%= stylesheet_link_tag "screen-manual-#{dir}", :media => "screen" %>
     <%= stylesheet_link_tag "screen-auto-#{dir}", :media => "screen" %>
   <% else %>
     <%= stylesheet_link_tag "screen-manual-#{dir}", :media => "screen" %>
index dd573d476bcd11b53882bc2f20066693fb7cbc26..6898b6f0bbff447522f1b7394cc55cfd38d99b5d 100644 (file)
@@ -1,5 +1,7 @@
 <!DOCTYPE html>
 <!DOCTYPE html>
-<%= tag.html :lang => I18n.locale, :dir => dir, :data => { :bs_theme => (preferred_site_color_scheme if preferred_site_color_scheme != "auto") } do %>
+<%= tag.html :lang => I18n.locale,
+             :dir => dir,
+             :data => { :bs_theme => (preferred_color_scheme(:site) if preferred_color_scheme(:site) != "auto") } do %>
   <%= render :partial => "layouts/head" %>
   <body class="<%= body_class %>">
     <%= render :partial => "layouts/header" %>
   <%= render :partial => "layouts/head" %>
   <body class="<%= body_class %>">
     <%= render :partial => "layouts/header" %>
index 34cb72046d74efe73e8e050c737eb4a60df3aee7..2c3cd4ba0d961711e81002489a9b478a7163e41f 100644 (file)
@@ -11,7 +11,7 @@
     <%= label_tag "site_color_scheme", t("preferences.show.preferred_site_color_scheme"), :class => "form-label" %>
     <%= select_tag "site_color_scheme",
                    options_for_select(%w[auto light dark].map { |scheme| [t("preferences.show.site_color_schemes.#{scheme}"), scheme] },
     <%= label_tag "site_color_scheme", t("preferences.show.preferred_site_color_scheme"), :class => "form-label" %>
     <%= select_tag "site_color_scheme",
                    options_for_select(%w[auto light dark].map { |scheme| [t("preferences.show.site_color_schemes.#{scheme}"), scheme] },
-                                      preferred_site_color_scheme),
+                                      preferred_color_scheme(:site)),
                    :class => "form-select" %>
   </div>
 
                    :class => "form-select" %>
   </div>
 
index 4b772fba907fe051e2e86f625f04f948f8dd3ba3..7681638ed95057f5e9092fb326ebaf5113bc1c30 100644 (file)
@@ -23,7 +23,7 @@
 
   <dt class="col-sm-4"><%= t ".preferred_site_color_scheme" %></dt>
   <dd class="col-sm-8">
 
   <dt class="col-sm-4"><%= t ".preferred_site_color_scheme" %></dt>
   <dd class="col-sm-8">
-    <%= t ".site_color_schemes.#{preferred_site_color_scheme}" %>
+    <%= t ".site_color_schemes.#{preferred_color_scheme(:site)}" %>
   </dd>
 </dl>
 
   </dd>
 </dl>