2019-05-03 06:17:27 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2018-03-05 08:04:23 +08:00
|
|
|
class ThemeSettingsSerializer < ApplicationSerializer
|
2018-08-04 04:41:37 +08:00
|
|
|
attributes :setting,
|
|
|
|
:type,
|
|
|
|
:default,
|
|
|
|
:value,
|
|
|
|
:description,
|
|
|
|
:valid_values,
|
2021-03-11 09:15:04 +08:00
|
|
|
:list_type,
|
|
|
|
:textarea,
|
|
|
|
:json_schema
|
2018-03-05 08:04:23 +08:00
|
|
|
|
|
|
|
def setting
|
|
|
|
object.name
|
|
|
|
end
|
|
|
|
|
|
|
|
def type
|
|
|
|
object.type_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
object.default
|
|
|
|
end
|
|
|
|
|
|
|
|
def value
|
|
|
|
object.value
|
|
|
|
end
|
|
|
|
|
|
|
|
def description
|
2019-05-31 21:49:59 +08:00
|
|
|
locale_file_description =
|
|
|
|
object
|
|
|
|
.theme
|
|
|
|
.internal_translations
|
|
|
|
.find { |t| t.key == "theme_metadata.settings.#{setting}" }
|
|
|
|
&.value
|
|
|
|
locale_file_description || object.description
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def valid_values
|
|
|
|
object.choices
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_valid_values?
|
|
|
|
object.type == ThemeSetting.types[:enum]
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_description?
|
2019-05-31 21:49:59 +08:00
|
|
|
description.present?
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|
2018-08-04 04:41:37 +08:00
|
|
|
|
|
|
|
def list_type
|
|
|
|
object.list_type
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_list_type?
|
|
|
|
object.type == ThemeSetting.types[:list]
|
|
|
|
end
|
2019-02-05 22:14:53 +08:00
|
|
|
|
|
|
|
def textarea
|
|
|
|
object.textarea
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_textarea?
|
|
|
|
object.type == ThemeSetting.types[:string]
|
|
|
|
end
|
|
|
|
|
2021-03-11 09:15:04 +08:00
|
|
|
def json_schema
|
|
|
|
object.json_schema
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_json_schema?
|
|
|
|
object.type == ThemeSetting.types[:string] && object.json_schema.present?
|
|
|
|
end
|
2018-03-05 08:04:23 +08:00
|
|
|
end
|