discourse/app/serializers/theme_serializer.rb
Martin Brennan e26a1175d7
FEATURE: Initial version of experimental admin search (#31299)
This feature allows admins to find what they are
looking for in the admin interface via a search modal.
This replaces the admin sidebar filter
as the focus of the Ctrl+/ command, but the sidebar
filter can also still be used. Perhaps at some point
we may remove it or change the shortcut.

The search modal presents the following data for filtering:

* A list of all admin pages, the same as the sidebar,
   except also showing "third level" pages like
   "Email > Skipped"
* All site settings
* Themes
* Components
* Reports

Admins can also filter which types of items are shown in the modal,
for example hiding Settings if they know they are looking for a Page.

In this PR, I also have the following fixes:

* Site setting filters now clear when moving between
   filtered site setting pages, previously it was super
   sticky from Ember
* Many translations were moved around, instead of being
   in various namespaces for the sidebar links and the admin
   page titles and descriptions, now everything is under
   `admin.config` namespace, this makes it way easier to reuse
   this text for pages, search, and sidebar, and if you change it
   in one place then it is changed everywhere.

---------

Co-authored-by: Ella <ella.estigoy@gmail.com>
2025-02-21 11:59:24 +10:00

94 lines
2.4 KiB
Ruby

# frozen_string_literal: true
require "base64"
class ThemeSerializer < BasicThemeSerializer
attributes :color_scheme_id,
:user_selectable,
:auto_update,
:remote_theme_id,
:settings,
:errors,
:supported?,
:enabled?,
:disabled_at,
:theme_fields,
:screenshot_url
has_one :color_scheme, serializer: ColorSchemeSerializer, embed: :object
has_one :user, serializer: UserNameSerializer, embed: :object
has_one :disabled_by, serializer: UserNameSerializer, embed: :object
has_many :child_themes, serializer: BasicThemeSerializer, embed: :objects
has_many :parent_themes, serializer: BasicThemeSerializer, embed: :objects
has_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects
has_many :translations, serializer: ThemeTranslationSerializer, embed: :objects
def initialize(theme, options = {})
super
@include_theme_field_values = options[:include_theme_field_values] || false
@errors = []
object.theme_fields.each { |o| @errors << o.error if o.error }
end
def theme_fields
ActiveModel::ArraySerializer.new(
object.theme_fields,
each_serializer: ThemeFieldSerializer,
include_value: include_theme_field_values?,
).as_json
end
def include_theme_field_values?
# This is passed into each `ThemeFieldSerializer` to determine if `value` will be serialized.
# We only want to serialize if we are viewing staff_action_logs (for diffing changes), or if
# the theme is a local theme, so the saved values appear in the theme field editor.
@include_theme_field_values || object.remote_theme_id.nil?
end
def screenshot_url
object
.theme_fields
.find { |field| field.type_id == ThemeField.types[:theme_screenshot_upload_var] }
&.upload_url
end
def child_themes
object.child_themes
end
def parent_themes
object.parent_themes
end
def settings
object.settings.map do |_name, setting|
ThemeSettingsSerializer.new(setting, scope:, root: false)
end
rescue ThemeSettingsParser::InvalidYaml => e
@errors << e.message
nil
end
def include_child_themes?
!object.component?
end
def errors
@errors
end
def include_errors?
@errors.present?
end
def include_disabled_at?
object.component? && !object.enabled?
end
def include_disabled_by?
include_disabled_at?
end
end