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.
educoder/app/models/laboratory_setting.rb

54 lines
1.3 KiB

class LaboratorySetting < ApplicationRecord
belongs_to :laboratory
serialize :config, JSON
%i[name navbar footer].each do |method_name|
define_method method_name do
config&.[](method_name.to_s)
end
define_method "#{method_name}=" do |value|
self.config ||= {}
config.[]=(method_name.to_s, value)
end
end
def login_logo_url
logo_url('login')
end
def nav_logo_url
logo_url('nav')
end
def tab_logo_url
logo_url('tab')
end
def default_navbar
self.class.default_config[:navbar]
end
private
def logo_url(type)
return nil unless Util::FileManage.exists?(self, type)
Util::FileManage.source_disk_file_url(self, type)
end
def self.default_config
{
name: nil,
navbar: [
{ 'name' => '实践课程', 'link' => '/paths', 'hidden' => false },
{ 'name' => '翻转课堂', 'link' => '/courses', 'hidden' => false },
{ 'name' => '实训项目', 'link' => '/shixuns', 'hidden' => false },
{ 'name' => '在线竞赛', 'link' => '/competitions', 'hidden' => false },
{ 'name' => '教学案例', 'link' => '/moop_cases', 'hidden' => false },
{ 'name' => '交流问答', 'link' => '/forums', 'hidden' => false },
],
footer: nil
}
end
end