2017-04-12 10:52:52 -04:00
|
|
|
class ThemeFieldSerializer < ApplicationSerializer
|
2017-05-09 17:20:28 -04:00
|
|
|
attributes :name, :target, :value, :error, :type_id, :upload_id, :url, :filename
|
|
|
|
|
|
|
|
def include_url?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_upload_id?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def include_filename?
|
|
|
|
object.upload
|
|
|
|
end
|
|
|
|
|
|
|
|
def url
|
|
|
|
object.upload&.url
|
|
|
|
end
|
|
|
|
|
|
|
|
def filename
|
|
|
|
object.upload&.original_filename
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
|
|
|
|
def target
|
2017-05-02 16:01:01 -04:00
|
|
|
case object.target_id
|
2017-04-12 10:52:52 -04:00
|
|
|
when 0 then "common"
|
|
|
|
when 1 then "desktop"
|
|
|
|
when 2 then "mobile"
|
|
|
|
end
|
|
|
|
end
|
2017-04-19 16:46:28 -04:00
|
|
|
|
|
|
|
def include_error?
|
|
|
|
object.error.present?
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class ChildThemeSerializer < ApplicationSerializer
|
|
|
|
attributes :id, :name, :key, :created_at, :updated_at, :default
|
|
|
|
|
|
|
|
def include_default?
|
|
|
|
object.key == SiteSetting.default_theme_key
|
|
|
|
end
|
|
|
|
|
|
|
|
def default
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class RemoteThemeSerializer < ApplicationSerializer
|
|
|
|
attributes :id, :remote_url, :remote_version, :local_version, :about_url,
|
|
|
|
:license_url, :commits_behind, :remote_updated_at, :updated_at
|
|
|
|
|
|
|
|
# wow, AMS has some pretty nutty logic where it tries to find the path here
|
|
|
|
# from action dispatch, tell it not to
|
|
|
|
def about_url
|
|
|
|
object.about_url
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
class ThemeSerializer < ChildThemeSerializer
|
|
|
|
attributes :color_scheme, :color_scheme_id, :user_selectable, :remote_theme_id
|
|
|
|
|
|
|
|
has_many :theme_fields, serializer: ThemeFieldSerializer, embed: :objects
|
|
|
|
has_many :child_themes, serializer: ChildThemeSerializer, embed: :objects
|
|
|
|
has_one :remote_theme, serializer: RemoteThemeSerializer, embed: :objects
|
2017-04-13 10:51:44 -04:00
|
|
|
|
|
|
|
def child_themes
|
|
|
|
object.child_themes.order(:name)
|
|
|
|
end
|
2017-04-12 10:52:52 -04:00
|
|
|
end
|