Sha256: d8e5738ee586dde4fc1a4d201e5c807ccc98a4fc94222a84b49e269649730c99

Contents?: true

Size: 1.09 KB

Versions: 6

Compression:

Stored size: 1.09 KB

Contents

module Scrivito

class PageConfig < Struct.new(:obj, :editing_context, :lookup_context)

  def initialize(**named_params)
    named_params.each { |key, value| self[key] = value }
  end

  def to_json
    {
      current_page: current_page_config,
      user_id: user_id_config,
    }.to_json
  end

  private

  def user_id_config
    editor.id
  end

  def current_page_config
    return {} unless obj
    {
      id: obj.id,
      obj_class_name: obj.obj_class_name,
      has_children: obj.children.any?,
      has_conflict: obj.has_conflict?,
      has_details_view: obj_has_details_view?,
      modification: modification(obj),
      restriction_messages: editor.restriction_messages_for(obj),
    }
  end

  def obj_has_details_view?
    lookup_context.find(obj.details_view_path).present?
  rescue ActionView::MissingTemplate
    false
  end

  def modification(obj_or_resource)
    comparison = editing_context.comparison
    if comparison.active?
      comparison.modification(obj_or_resource)
    else
      obj_or_resource.modification
    end
  end

  def editor
    editing_context.editor
  end
end

end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
scrivito_sdk-0.70.2 lib/scrivito/page_config.rb
scrivito_sdk-0.70.1 lib/scrivito/page_config.rb
scrivito_sdk-0.70.0 lib/scrivito/page_config.rb
scrivito_sdk-0.70.0.rc3 lib/scrivito/page_config.rb
scrivito_sdk-0.70.0.rc2 lib/scrivito/page_config.rb
scrivito_sdk-0.70.0.rc1 lib/scrivito/page_config.rb