From 1db4117030ac69b1083ddfe7390dedb02cede421 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jun 2019 03:39:24 +0200 Subject: Change preferences page into appearance, notifications, and other (#10977) --- .../settings/preferences/appearance/show.html.haml | 41 ++++++++++++++++++ .../preferences/notifications/show.html.haml | 30 ++++++++++++++ app/views/settings/preferences/show.html.haml | 48 ++++------------------ 3 files changed, 80 insertions(+), 39 deletions(-) create mode 100644 app/views/settings/preferences/appearance/show.html.haml create mode 100644 app/views/settings/preferences/notifications/show.html.haml (limited to 'app/views/settings/preferences') diff --git a/app/views/settings/preferences/appearance/show.html.haml b/app/views/settings/preferences/appearance/show.html.haml new file mode 100644 index 000000000..10f009264 --- /dev/null +++ b/app/views/settings/preferences/appearance/show.html.haml @@ -0,0 +1,41 @@ +- content_for :page_title do + = t('settings.appearance') + += simple_form_for current_user, url: settings_preferences_appearance_path, html: { method: :put } do |f| + .fields-row + .fields-group.fields-row__column.fields-row__column-6 + = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale, hint: false + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: false + + %h4= t 'appearance.advanced_web_interface' + + %p.hint= t 'appearance.advanced_web_interface_hint' + + .fields-group + = f.input :setting_advanced_layout, as: :boolean, wrapper: :with_label, hint: false + + %h4= t 'appearance.animations_and_accessibility' + + .fields-group + = f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label, recommended: true + = f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label + = f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label + + %h4= t 'appearance.confirmation_dialogs' + + .fields-group + = f.input :setting_unfollow_modal, as: :boolean, wrapper: :with_label + = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label + = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label + + %h4= t 'appearance.sensitive_content' + + .fields-group + = f.input :setting_display_media, collection: ['default', 'show_all', 'hide_all'],label_method: lambda { |item| t("simple_form.hints.defaults.setting_display_media_#{item}") }, hint: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li', wrapper: :with_floating_label + + .fields-group + = f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label + + .actions + = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/settings/preferences/notifications/show.html.haml b/app/views/settings/preferences/notifications/show.html.haml new file mode 100644 index 000000000..acc646fc3 --- /dev/null +++ b/app/views/settings/preferences/notifications/show.html.haml @@ -0,0 +1,30 @@ +- content_for :page_title do + = t('settings.notifications') + += simple_form_for current_user, url: settings_preferences_notifications_path, html: { method: :put } do |f| + = render 'shared/error_messages', object: current_user + + .fields-group + = f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff| + = ff.input :follow, as: :boolean, wrapper: :with_label + = ff.input :follow_request, as: :boolean, wrapper: :with_label + = ff.input :reblog, as: :boolean, wrapper: :with_label + = ff.input :favourite, as: :boolean, wrapper: :with_label + = ff.input :mention, as: :boolean, wrapper: :with_label + + - if current_user.staff? + = ff.input :report, as: :boolean, wrapper: :with_label + = ff.input :pending_account, as: :boolean, wrapper: :with_label + + .fields-group + = f.simple_fields_for :notification_emails, hash_to_object(current_user.settings.notification_emails) do |ff| + = ff.input :digest, as: :boolean, wrapper: :with_label + + .fields-group + = f.simple_fields_for :interactions, hash_to_object(current_user.settings.interactions) do |ff| + = ff.input :must_be_follower, as: :boolean, wrapper: :with_label + = ff.input :must_be_following, as: :boolean, wrapper: :with_label + = ff.input :must_be_following_dm, as: :boolean, wrapper: :with_label + + .actions + = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml index 35b660a68..c966a16bc 100644 --- a/app/views/settings/preferences/show.html.haml +++ b/app/views/settings/preferences/show.html.haml @@ -1,34 +1,9 @@ - content_for :page_title do = t('settings.preferences') -%ul.quick-nav - %li= link_to t('preferences.languages'), '#settings_languages' - %li= link_to t('preferences.publishing'), '#settings_publishing' - %li= link_to t('preferences.other'), '#settings_other' - %li= link_to t('preferences.web'), '#settings_web' - %li= link_to t('settings.notifications'), settings_notifications_path - = simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| = render 'shared/error_messages', object: current_user - .fields-row#settings_languages - .fields-group.fields-row__column.fields-row__column-6 - = f.input :locale, collection: I18n.available_locales, wrapper: :with_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, selected: I18n.locale - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false - - .fields-group - = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' - - %hr#settings_publishing/ - - .fields-group - = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_floating_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), content_tag(:span, I18n.t("statuses.visibilities.#{visibility}_long"), class: 'hint')]) }, required: false, as: :radio_buttons, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' - - = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label - - %hr#settings_other/ - .fields-group = f.input :setting_noindex, as: :boolean, wrapper: :with_label @@ -36,32 +11,27 @@ = f.input :setting_hide_network, as: :boolean, wrapper: :with_label .fields-group - = f.input :setting_show_application, as: :boolean, wrapper: :with_label + = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true - %hr#settings_web/ + %h4= t 'preferences.posting_defaults' .fields-row .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_theme, collection: Themes.instance.names, label_method: lambda { |theme| I18n.t("themes.#{theme}", default: theme) }, wrapper: :with_label, include_blank: false, hint: false + = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false + .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_display_media, collection: ['default', 'show_all', 'hide_all'], wrapper: :with_label, include_blank: false, label_method: lambda { |item| t("simple_form.hints.defaults.setting_display_media_#{item}") }, hint: false + = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false, hint: false .fields-group - = f.input :setting_advanced_layout, as: :boolean, wrapper: :with_label + = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label .fields-group - = f.input :setting_unfollow_modal, as: :boolean, wrapper: :with_label - = f.input :setting_boost_modal, as: :boolean, wrapper: :with_label - = f.input :setting_delete_modal, as: :boolean, wrapper: :with_label + = f.input :setting_show_application, as: :boolean, wrapper: :with_label, recommended: true - .fields-group - = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label + %h4= t 'preferences.public_timelines' .fields-group - = f.input :setting_auto_play_gif, as: :boolean, wrapper: :with_label - = f.input :setting_expand_spoilers, as: :boolean, wrapper: :with_label - = f.input :setting_reduce_motion, as: :boolean, wrapper: :with_label - = f.input :setting_system_font_ui, as: :boolean, wrapper: :with_label + = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' .actions = f.button :button, t('generic.save_changes'), type: :submit -- cgit From 560ec24e585face30ee99d5bba39a02948fd118f Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Fri, 7 Jun 2019 16:51:08 +0200 Subject: Change /settings/preferences to redirect to appearance, add /settings/preferences/other (#10988) --- .../settings/preferences/other_controller.rb | 9 +++++ .../settings/preferences/other/show.html.haml | 37 +++++++++++++++++ app/views/settings/preferences/show.html.haml | 37 ----------------- config/navigation.rb | 4 +- config/routes.rb | 6 ++- .../settings/preferences/other_controller_spec.rb | 46 ++++++++++++++++++++++ .../settings/preferences_controller_spec.rb | 46 ---------------------- 7 files changed, 98 insertions(+), 87 deletions(-) create mode 100644 app/controllers/settings/preferences/other_controller.rb create mode 100644 app/views/settings/preferences/other/show.html.haml delete mode 100644 app/views/settings/preferences/show.html.haml create mode 100644 spec/controllers/settings/preferences/other_controller_spec.rb delete mode 100644 spec/controllers/settings/preferences_controller_spec.rb (limited to 'app/views/settings/preferences') diff --git a/app/controllers/settings/preferences/other_controller.rb b/app/controllers/settings/preferences/other_controller.rb new file mode 100644 index 000000000..07eb89a76 --- /dev/null +++ b/app/controllers/settings/preferences/other_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +class Settings::Preferences::OtherController < Settings::PreferencesController + private + + def after_update_redirect_path + settings_preferences_other_path + end +end diff --git a/app/views/settings/preferences/other/show.html.haml b/app/views/settings/preferences/other/show.html.haml new file mode 100644 index 000000000..c966a16bc --- /dev/null +++ b/app/views/settings/preferences/other/show.html.haml @@ -0,0 +1,37 @@ +- content_for :page_title do + = t('settings.preferences') + += simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| + = render 'shared/error_messages', object: current_user + + .fields-group + = f.input :setting_noindex, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_hide_network, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true + + %h4= t 'preferences.posting_defaults' + + .fields-row + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false + + .fields-group.fields-row__column.fields-row__column-6 + = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false, hint: false + + .fields-group + = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label + + .fields-group + = f.input :setting_show_application, as: :boolean, wrapper: :with_label, recommended: true + + %h4= t 'preferences.public_timelines' + + .fields-group + = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' + + .actions + = f.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/settings/preferences/show.html.haml b/app/views/settings/preferences/show.html.haml deleted file mode 100644 index c966a16bc..000000000 --- a/app/views/settings/preferences/show.html.haml +++ /dev/null @@ -1,37 +0,0 @@ -- content_for :page_title do - = t('settings.preferences') - -= simple_form_for current_user, url: settings_preferences_path, html: { method: :put } do |f| - = render 'shared/error_messages', object: current_user - - .fields-group - = f.input :setting_noindex, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_hide_network, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_aggregate_reblogs, as: :boolean, wrapper: :with_label, recommended: true - - %h4= t 'preferences.posting_defaults' - - .fields-row - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_default_privacy, collection: Status.selectable_visibilities, wrapper: :with_label, include_blank: false, label_method: lambda { |visibility| safe_join([I18n.t("statuses.visibilities.#{visibility}"), I18n.t("statuses.visibilities.#{visibility}_long")], ' - ') }, required: false, hint: false - - .fields-group.fields-row__column.fields-row__column-6 - = f.input :setting_default_language, collection: [nil] + filterable_languages.sort, wrapper: :with_label, label_method: lambda { |locale| locale.nil? ? I18n.t('statuses.language_detection') : human_locale(locale) }, required: false, include_blank: false, hint: false - - .fields-group - = f.input :setting_default_sensitive, as: :boolean, wrapper: :with_label - - .fields-group - = f.input :setting_show_application, as: :boolean, wrapper: :with_label, recommended: true - - %h4= t 'preferences.public_timelines' - - .fields-group - = f.input :chosen_languages, collection: filterable_languages.sort, wrapper: :with_block_label, include_blank: false, label_method: lambda { |locale| human_locale(locale) }, required: false, as: :check_boxes, collection_wrapper_tag: 'ul', item_wrapper_tag: 'li' - - .actions - = f.button :button, t('generic.save_changes'), type: :submit diff --git a/config/navigation.rb b/config/navigation.rb index 45e5bc562..df1024189 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -10,10 +10,10 @@ SimpleNavigation::Configuration.run do |navigation| s.item :identity_proofs, safe_join([fa_icon('key fw'), t('settings.identity_proofs')]), settings_identity_proofs_path, highlights_on: %r{/settings/identity_proofs*}, if: proc { current_account.identity_proofs.exists? } end - n.item :preferences, safe_join([fa_icon('cog fw'), t('settings.preferences')]), settings_preferences_appearance_url do |s| + n.item :preferences, safe_join([fa_icon('cog fw'), t('settings.preferences')]), settings_preferences_url do |s| s.item :appearance, safe_join([fa_icon('desktop fw'), t('settings.appearance')]), settings_preferences_appearance_url s.item :notifications, safe_join([fa_icon('bell fw'), t('settings.notifications')]), settings_preferences_notifications_url - s.item :other, safe_join([fa_icon('cog fw'), t('preferences.other')]), settings_preferences_url + s.item :other, safe_join([fa_icon('cog fw'), t('preferences.other')]), settings_preferences_other_url end n.item :relationships, safe_join([fa_icon('users fw'), t('settings.relationships')]), relationships_url diff --git a/config/routes.rb b/config/routes.rb index 2b35472bd..145079c69 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,15 +87,17 @@ Rails.application.routes.draw do get '/explore', to: 'directories#index', as: :explore get '/explore/:id', to: 'directories#show', as: :explore_hashtag - get '/settings', to: redirect('/settings/preferences') + get '/settings', to: redirect('/settings/profile') namespace :settings do resource :profile, only: [:show, :update] - resource :preferences, only: [:show, :update] + + get :preferences, to: redirect('/settings/preferences/appearance') namespace :preferences do resource :appearance, only: [:show, :update], controller: :appearance resource :notifications, only: [:show, :update] + resource :other, only: [:show, :update], controller: :other end resource :import, only: [:show, :create] diff --git a/spec/controllers/settings/preferences/other_controller_spec.rb b/spec/controllers/settings/preferences/other_controller_spec.rb new file mode 100644 index 000000000..1b556ac7f --- /dev/null +++ b/spec/controllers/settings/preferences/other_controller_spec.rb @@ -0,0 +1,46 @@ +require 'rails_helper' + +describe Settings::Preferences::OtherController do + render_views + + let(:user) { Fabricate(:user, filtered_languages: []) } + + before do + sign_in user, scope: :user + end + + describe 'GET #show' do + it 'returns http success' do + get :show + expect(response).to have_http_status(200) + end + end + + describe 'PUT #update' do + it 'updates the user record' do + put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } } + + expect(response).to redirect_to(settings_preferences_other_path) + user.reload + expect(user.locale).to eq 'en' + expect(user.chosen_languages).to eq ['es', 'fr'] + end + + it 'updates user settings' do + user.settings['boost_modal'] = false + user.settings['delete_modal'] = true + + put :update, params: { + user: { + setting_boost_modal: '1', + setting_delete_modal: '0', + } + } + + expect(response).to redirect_to(settings_preferences_other_path) + user.reload + expect(user.settings['boost_modal']).to be true + expect(user.settings['delete_modal']).to be false + end + end +end diff --git a/spec/controllers/settings/preferences_controller_spec.rb b/spec/controllers/settings/preferences_controller_spec.rb deleted file mode 100644 index f2028cf39..000000000 --- a/spec/controllers/settings/preferences_controller_spec.rb +++ /dev/null @@ -1,46 +0,0 @@ -require 'rails_helper' - -describe Settings::PreferencesController do - render_views - - let(:user) { Fabricate(:user, filtered_languages: []) } - - before do - sign_in user, scope: :user - end - - describe 'GET #show' do - it 'returns http success' do - get :show - expect(response).to have_http_status(200) - end - end - - describe 'PUT #update' do - it 'updates the user record' do - put :update, params: { user: { locale: 'en', chosen_languages: ['es', 'fr', ''] } } - - expect(response).to redirect_to(settings_preferences_path) - user.reload - expect(user.locale).to eq 'en' - expect(user.chosen_languages).to eq ['es', 'fr'] - end - - it 'updates user settings' do - user.settings['boost_modal'] = false - user.settings['delete_modal'] = true - - put :update, params: { - user: { - setting_boost_modal: '1', - setting_delete_modal: '0', - } - } - - expect(response).to redirect_to(settings_preferences_path) - user.reload - expect(user.settings['boost_modal']).to be true - expect(user.settings['delete_modal']).to be false - end - end -end -- cgit