You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
51 lines
1.3 KiB
51 lines
1.3 KiB
class Admins::SaveLaboratorySettingService < ApplicationService
|
|
attr_reader :laboratory, :laboratory_setting, :params
|
|
|
|
def initialize(laboratory, params)
|
|
@params = params
|
|
@laboratory = laboratory
|
|
@laboratory_setting = laboratory.laboratory_setting
|
|
end
|
|
|
|
def call
|
|
ActiveRecord::Base.transaction do
|
|
laboratory.identifier = strip params[:identifier]
|
|
laboratory_setting.name = strip params[:name]
|
|
laboratory_setting.navbar = navbar_config
|
|
laboratory_setting.footer = strip params[:footer]
|
|
|
|
laboratory.save!
|
|
laboratory_setting.save!
|
|
|
|
deal_logo_file
|
|
end
|
|
|
|
laboratory
|
|
end
|
|
|
|
private
|
|
|
|
def navbar_config
|
|
params[:navbar].map do |nav|
|
|
hash = {}
|
|
hash[:name] = strip nav[:name]
|
|
hash[:link] = strip nav[:link]
|
|
hash[:hidden] = nav[:hidden].to_s != '0'
|
|
hash
|
|
end
|
|
end
|
|
|
|
def deal_logo_file
|
|
save_logo_file(params[:nav_logo], 'nav')
|
|
save_logo_file(params[:login_logo], 'login')
|
|
save_logo_file(params[:tab_logo], 'tab')
|
|
end
|
|
|
|
def save_logo_file(file, type)
|
|
return unless file.present? && file.is_a?(ActionDispatch::Http::UploadedFile)
|
|
|
|
file_path = Util::FileManage.source_disk_filename(laboratory_setting, type)
|
|
File.delete(file_path) if File.exist?(file_path) # 删除之前的文件
|
|
Util.write_file(file, file_path)
|
|
end
|
|
end |