Sha256: dde07e4f7cc97b4115b4da1232629712e88d3223cd5c224cb48ba6b349954c81

Contents?: true

Size: 1.44 KB

Versions: 8

Compression:

Stored size: 1.44 KB

Contents

module Scrivito

class UiConfig < Struct.new(:editing_context, :resource, :return_to, :app_extension_tags,
                            :obj_models, :widget_models, :lookup_context)
  def initialize(**named_params)
    named_params.each { |key, value| self[key] = value }
  end

  def to_json
    {
      app_extension_tags:  app_extension_tags,
      backend_endpoint:    Configuration.endpoint,
      tenant:              Configuration.tenant,
      i18n:                i18n_config,
      is_development_mode: Rails.env.development?,
      resource_dialog:     resource_dialog_config,
      class_datas:         obj_class_config + widget_class_config,
      useRailsEngine:      true,
    }.to_json
  end

  private

  def i18n_config
    {locale: Scrivito::Configuration.ui_locale || I18n.locale}
  end

  def obj_class_config
    obj_models.map do |obj_class|
      obj_class_formatter.format(obj_class)
    end
  end

  def widget_class_config
    widget_models.map do |widget_class|
      obj_class_formatter.format(widget_class)
    end
  end

  def resource_dialog_config
    return {} unless resource
    {
      obj: Configuration.obj_formats.fetch('_default').call(resource, editor),
      return_to: return_to,
    }
  end

  def editor
    editing_context.editor
  end

  def selected_workspace
    editing_context.selected_workspace
  end

  def obj_class_formatter
    @obj_class_formatter ||= UiObjClassesJsonFormatter.new(lookup_context)
  end
end

end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
scrivito_sdk-1.11.0 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.11.0.rc1 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.10.0 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.10.0.rc5 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.10.0.rc4 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.10.0.rc3 app/cms/scrivito/ui_config.rb
scrivito_sdk-1.10.0.rc2 lib/scrivito/ui_config.rb
scrivito_sdk-1.10.0.rc1 lib/scrivito/ui_config.rb