diff --git a/app/assets/javascripts/users/settings/preferences.js b/app/assets/javascripts/users/settings/account/preferences.js similarity index 100% rename from app/assets/javascripts/users/settings/preferences.js rename to app/assets/javascripts/users/settings/account/preferences.js diff --git a/app/controllers/users/settings/account/preferences_controller.rb b/app/controllers/users/settings/account/preferences_controller.rb new file mode 100644 index 000000000..ac85f0148 --- /dev/null +++ b/app/controllers/users/settings/account/preferences_controller.rb @@ -0,0 +1,124 @@ +module Users + module Settings + module Account + class PreferencesController < ApplicationController + before_action :load_user, only: [ + :index, + :update, + :tutorial, + :reset_tutorial, + :notifications_settings + ] + + def index + end + + def update + respond_to do |format| + if @user.update(update_params) + flash[:notice] = + t('users.settings.account.preferences.update_flash') + format.json do + flash.keep + render json: { status: :ok } + end + else + format.json do + render json: @user.errors, + status: :unprocessable_entity + end + end + end + end + + def tutorial + @teams = + @user + .user_teams + .includes(team: :users) + .where(role: 1..2) + .order(created_at: :asc) + .map(&:team) + @member_of = @teams.count + + respond_to do |format| + format.json do + render json: { + status: :ok, + html: render_to_string( + partial: 'users/settings/account/preferences/' \ + 'repeat_tutorial_modal_body.html.erb' + ) + } + end + end + end + + def reset_tutorial + if @user.update(tutorial_status: 0) && params[:team][:id].present? + @user.update(current_team_id: params[:team][:id]) + cookies.delete :tutorial_data + cookies.delete :current_tutorial_step + cookies[:repeat_tutorial_team_id] = { + value: params[:team][:id], + expires: 1.day.from_now + } + + flash[:notice] = t( + 'users.settings.account.preferences.tutorial.tutorial_reset_flash' + ) + redirect_to root_path + else + flash[:alert] = t( + 'users.settings.account.preferences.tutorial.tutorial_reset_error' + ) + redirect_to :back + end + end + + def notifications_settings + @user.assignments_notification = + params[:assignments_notification] ? true : false + @user.recent_notification = + params[:recent_notification] ? true : false + @user.recent_notification_email = + params[:recent_notification_email] ? true : false + @user.assignments_notification_email = + params[:assignments_notification_email] ? true : false + @user.system_message_notification_email = + params[:system_message_notification_email] ? true : false + + if @user.save + respond_to do |format| + format.json do + render json: { + status: :ok + } + end + end + else + respond_to do |format| + format.json do + render json: { + status: :unprocessable_entity + } + end + end + end + end + + private + + def load_user + @user = current_user + end + + def update_params + params.require(:user).permit( + :time_zone + ) + end + end + end + end +end diff --git a/app/controllers/users/settings_controller.rb b/app/controllers/users/settings_controller.rb index 2e607abee..a76dd8e9b 100644 --- a/app/controllers/users/settings_controller.rb +++ b/app/controllers/users/settings_controller.rb @@ -4,16 +4,11 @@ class Users::SettingsController < ApplicationController include InputSanitizeHelper before_action :load_user, only: [ - :preferences, - :update_preferences, :teams, :team, :create_team, :teams_datatable, :team_users_datatable, - :tutorial, - :reset_tutorial, - :notifications_settings, :user_current_team, :destroy_user_team ] @@ -34,26 +29,6 @@ class Users::SettingsController < ApplicationController :destroy_user_team ] - def preferences - end - - def update_preferences - respond_to do |format| - if @user.update(update_preferences_params) - flash[:notice] = t("users.settings.preferences.update_flash") - format.json { - flash.keep - render json: { status: :ok } - } - else - format.json { - render json: @user.errors, - status: :unprocessable_entity - } - end - end - end - def teams @user_teams = @user @@ -288,76 +263,6 @@ class Users::SettingsController < ApplicationController end end - def tutorial - @teams = - @user - .user_teams - .includes(team: :users) - .where(role: 1..2) - .order(created_at: :asc) - .map(&:team) - @member_of = @teams.count - - respond_to do |format| - format.json { - render json: { - status: :ok, - html: render_to_string({ - partial: "users/settings/repeat_tutorial_modal_body.html.erb" - }) - } - } - end - end - - def reset_tutorial - if @user.update(tutorial_status: 0) && params[:team][:id].present? - @user.update(current_team_id: params[:team][:id]) - cookies.delete :tutorial_data - cookies.delete :current_tutorial_step - cookies[:repeat_tutorial_team_id] = { - value: params[:team][:id], - expires: 1.day.from_now - } - - flash[:notice] = t("users.settings.preferences.tutorial.tutorial_reset_flash") - redirect_to root_path - else - flash[:alert] = t("users.settings.preferences.tutorial.tutorial_reset_error") - redirect_to :back - end - end - - def notifications_settings - @user.assignments_notification = - params[:assignments_notification] ? true : false - @user.recent_notification = params[:recent_notification] ? true : false - @user.recent_notification_email = - params[:recent_notification_email] ? true : false - @user.assignments_notification_email = - params[:assignments_notification_email] ? true : false - @user.system_message_notification_email = - params[:system_message_notification_email] ? true : false - - if @user.save - respond_to do |format| - format.json do - render json: { - status: :ok - } - end - end - else - respond_to do |format| - format.json do - render json: { - status: :unprocessable_entity - } - end - end - end - end - def user_current_team team_id = params[:user][:current_team_id].to_i if @user.teams_ids.include?(team_id) @@ -398,12 +303,6 @@ class Users::SettingsController < ApplicationController end end - def update_preferences_params - params.require(:user).permit( - :time_zone - ) - end - def create_team_params params.require(:team).permit( :name, diff --git a/app/views/users/settings/_repeat_tutorial_modal_body.html.erb b/app/views/users/settings/account/preferences/_repeat_tutorial_modal_body.html.erb similarity index 58% rename from app/views/users/settings/_repeat_tutorial_modal_body.html.erb rename to app/views/users/settings/account/preferences/_repeat_tutorial_modal_body.html.erb index b3d4897dd..2ee232424 100644 --- a/app/views/users/settings/_repeat_tutorial_modal_body.html.erb +++ b/app/views/users/settings/account/preferences/_repeat_tutorial_modal_body.html.erb @@ -1,10 +1,10 @@ <% if @member_of == 0 %>
- <%=t 'users.settings.preferences.tutorial.no_teams' %> + <%=t 'users.settings.account.preferences.tutorial.no_teams' %>
<% else %>
- <%=t 'users.settings.preferences.tutorial.select_team_instruction' %> + <%=t 'users.settings.account.preferences.tutorial.select_team_instruction' %>

@@ -14,7 +14,7 @@
 
- <%= f.button t('users.settings.preferences.tutorial.repeat_tutorial'), class: "btn btn-primary" %> + <%= f.button t('users.settings.account.preferences.tutorial.repeat_tutorial'), class: "btn btn-primary" %>
<% end %> diff --git a/app/views/users/settings/preferences.html.erb b/app/views/users/settings/account/preferences/index.html.erb similarity index 87% rename from app/views/users/settings/preferences.html.erb rename to app/views/users/settings/account/preferences/index.html.erb index 353626a2c..00d10f2ab 100644 --- a/app/views/users/settings/preferences.html.erb +++ b/app/views/users/settings/account/preferences/index.html.erb @@ -1,4 +1,4 @@ -<% provide(:head_title, t("users.settings.preferences.head_title")) %> +<% provide(:head_title, t("users.settings.account.preferences.head_title")) %> <%= render partial: "users/settings/navigation.html.erb" %>
@@ -10,7 +10,7 @@ html: { method: :put, 'data-for' => 'time_zone' }) do |f| %>
- <%= f.label t("users.settings.preferences.edit.time_zone_label") %> + <%= f.label t("users.settings.account.preferences.edit.time_zone_label") %>
<%=t "general.edit" %>
- <%= t("users.settings.preferences.edit.time_zone_sublabel") %> + <%= t("users.settings.account.preferences.edit.time_zone_sublabel") %>
-

<%=t "users.settings.preferences.edit.time_zone_title" %>

+

<%=t "users.settings.account.preferences.edit.time_zone_title" %>

<%= f.select :time_zone, ActiveSupport::TimeZone.all.collect { |tz| [tz.formatted_offset + " " + tz.name, tz.name] }, {}, {class: 'form-control selectpicker', 'ata-role' => 'clear'} %> - <%= t("users.settings.preferences.edit.time_zone_sublabel") %> + <%= t("users.settings.account.preferences.edit.time_zone_sublabel") %>
<%=t "general.cancel" %> @@ -45,7 +45,7 @@ <% if Rails.configuration.x.enable_tutorial %>
<%= t('tutorial.title') %>
- <%= link_to t('users.settings.preferences.tutorial.repeat_tutorial'), + <%= link_to t('users.settings.account.preferences.tutorial.repeat_tutorial'), tutorial_path(format: :json), remote: true, class: 'btn btn-primary', @@ -100,7 +100,7 @@