mirror of
https://github.com/discourse/discourse.git
synced 2024-11-27 16:33:37 +08:00
ef99b97ea7
Why this change? Previously, we were preloading the necessary metadata for `adminCustomizeThemes.show.schema` route in the `adminCustomizeThemes.show` route. This is wasteful because we're loading data upfront when the objects setting editor may not be used. This change also lays the ground work for a future commit where we need to be shipping down additional metadata which may further add to the payload.
84 lines
1.5 KiB
Ruby
84 lines
1.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class ThemeSettingsSerializer < ApplicationSerializer
|
|
attributes :setting,
|
|
:type,
|
|
:default,
|
|
:value,
|
|
:description,
|
|
:valid_values,
|
|
:list_type,
|
|
:textarea,
|
|
:json_schema,
|
|
:objects_schema
|
|
|
|
def setting
|
|
object.name
|
|
end
|
|
|
|
def type
|
|
object.type_name
|
|
end
|
|
|
|
def default
|
|
object.default
|
|
end
|
|
|
|
def value
|
|
object.value
|
|
end
|
|
|
|
def description
|
|
description_regexp = /^theme_metadata\.settings\.#{setting}(\.description)?$/
|
|
|
|
locale_file_description =
|
|
object.theme.internal_translations.find { |t| t.key.match?(description_regexp) }&.value
|
|
|
|
locale_file_description || object.description
|
|
end
|
|
|
|
def valid_values
|
|
object.choices
|
|
end
|
|
|
|
def include_valid_values?
|
|
object.type == ThemeSetting.types[:enum]
|
|
end
|
|
|
|
def include_description?
|
|
description.present?
|
|
end
|
|
|
|
def list_type
|
|
object.list_type
|
|
end
|
|
|
|
def include_list_type?
|
|
object.type == ThemeSetting.types[:list]
|
|
end
|
|
|
|
def textarea
|
|
object.textarea
|
|
end
|
|
|
|
def include_textarea?
|
|
object.type == ThemeSetting.types[:string]
|
|
end
|
|
|
|
def objects_schema
|
|
object.schema
|
|
end
|
|
|
|
def include_objects_schema?
|
|
object.type == ThemeSetting.types[:objects]
|
|
end
|
|
|
|
def json_schema
|
|
object.json_schema
|
|
end
|
|
|
|
def include_json_schema?
|
|
object.type == ThemeSetting.types[:string] && object.json_schema.present?
|
|
end
|
|
end
|