2017-02-09 18:07:16 +08:00
|
|
|
module Users
|
|
|
|
module Settings
|
|
|
|
module Account
|
|
|
|
class PreferencesController < ApplicationController
|
|
|
|
before_action :load_user, only: [
|
|
|
|
:index,
|
|
|
|
:update,
|
2018-09-05 22:36:32 +08:00
|
|
|
:update_togglable_settings
|
2017-02-09 18:07:16 +08:00
|
|
|
]
|
2018-04-05 22:30:02 +08:00
|
|
|
layout 'fluid'
|
2017-02-09 18:07:16 +08:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
respond_to do |format|
|
|
|
|
if @user.update(update_params)
|
|
|
|
format.json do
|
|
|
|
render json: { status: :ok }
|
|
|
|
end
|
|
|
|
else
|
|
|
|
format.json do
|
|
|
|
render json: @user.errors,
|
|
|
|
status: :unprocessable_entity
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-05 22:36:32 +08:00
|
|
|
def update_togglable_settings
|
|
|
|
read_from_params(:assignments_notification) do |val|
|
|
|
|
@user.assignments_notification = val
|
|
|
|
end
|
|
|
|
read_from_params(:recent_notification) do |val|
|
|
|
|
@user.recent_notification = val
|
|
|
|
end
|
|
|
|
read_from_params(:recent_notification_email) do |val|
|
|
|
|
@user.recent_email_notification = val
|
|
|
|
end
|
|
|
|
read_from_params(:assignments_notification_email) do |val|
|
|
|
|
@user.assignments_email_notification = val
|
|
|
|
end
|
|
|
|
read_from_params(:system_message_notification_email) do |val|
|
|
|
|
@user.system_message_email_notification = val
|
|
|
|
end
|
|
|
|
read_from_params(:tooltips_enabled) do |val|
|
|
|
|
@user.settings[:tooltips_enabled] = val
|
|
|
|
end
|
2017-02-09 18:07:16 +08:00
|
|
|
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
|
2018-11-09 22:58:08 +08:00
|
|
|
params.require(:user).permit(:time_zone, :date_format)
|
2017-02-09 18:07:16 +08:00
|
|
|
end
|
2018-09-05 22:36:32 +08:00
|
|
|
|
|
|
|
def read_from_params(name)
|
|
|
|
yield(params.include?(name) ? true : false)
|
|
|
|
end
|
2017-02-09 18:07:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|