brick 1.0.199 → 1.0.201
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/brick/extensions.rb +196 -648
- data/lib/brick/frameworks/rails/engine.rb +55 -61
- data/lib/brick/frameworks/rails/form_tags.rb +3 -3
- data/lib/brick/reflect_tables.rb +582 -0
- data/lib/brick/route_mapper.rb +20 -4
- data/lib/brick/version_number.rb +1 -1
- data/lib/brick.rb +1 -0
- metadata +4 -3
| @@ -296,13 +296,13 @@ function linkSchemas() { | |
| 296 296 | 
             
                        end
         | 
| 297 297 |  | 
| 298 298 | 
             
                        module UrlHelpers
         | 
| 299 | 
            -
                          alias  | 
| 299 | 
            +
                          alias _brick_resources_path resources_path
         | 
| 300 300 | 
             
                          # Accommodate STI resources
         | 
| 301 | 
            -
                          def  | 
| 302 | 
            -
                            resource ||= if (klass =  | 
| 301 | 
            +
                          def resources_path(resource:, **kwargs)
         | 
| 302 | 
            +
                            resource ||= if (klass = resource.model_class)
         | 
| 303 303 | 
             
                                           Avo::App.resources.find { |r| r.model_class > klass }
         | 
| 304 304 | 
             
                                         end
         | 
| 305 | 
            -
                             | 
| 305 | 
            +
                            _brick_resources_path(resource: resource, **kwargs)
         | 
| 306 306 | 
             
                          end
         | 
| 307 307 | 
             
                        end
         | 
| 308 308 |  | 
| @@ -329,31 +329,50 @@ function linkSchemas() { | |
| 329 329 | 
             
                        #   end
         | 
| 330 330 | 
             
                        # end
         | 
| 331 331 |  | 
| 332 | 
            -
                         | 
| 333 | 
            -
             | 
| 334 | 
            -
             | 
| 335 | 
            -
                             | 
| 336 | 
            -
                               | 
| 337 | 
            -
                               | 
| 338 | 
            -
                                 | 
| 339 | 
            -
                                 | 
| 340 | 
            -
             | 
| 341 | 
            -
             | 
| 342 | 
            -
             | 
| 343 | 
            -
             | 
| 344 | 
            -
             | 
| 345 | 
            -
             | 
| 346 | 
            -
             | 
| 347 | 
            -
             | 
| 348 | 
            -
             | 
| 349 | 
            -
             | 
| 350 | 
            -
             | 
| 351 | 
            -
             | 
| 352 | 
            -
             | 
| 353 | 
            -
             | 
| 332 | 
            +
                        if self.const_defined?('Resources') &&
         | 
| 333 | 
            +
                           self::Resources.const_defined?('ResourceManager') # Avo 3.x?
         | 
| 334 | 
            +
                          self::Resources::ResourceManager.class_exec do
         | 
| 335 | 
            +
                            class << self
         | 
| 336 | 
            +
                              alias _brick_fetch_resources fetch_resources
         | 
| 337 | 
            +
                              def fetch_resources
         | 
| 338 | 
            +
                                Avo._brick_avo_resources
         | 
| 339 | 
            +
                                _brick_fetch_resources
         | 
| 340 | 
            +
                              end
         | 
| 341 | 
            +
                            end
         | 
| 342 | 
            +
                          end
         | 
| 343 | 
            +
                        else # Avo 2.x
         | 
| 344 | 
            +
                          (self::App.respond_to?(:eager_load) ? App : DynamicRouter).class_exec do
         | 
| 345 | 
            +
                            class << self
         | 
| 346 | 
            +
                              alias _brick_eager_load eager_load
         | 
| 347 | 
            +
                              def eager_load(entity)
         | 
| 348 | 
            +
                                Avo._brick_avo_resources(true) if entity == :resources
         | 
| 349 | 
            +
                                _brick_eager_load(entity)
         | 
| 350 | 
            +
                              end
         | 
| 351 | 
            +
                            end
         | 
| 352 | 
            +
                          end
         | 
| 353 | 
            +
                        end
         | 
| 354 | 
            +
             | 
| 355 | 
            +
                        def self._brick_avo_resources(is_2x = nil)
         | 
| 356 | 
            +
                          possible_schema, _x1, _x2 = ::Brick.get_possible_schemas
         | 
| 357 | 
            +
                          if possible_schema
         | 
| 358 | 
            +
                            orig_tenant = Apartment::Tenant.current
         | 
| 359 | 
            +
                            Apartment::Tenant.switch!(possible_schema)
         | 
| 360 | 
            +
                          end
         | 
| 361 | 
            +
                          existing = Avo::BaseResource.descendants.each_with_object({}) do |r, s|
         | 
| 362 | 
            +
                                       s[r.name[0..-9]] = nil if r.name.end_with?('Resource')
         | 
| 363 | 
            +
                                     end
         | 
| 364 | 
            +
                          ::Brick.relations.each do |k, v|
         | 
| 365 | 
            +
                            unless k.is_a?(Symbol) || existing.key?(class_name = v[:class_name]) || Brick.config.exclude_tables.include?(k) ||
         | 
| 366 | 
            +
                                   class_name.blank? || class_name.include?('::') ||
         | 
| 367 | 
            +
                                   ['ActiveAdminComment', 'MotorAlert', 'MotorAlertLock', 'MotorApiConfig', 'MotorAudit', 'MotorConfig', 'MotorDashboard', 'MotorForm', 'MotorNote', 'MotorNoteTag', 'MotorNoteTagTag', 'MotorNotification', 'MotorQuery', 'MotorReminder', 'MotorResource', 'MotorTag', 'MotorTaggableTag'].include?(class_name)
         | 
| 368 | 
            +
                              if is_2x # Avo 2.x?
         | 
| 369 | 
            +
                                "::#{class_name}Resource".constantize
         | 
| 370 | 
            +
                              else # Avo 3.x
         | 
| 371 | 
            +
                                ::Brick.avo_3x_resource(Object.const_get(class_name), class_name) unless ::Avo::BaseResource.constants.include?(class_name.to_sym)
         | 
| 354 372 | 
             
                              end
         | 
| 355 373 | 
             
                            end
         | 
| 356 374 | 
             
                          end
         | 
| 375 | 
            +
                          Apartment::Tenant.switch!(orig_tenant) if orig_tenant
         | 
| 357 376 | 
             
                        end
         | 
| 358 377 |  | 
| 359 378 | 
             
                        # Add our schema link Javascript code when the TurboFrameWrapper is rendered so it ends up on all index / show / etc
         | 
| @@ -409,18 +428,21 @@ window.addEventListener(\"popstate\", linkSchemas); | |
| 409 428 | 
             
                        class Fields::IndexComponent
         | 
| 410 429 | 
             
                          alias _brick_resource_view_path resource_view_path
         | 
| 411 430 | 
             
                          def resource_view_path
         | 
| 412 | 
            -
                             | 
| 431 | 
            +
                            mdl_class = @resource.respond_to?(:model_class) ? @resource.model_class : @resource.model&.class
         | 
| 432 | 
            +
                            return if mdl_class&.is_view?
         | 
| 413 433 |  | 
| 414 434 | 
             
                            _brick_resource_view_path
         | 
| 415 435 | 
             
                          end
         | 
| 416 436 | 
             
                        end
         | 
| 417 437 |  | 
| 418 438 | 
             
                        module Concerns::HasFields
         | 
| 419 | 
            -
                           | 
| 420 | 
            -
                             | 
| 421 | 
            -
             | 
| 422 | 
            -
                               | 
| 423 | 
            -
             | 
| 439 | 
            +
                          class << self
         | 
| 440 | 
            +
                            if respond_to?(:field)
         | 
| 441 | 
            +
                              alias _brick_field field
         | 
| 442 | 
            +
                              def field(name, *args, **kwargs, &block)
         | 
| 443 | 
            +
                                kwargs.merge!(args.pop) if args.last.is_a?(Hash)
         | 
| 444 | 
            +
                                _brick_field(name, **kwargs, &block)
         | 
| 445 | 
            +
                              end
         | 
| 424 446 | 
             
                            end
         | 
| 425 447 | 
             
                          end
         | 
| 426 448 | 
             
                        end
         | 
| @@ -794,7 +816,7 @@ window.addEventListener(\"popstate\", linkSchemas); | |
| 794 816 | 
             
                                            if (rowcount = rel.last.fetch(:rowcount, nil))
         | 
| 795 817 | 
             
                                              rowcount = rowcount > 0 ? " (#{rowcount})" : nil
         | 
| 796 818 | 
             
                                            end
         | 
| 797 | 
            -
                                            s << "<option value=\"#{::Brick._brick_index(rel.first, nil, '/')}\">#{rel.first}#{rowcount}</option>"
         | 
| 819 | 
            +
                                            s << "<option value=\"#{::Brick._brick_index(rel.first, nil, '/', nil, true)}\">#{rel.first}#{rowcount}</option>"
         | 
| 798 820 | 
             
                                          end.html_safe
         | 
| 799 821 | 
             
                          prefix = "#{::Brick.config.path_prefix}/" if ::Brick.config.path_prefix
         | 
| 800 822 | 
             
                          table_options << "<option value=\"#{prefix}brick_status\">(Status)</option>".html_safe if ::Brick.config.add_status
         | 
| @@ -1955,34 +1977,6 @@ document.querySelectorAll(\"input, select\").forEach(function (inp) { | |
| 1955 1977 | 
             
                      end # TemplateRenderer
         | 
| 1956 1978 | 
             
                    end
         | 
| 1957 1979 |  | 
| 1958 | 
            -
                    if ::Brick.enable_routes?
         | 
| 1959 | 
            -
                      require 'brick/route_mapper'
         | 
| 1960 | 
            -
                      ActionDispatch::Routing::RouteSet.class_exec do
         | 
| 1961 | 
            -
                        # In order to defer auto-creation of any routes that already exist, calculate Brick routes only after having loaded all others
         | 
| 1962 | 
            -
                        prepend ::Brick::RouteSet
         | 
| 1963 | 
            -
                      end
         | 
| 1964 | 
            -
                      ActionDispatch::Routing::Mapper.class_exec do
         | 
| 1965 | 
            -
                        include ::Brick::RouteMapper
         | 
| 1966 | 
            -
                      end
         | 
| 1967 | 
            -
             | 
| 1968 | 
            -
                      # Do the root route before the Rails Welcome one would otherwise take precedence
         | 
| 1969 | 
            -
                      if (route = ::Brick.config.default_route_fallback).present?
         | 
| 1970 | 
            -
                        action = "#{route}#{'#index' unless route.index('#')}"
         | 
| 1971 | 
            -
                        if ::Brick.config.path_prefix
         | 
| 1972 | 
            -
                          ::Rails.application.routes.append do
         | 
| 1973 | 
            -
                            send(:namespace, ::Brick.config.path_prefix) do
         | 
| 1974 | 
            -
                              send(:root, action)
         | 
| 1975 | 
            -
                            end
         | 
| 1976 | 
            -
                          end
         | 
| 1977 | 
            -
                        elsif ::Rails.application.routes.named_routes.send(:routes)[:root].nil?
         | 
| 1978 | 
            -
                          ::Rails.application.routes.append do
         | 
| 1979 | 
            -
                            send(:root, action)
         | 
| 1980 | 
            -
                          end
         | 
| 1981 | 
            -
                        end
         | 
| 1982 | 
            -
                        ::Brick.established_drf = "/#{::Brick.config.path_prefix}#{action[action.index('#')..-1]}"
         | 
| 1983 | 
            -
                      end
         | 
| 1984 | 
            -
                    end
         | 
| 1985 | 
            -
             | 
| 1986 1980 | 
             
                    # Just in case it hadn't been done previously when we tried to load the brick initialiser,
         | 
| 1987 1981 | 
             
                    # go make sure we've loaded additional references (virtual foreign keys and polymorphic associations).
         | 
| 1988 1982 | 
             
                    # (This should only happen if for whatever reason the initializer file was not exactly config/initializers/brick.rb.)
         | 
| @@ -222,7 +222,7 @@ module Brick::Rails::FormTags | |
| 222 222 | 
             
                            out << link_to(ho_txt, send("#{hm_klass.base_class._brick_index(:singular)}_path".to_sym, ho_id))
         | 
| 223 223 | 
             
                          end
         | 
| 224 224 | 
             
                        elsif obj.respond_to?(ct_col = hms_col[1].to_sym) && (ct = obj.send(ct_col)&.to_i)&.positive?
         | 
| 225 | 
            -
                          predicates = hms_col[2].each_with_object({}) { |v, s| s["__#{v.first}"] = v.last.is_a?(String) ? v.last : obj.send(v.last) }
         | 
| 225 | 
            +
                          predicates = hms_col[2].each_with_object({}) { |v, s| s["__#{v.first}"] = v.last.is_a?(String) ? v.last : obj.send(v.last) if v.last }
         | 
| 226 226 | 
             
                          predicates.each { |k, v| predicates[k] = klass.name if v == '[sti_type]' }
         | 
| 227 227 | 
             
                          out << "#{link_to("#{ct || 'View'} #{hms_col.first}",
         | 
| 228 228 | 
             
                                            send("#{hm_klass._brick_index}_path".to_sym, predicates))}\n"
         | 
| @@ -592,11 +592,11 @@ function onImagesLoaded(event) { | |
| 592 592 | 
             
                  relation = ::Brick.relations.fetch(rel_name || klass.table_name, nil)
         | 
| 593 593 | 
             
                  if (klass_or_obj&.is_a?(Class) && klass_or_obj < ActiveRecord::Base) ||
         | 
| 594 594 | 
             
                     (klass_or_obj&.is_a?(ActiveRecord::Base) && klass_or_obj.new_record? && (klass_or_obj = klass_or_obj.class))
         | 
| 595 | 
            -
                    path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index(nil, '/', relation), action: :index)}#{filter}"
         | 
| 595 | 
            +
                    path = (proc = kwargs[:index_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.base_class._brick_index(nil, '/', relation, true), action: :index)}#{filter}"
         | 
| 596 596 | 
             
                    lt_args = [text || "Index for #{klass_or_obj.name.pluralize}", path]
         | 
| 597 597 | 
             
                  else
         | 
| 598 598 | 
             
                    # If there are multiple incoming parameters then last one is probably the actual ID, and first few might be some nested tree of stuff leading up to it
         | 
| 599 | 
            -
                    path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index(nil, '/', relation), action: :show, id: klass_or_obj)}#{filter}"
         | 
| 599 | 
            +
                    path = (proc = kwargs[:show_proc]) ? proc.call(klass_or_obj, relation) : "#{app_routes.path_for(controller: klass_or_obj.class.base_class._brick_index(nil, '/', relation, true), action: :show, id: klass_or_obj)}#{filter}"
         | 
| 600 600 | 
             
                    lt_args = [text || "Show this #{klass_or_obj.class.name}", path]
         | 
| 601 601 | 
             
                  end
         | 
| 602 602 | 
             
                  kwargs.delete(:visited)
         |