2024-02-08 12:59:52 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class ThemeSettingsManager::Objects < ThemeSettingsManager
|
|
|
|
def value
|
|
|
|
has_record? ? db_record.json_value : default.map!(&:deep_stringify_keys)
|
|
|
|
end
|
|
|
|
|
|
|
|
def value=(objects)
|
2024-03-11 08:42:12 +08:00
|
|
|
objects = JSON.parse(objects) if objects.is_a?(::String)
|
2024-02-28 10:33:22 +08:00
|
|
|
ensure_is_valid_value!(objects)
|
2024-03-07 16:38:11 +08:00
|
|
|
record = has_record? ? update_record!(json_value: objects) : create_record!(json_value: objects)
|
2024-02-08 12:59:52 +08:00
|
|
|
theme.reload
|
|
|
|
record.json_value
|
|
|
|
end
|
2024-03-06 08:24:29 +08:00
|
|
|
|
|
|
|
def schema
|
|
|
|
@opts[:schema]
|
|
|
|
end
|
2024-03-27 10:54:30 +08:00
|
|
|
|
|
|
|
def categories(guardian)
|
|
|
|
category_ids = Set.new
|
|
|
|
|
|
|
|
value.each do |theme_setting_object|
|
|
|
|
category_ids.merge(
|
|
|
|
ThemeSettingsObjectValidator.new(
|
|
|
|
schema:,
|
|
|
|
object: theme_setting_object,
|
|
|
|
).property_values_of_type("categories"),
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
return [] if category_ids.empty?
|
|
|
|
|
|
|
|
Category.secured(guardian).where(id: category_ids)
|
|
|
|
end
|
2024-02-08 12:59:52 +08:00
|
|
|
end
|