Sha256: dc613aeeaa4dc9fa698519fe267b49783719ec288c707dc79775884405464d9b

Contents?: true

Size: 1.21 KB

Versions: 22

Compression:

Stored size: 1.21 KB

Contents

module ActiveScaffold
  module Bridges
    class Bitfields
      module BitfieldsBridge
        def initialize(model_id)
          super
          return unless model.respond_to?(:bitfields) && model.bitfields.present?

          model.bitfields.each_value do |options|
            columns << options.keys
            options.each do |column, value|
              columns[column].form_ui = :checkbox
              columns[column].weight = 1000 + value.to_s(2).size
            end
          end
        end

        def _setup_bitfields
          return unless model.respond_to?(:bitfields) && model.bitfields.present?
          model.bitfields.each do |column_name, options|
            columns = options.keys.sort_by { |column| self.columns[column].weight }
            %i[create update show subform].each do |action|
              next unless actions.include? action
              if send(action).columns.include? column_name
                send(action).columns.exclude column_name
                send(action).columns.add_subgroup(column_name) { |group| group.add(*columns) }
              else
                send(action).columns.exclude(*columns)
              end
            end
          end
        end
      end
    end
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
active_scaffold-3.6.0.rc2 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.0.rc1 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb