2017-02-09 18:07:16 +08:00
|
|
|
module Users
|
|
|
|
module Settings
|
|
|
|
module Account
|
|
|
|
class PreferencesController < ApplicationController
|
|
|
|
before_action :load_user, only: [
|
|
|
|
:index,
|
2023-10-13 19:54:59 +08:00
|
|
|
:update
|
2017-02-09 18:07:16 +08:00
|
|
|
]
|
2023-10-13 19:54:59 +08:00
|
|
|
before_action :set_breadcrumbs_items, only: %i(index)
|
2018-04-05 22:30:02 +08:00
|
|
|
layout 'fluid'
|
2017-02-09 18:07:16 +08:00
|
|
|
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2023-07-18 19:36:41 +08:00
|
|
|
if @user.update(update_params)
|
|
|
|
render json: { status: :ok }
|
|
|
|
else
|
|
|
|
render json: @user.errors, status: :unprocessable_entity
|
2017-02-09 18:07:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def load_user
|
|
|
|
@user = current_user
|
|
|
|
end
|
|
|
|
|
|
|
|
def update_params
|
2023-10-13 19:54:59 +08:00
|
|
|
params.require(:user).permit(:time_zone, :date_format, notifications_settings: {})
|
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
|
2023-10-13 19:54:59 +08:00
|
|
|
|
|
|
|
def set_breadcrumbs_items
|
|
|
|
@breadcrumbs_items = [{
|
|
|
|
label: t('notifications.breadcrumb'),
|
|
|
|
url: preferences_path
|
|
|
|
}]
|
|
|
|
|
|
|
|
@breadcrumbs_items
|
|
|
|
end
|
2017-02-09 18:07:16 +08:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|