From bf51d68f15aeb90dab9d92ee47deefb305a4dd85 Mon Sep 17 00:00:00 2001 From: evazion Date: Thu, 19 Sep 2019 13:20:06 -0500 Subject: [PATCH] users: add dark mode account setting (fix #4158). --- app/controllers/users_controller.rb | 2 +- app/helpers/application_helper.rb | 2 +- app/models/user.rb | 2 ++ app/views/users/edit.html.erb | 14 +++++++------- db/migrate/20190919175836_add_theme_to_users.rb | 5 +++++ db/structure.sql | 6 ++++-- 6 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 db/migrate/20190919175836_add_theme_to_users.rb diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index c078eb908..9fb1ab28f 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -101,7 +101,7 @@ class UsersController < ApplicationController permitted_params = %i[ password old_password password_confirmation email comment_threshold default_image_size favorite_tags blacklisted_tags - time_zone per_page custom_style + time_zone per_page custom_style theme receive_email_notifications always_resize_images enable_post_navigation new_post_navigation_layout enable_privacy_mode diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 53b506749..12481db75 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -174,7 +174,7 @@ module ApplicationHelper end def body_attributes(user = CurrentUser.user) - attributes = [:id, :name, :level, :level_string, :can_approve_posts?, :can_upload_free?] + attributes = [:id, :name, :level, :level_string, :theme, :can_approve_posts?, :can_upload_free?] attributes += User::Roles.map { |role| :"is_#{role}?" } controller_param = params[:controller].parameterize.dasherize diff --git a/app/models/user.rb b/app/models/user.rb index cd395f277..9341105ae 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -114,6 +114,8 @@ class User < ApplicationRecord belongs_to :inviter, class_name: "User", optional: true accepts_nested_attributes_for :dmail_filter + enum theme: { light: 0, dark: 100 }, _suffix: true + module BanMethods def validate_ip_addr_is_not_banned if IpBan.is_banned?(CurrentUser.ip_addr) diff --git a/app/views/users/edit.html.erb b/app/views/users/edit.html.erb index 5df373ea5..a6f018cbf 100644 --- a/app/views/users/edit.html.erb +++ b/app/views/users/edit.html.erb @@ -31,17 +31,17 @@

- <%= f.input :time_zone, :include_blank => false %> - <%= f.input :receive_email_notifications, :as => :select, :include_blank => false, :collection => [["Yes", "true"], ["No", "false"]] %> - <%= f.input :comment_threshold, :hint => "Comments below this score will be hidden by default" %> - <%= f.input :default_image_size, :hint => "Show original image or show resized #{Danbooru.config.large_image_width} pixel version", :label => "Default image width", :collection => [["850px", "large"], ["original", "original"]], :include_blank => false %> + <%= f.input :theme, collection: User.themes.keys, include_blank: false, hint: "The site's colorscheme (light mode or dark mode)." %> + <%= f.input :enable_safe_mode, label: "Safe mode", hint: "Show only safe images. Hide questionable and explicit images.", as: :select, include_blank: false, collection: [["Yes", "true"], ["No", "false"]] %> <% if CurrentUser.user.is_gold? %> <%= f.input :per_page, :label => "Posts per page", :as => :select, :hint => "Number of thumbnails per page", :collection => (1..PostSets::Post::MAX_PER_PAGE), :include_blank => false %> <% end %> - - <%= f.input :enable_safe_mode, :label => "Safe mode", :hint => "Show only safe images. Hide questionable and explicit images.", :as => :select, :include_blank => false, :collection => [["Yes", "true"], ["No", "false"]] %> - <%= f.input :blacklisted_tags, :hint => "Posts with these tags will be hidden. Put each tag on a separate line. View help.".html_safe, :input_html => {:size => "40x5", :data => {:autocomplete => "tag-query"}} %> + <%= f.input :default_image_size, hint: "Show full original images or resized #{Danbooru.config.large_image_width}px width samples.", label: "Default image width", collection: [["850px", "large"], ["original", "original"]], include_blank: false %> + <%= f.input :receive_email_notifications, as: :select, include_blank: false, collection: [["Yes", "true"], ["No", "false"]], hint: "Receive an email when you receive a new dmail." %> + <%= f.input :time_zone, include_blank: false, hint: "The timezone to use for timestamps." %> + <%= f.input :comment_threshold, hint: "Comments below this score will be hidden by default" %> + <%= f.input :blacklisted_tags, hint: "Posts with these tags will be hidden. Put each tag on a separate line. View help.".html_safe, :input_html => {:size => "40x5", :data => {:autocomplete => "tag-query"}} %>
diff --git a/db/migrate/20190919175836_add_theme_to_users.rb b/db/migrate/20190919175836_add_theme_to_users.rb new file mode 100644 index 000000000..99e2887f9 --- /dev/null +++ b/db/migrate/20190919175836_add_theme_to_users.rb @@ -0,0 +1,5 @@ +class AddThemeToUsers < ActiveRecord::Migration[6.0] + def change + add_column :users, :theme, :integer, default: 0, null: false + end +end diff --git a/db/structure.sql b/db/structure.sql index ad93a29c2..7892a2340 100644 --- a/db/structure.sql +++ b/db/structure.sql @@ -3108,7 +3108,8 @@ furry -rating:s'::text, custom_style text, bit_prefs bigint DEFAULT 0 NOT NULL, last_ip_addr inet, - unread_dmail_count integer DEFAULT 0 NOT NULL + unread_dmail_count integer DEFAULT 0 NOT NULL, + theme integer DEFAULT 0 NOT NULL ); @@ -7337,6 +7338,7 @@ INSERT INTO "schema_migrations" (version) VALUES ('20190829055758'), ('20190902224045'), ('20190908031103'), -('20190908035317'); +('20190908035317'), +('20190919175836');