Sha256: f03a19ae183d2bacd0943af21ccdba17440004d9647fcdf1250043218bd0d515
Contents?: true
Size: 1.47 KB
Versions: 11
Compression:
Stored size: 1.47 KB
Contents
module PageflowScrolled # @api private class ContentElement < Pageflow::ApplicationRecord include Pageflow::SerializedConfiguration include Pageflow::AutoGeneratedPermaId include Pageflow::NestedRevisionComponent belongs_to :section def self.all_for_revision(revision) joins(section: {chapter: {storyline: :revision}}) .where(pageflow_scrolled_storylines: {revision_id: revision}) end def self.select_used_type_names(revision, type_names) all_for_revision(revision) .where(type_name: type_names) .map(&:type_name) .uniq end # @api private class Batch def initialize(section, items) @section = section @storyline = section.chapter.storyline @items = items end def save! ContentElement.transaction do @items.map.with_index { |item, index| if item[:_delete] @section.content_elements.delete(item[:id]) nil else create_or_update(item, index) end }.compact end end private def create_or_update(item, index) attributes = { section_id: @section.id, position: index }.merge(item.slice(:type_name, :configuration)) if item[:id] @storyline.content_elements.update(item[:id], attributes) else @section.content_elements.create(attributes) end end end end end
Version data entries
11 entries across 11 versions & 1 rubygems