2022-06-25 18:17:48 -07:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-06-25 17:58:22 -07:00
|
|
|
class Settings::ThemeController < ApplicationController
|
|
|
|
include ThemeHelper
|
|
|
|
|
|
|
|
before_action :authenticate_user!
|
|
|
|
|
2022-06-25 18:07:59 -07:00
|
|
|
def edit; end
|
2022-06-25 17:58:22 -07:00
|
|
|
|
|
|
|
def update
|
2022-06-25 18:07:59 -07:00
|
|
|
update_attributes = params.require(:theme).permit(%i[
|
|
|
|
primary_color primary_text
|
|
|
|
danger_color danger_text
|
|
|
|
success_color success_text
|
|
|
|
warning_color warning_text
|
|
|
|
info_color info_text
|
|
|
|
dark_color dark_text
|
|
|
|
light_color light_text
|
|
|
|
raised_background raised_accent
|
|
|
|
background_color body_text
|
|
|
|
muted_text input_color
|
|
|
|
input_text
|
|
|
|
])
|
2022-06-25 17:58:22 -07:00
|
|
|
|
|
|
|
if current_user.theme.nil?
|
|
|
|
current_user.theme = Theme.new update_attributes
|
|
|
|
current_user.theme.user_id = current_user.id
|
|
|
|
|
|
|
|
if current_user.theme.save
|
|
|
|
flash[:success] = t(".success")
|
|
|
|
else
|
|
|
|
flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" "))
|
|
|
|
end
|
|
|
|
elsif current_user.theme.update(update_attributes)
|
|
|
|
flash[:success] = t(".success")
|
|
|
|
else
|
|
|
|
flash[:error] = t(".error", errors: current_user.theme.errors.messages.flatten.join(" "))
|
|
|
|
end
|
2022-06-26 04:37:15 -07:00
|
|
|
redirect_to settings_theme_path
|
2022-06-25 17:58:22 -07:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
current_user.theme.destroy!
|
2022-06-26 04:37:15 -07:00
|
|
|
redirect_to settings_theme_path
|
2022-06-25 17:58:22 -07:00
|
|
|
end
|
|
|
|
end
|