discourse/app/serializers/theme_settings_serializer.rb
Alan Guo Xiang Tan 94b09f3331
DEV: Open theme settings objects editor from admin customize theme page (#26006)
Why this change?

The `/admin/customize/themes/:id/schema/name` route is a work in
progress but we want to be able to start navigating to it from the
`/admin/customize/themes/:id` route.

What does this change do?

1. Move `adminCustomizeThemes.schema` to a child route of
   `adminCustomizeThemes.show`. This is because we need the model
   from the parent route and if it isn't a child route we end up
   having to load the theme model again from the server.

1. Add the `objects_schema` attribute to `ThemeSettingsSerializer`

1. Refactor `SiteSettingComponent` to be able to render a button
   so that we don't have to hardcode the button rendering into the
   `SiteSettings::String` component
2024-03-06 08:24:29 +08:00

85 lines
1.4 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
locale_file_description =
object
.theme
.internal_translations
.find { |t| t.key == "theme_metadata.settings.#{setting}" }
&.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