mirror of
https://gh.wpcy.net/https://github.com/discourse/discourse.git
synced 2026-05-05 02:11:15 +08:00
Some checks failed
Licenses / run (push) Has been cancelled
Linting / run (push) Has been cancelled
Migration Tests / Tests (push) Has been cancelled
Publish Assets / publish-assets (push) Has been cancelled
Tests / core backend (push) Has been cancelled
Tests / plugins backend (push) Has been cancelled
Tests / core frontend (Chrome) (push) Has been cancelled
Tests / plugins frontend (push) Has been cancelled
Tests / themes frontend (push) Has been cancelled
Tests / core system (push) Has been cancelled
Tests / plugins system (push) Has been cancelled
Tests / themes system (push) Has been cancelled
Tests / core frontend (Firefox ESR) (push) Has been cancelled
Tests / core frontend (Firefox Evergreen) (push) Has been cancelled
Tests / chat system (push) Has been cancelled
Tests / merge (push) Has been cancelled
This commit moves the /admin/config/theme-site-settings page to a tab in the "Themes and components" config page. This will make it easier to find for admins. Also add a `AdminFilterControls` component to the page to filter by setting name, description, or theme name.
73 lines
2.2 KiB
Ruby
73 lines
2.2 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
class Admin::Config::CustomizeController < Admin::AdminController
|
|
PAGE_SIZE = 20
|
|
|
|
def themes
|
|
themes =
|
|
Theme
|
|
.include_basic_relations
|
|
.includes(:theme_fields, color_scheme: [:color_scheme_colors])
|
|
.where(component: false)
|
|
.order(:name)
|
|
|
|
render json: { themes: serialize_data(themes, ThemeIndexSerializer) }
|
|
end
|
|
|
|
def components
|
|
page = params[:page]&.to_i
|
|
|
|
components =
|
|
Theme.include_basic_relations.where(component: true).order(:name).limit(PAGE_SIZE + 1)
|
|
|
|
components = components.offset(page * PAGE_SIZE) if page && page > 0
|
|
|
|
name_search_term = params[:name].presence&.strip
|
|
if name_search_term
|
|
components = components.where("themes.name ILIKE ?", "%#{name_search_term}%")
|
|
end
|
|
|
|
status_filter = params[:status].presence
|
|
if status_filter
|
|
case status_filter
|
|
when "used"
|
|
components = components.joins(:parent_themes).distinct
|
|
when "unused"
|
|
components = components.left_joins(:parent_themes).where(parent_themes: { id: nil })
|
|
when "updates_available"
|
|
components = components.joins(:remote_theme).where(remote_theme: { commits_behind: 1.. })
|
|
else
|
|
raise Discourse::InvalidParameters if status_filter != "all"
|
|
end
|
|
end
|
|
|
|
components = components.to_a
|
|
has_more = components.size > PAGE_SIZE
|
|
components = components[...PAGE_SIZE]
|
|
|
|
render json: { has_more:, components: serialize_data(components, ComponentIndexSerializer) }
|
|
end
|
|
|
|
def theme_site_settings
|
|
themes_with_site_setting_overrides = {}
|
|
|
|
SiteSetting.themeable_site_settings.each do |setting_name|
|
|
themes_with_site_setting_overrides[setting_name] = SiteSetting.setting_metadata_hash(
|
|
setting_name,
|
|
).merge(themes: [])
|
|
end
|
|
|
|
ThemeSiteSetting.themes_with_overridden_settings.each do |row|
|
|
themes_with_site_setting_overrides[row.setting_name][:themes] << {
|
|
theme_id: row.theme_id,
|
|
theme_name: row.theme_name,
|
|
value: row.value,
|
|
}
|
|
end
|
|
|
|
render_json_dump(
|
|
themeable_site_settings: SiteSetting.themeable_site_settings,
|
|
themes_with_site_setting_overrides: themes_with_site_setting_overrides,
|
|
)
|
|
end
|
|
end
|