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.20 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.19 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.17 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.15 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.14 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.13 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.12 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.11.1 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.11 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.10 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.9 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.8 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.6 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.5 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.4.1 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.4 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.3 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.2 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.1 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb
active_scaffold-3.6.0 lib/active_scaffold/bridges/bitfields/bitfields_bridge.rb