Sha256: cfb83c250d47e2d54f10b3de0a80e5fbfb9f5c1a4c9d3f29ce5a4e62fabc162f

Contents?: true

Size: 598 Bytes

Versions: 3

Compression:

Stored size: 598 Bytes

Contents

# frozen_string_literal: true

module Decidim
  module Slider
    module Admin
      # TODO: Remove when upgrading to Decidim 0.28
      class ReorderContentBlocks < Decidim::Admin::ReorderContentBlocks
        private

        def set_new_weights
          data = order.each_with_index.inject({}) do |hash, (id, index)|
            hash.update(id => index + 1)
          end

          data.each do |id, weight|
            content_block = collection.find_by(id: id)
            content_block.update!(weight: weight) if content_block.present?
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
decidim-slider-0.0.3 app/commands/decidim/slider/admin/reorder_content_blocks.rb
decidim-slider-0.0.2 app/commands/decidim/slider/admin/reorder_content_blocks.rb
decidim-slider-0.0.1 app/commands/decidim/slider/admin/reorder_content_blocks.rb