lib/scrivito/ui_config.rb in scrivito_sdk-1.7.0 vs lib/scrivito/ui_config.rb in scrivito_sdk-1.8.0.rc1
- old
+ new
@@ -1,9 +1,9 @@
module Scrivito
class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extension_tags,
- :obj_models, :widget_models)
+ :obj_models, :widget_models, :lookup_context)
def initialize(**named_params)
named_params.each { |key, value| self[key] = value }
end
def to_json
@@ -52,15 +52,19 @@
def i18n_config
{locale: Scrivito::Configuration.ui_locale || I18n.locale}
end
def obj_class_config
- obj_models.map(&:as_json)
+ obj_models.map do |obj_class|
+ obj_class.as_json.merge(hasDetailsView: details_view?(obj_class.name))
+ end
end
def widget_class_config
- widget_models.map(&:as_json)
+ widget_models.map do |widget_class|
+ widget_class.as_json.merge(hasDetailsView: details_view?(widget_class.name))
+ end
end
def resource_dialog_config
return {} unless resource
{
@@ -98,9 +102,15 @@
editing_context.selected_workspace
end
def visible_workspace
editing_context.visible_workspace
+ end
+
+ def details_view?(obj_class_name)
+ lookup_context.find("#{obj_class_name.underscore}/details").present?
+ rescue ActionView::MissingTemplate
+ false
end
end
end