Sha256: 51bc9e00bcb10e285f001d778d7b9405458cab64fbaefca486a266c99cfe3ac2

Contents?: true

Size: 1.44 KB

Versions: 16

Compression:

Stored size: 1.44 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,
      preloaded_obj_data: preloaded_obj_data
    }.to_json
  end

  private

  def user_id_config
    editor.id
  end

  def preloaded_obj_data
    if obj
      obj_in_selected_workpace =
        editing_context.selected_workspace.objs.find_including_deleted(obj.id)
      [obj_in_selected_workpace.data_from_cms.to_h]
    else
      []
    end
  end

  def current_page_config
    return {} unless obj
    {
      id: obj.id,
      obj_class: obj.obj_class,
      description_for_editor: obj.description_for_editor,
      has_children: obj.children.any?,
      has_conflict: obj.has_conflict?,
      has_details_view: obj_has_details_view?,
      modification: modification(obj),
      parent_path: obj.parent_path,
      is_restricted: editor.restriction_messages_for(obj).any?,
    }
  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

16 entries across 16 versions & 1 rubygems

Version Path
scrivito_sdk-1.12.0 app/cms/scrivito/page_config.rb
scrivito_sdk-1.12.0.rc2 app/cms/scrivito/page_config.rb
scrivito_sdk-1.12.0.rc1 app/cms/scrivito/page_config.rb
scrivito_sdk-1.11.0 app/cms/scrivito/page_config.rb
scrivito_sdk-1.11.0.rc1 app/cms/scrivito/page_config.rb
scrivito_sdk-1.10.0 app/cms/scrivito/page_config.rb
scrivito_sdk-1.10.0.rc5 app/cms/scrivito/page_config.rb
scrivito_sdk-1.10.0.rc4 app/cms/scrivito/page_config.rb
scrivito_sdk-1.10.0.rc3 app/cms/scrivito/page_config.rb
scrivito_sdk-1.10.0.rc2 lib/scrivito/page_config.rb
scrivito_sdk-1.10.0.rc1 lib/scrivito/page_config.rb
scrivito_sdk-1.9.1 lib/scrivito/page_config.rb
scrivito_sdk-1.9.1.rc1 lib/scrivito/page_config.rb
scrivito_sdk-1.9.0 lib/scrivito/page_config.rb
scrivito_sdk-1.9.0.rc2 lib/scrivito/page_config.rb
scrivito_sdk-1.9.0.rc1 lib/scrivito/page_config.rb