diff --git a/.gitignore b/.gitignore index 2c0e11f64..19b2adff0 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ config/pgq_processors.yml config/system_info.yml config/click_house.yml config/secrets.yml +config/ldap.yml coverage debian/files debian/yeti-web diff --git a/app/admin/routing/destinations.rb b/app/admin/routing/destinations.rb index 1debd2c9d..1e933fb9e 100644 --- a/app/admin/routing/destinations.rb +++ b/app/admin/routing/destinations.rb @@ -71,22 +71,13 @@ filter :network_prefix_country_id_eq, as: :select, label: 'Country', - input_html: { - class: 'chosen network_prefix_country_id_eq-filter' - }, + input_html: { class: 'chosen' }, collection: -> { System::Country.order(:name) } association_ajax_filter :network_prefix_network_id_eq, label: 'Network', scope: -> { System::Network.order(:name) }, - path: '/system_networks/search', - input_html: { - 'data-path-params': { 'q[country_id_eq]': '.network_prefix_country_id_eq-filter' }.to_json, - 'data-required-param': 'q[country_id_eq]' - }, - fill_params: lambda { - { country_id_eq: params.dig(:q, :network_prefix_country_id_eq) } - } + path: '/system_networks/search' filter :external_id_eq, label: 'EXTERNAL_ID' filter :valid_from, as: :date_time_range diff --git a/app/admin/routing/dialpeers.rb b/app/admin/routing/dialpeers.rb index a525bbd55..e4ec7e194 100644 --- a/app/admin/routing/dialpeers.rb +++ b/app/admin/routing/dialpeers.rb @@ -182,22 +182,13 @@ def scoped_collection filter :network_prefix_country_id_eq, as: :select, label: 'Country', - input_html: { - class: 'chosen network_prefix_country_id_eq-filter' - }, + input_html: { class: 'chosen' }, collection: -> { System::Country.order(:name) } association_ajax_filter :network_prefix_network_id_eq, label: 'Network', scope: -> { System::Network.order(:name) }, - path: '/system_networks/search', - input_html: { - 'data-path-params': { 'q[country_id_eq]': '.network_prefix_country_id_eq-filter' }.to_json, - 'data-required-param': 'q[country_id_eq]' - }, - fill_params: lambda { - { country_id_eq: params.dig(:q, :network_prefix_country_id_eq) } - } + path: '/system_networks/search' filter :created_at, as: :date_time_range filter :external_id diff --git a/app/admin/routing/routing_plan_static_routes.rb b/app/admin/routing/routing_plan_static_routes.rb index 6b7683ecf..b7049e256 100644 --- a/app/admin/routing/routing_plan_static_routes.rb +++ b/app/admin/routing/routing_plan_static_routes.rb @@ -19,8 +19,16 @@ filter :id filter :routing_plan, collection: -> { Routing::RoutingPlan.having_static_routes }, input_html: { class: 'chosen' } filter :prefix - filter :country, input_html: { class: 'chosen' } - filter :network, input_html: { class: 'chosen' } + filter :network_prefix_country_id_eq, + as: :select, + label: 'Country', + input_html: { class: 'chosen' }, + collection: -> { System::Country.order(:name) } + + association_ajax_filter :network_prefix_network_id_eq, + label: 'Network', + scope: -> { System::Network.order(:name) }, + path: '/system_networks/search' contractor_filter :vendor_id_eq, label: 'Vendor', path_params: { q: { vendor_eq: true } } # after_build do |resource| diff --git a/app/admin/system/network_prefixes.rb b/app/admin/system/network_prefixes.rb index c95d99169..c5b34e267 100644 --- a/app/admin/system/network_prefixes.rb +++ b/app/admin/system/network_prefixes.rb @@ -57,7 +57,10 @@ f.input :number_min_length f.input :number_max_length f.input :country, input_html: { class: 'chosen' } - f.input :network, input_html: { class: 'chosen' } + f.association_ajax_input :network_id, + label: 'Network', + scope: System::Network.order(:name), + path: '/system_networks/search' end f.actions end diff --git a/lib/active_admin/fast_count.rb b/lib/active_admin/fast_count.rb index 97597b120..d23e35771 100644 --- a/lib/active_admin/fast_count.rb +++ b/lib/active_admin/fast_count.rb @@ -22,5 +22,18 @@ def collection_size(records = collection) records.fast_count(:all) end end + + def current_page_collection_size + is_last_page = collection.total_count <= collection_offset + collection.limit_value + if is_last_page + collection.total_count - collection_offset + else + collection.limit_value + end + end + + def collection_offset + (collection.current_page - 1) * collection.limit_value + end end end diff --git a/lib/active_admin/views/components/paginated_collection.rb b/lib/active_admin/views/components/paginated_collection.rb index d6543c314..6c14808ec 100644 --- a/lib/active_admin/views/components/paginated_collection.rb +++ b/lib/active_admin/views/components/paginated_collection.rb @@ -7,6 +7,7 @@ class PaginatedCollection < ActiveAdmin::Component # def build(collection, options = {}) @collection = collection + @params = options.delete(:params) @param_name = options.delete(:param_name) @download_links = options.delete(:download_links) @display_total = options.delete(:pagination_total) { true } @@ -26,7 +27,7 @@ def build(collection, options = {}) @built = true end - protected + private def build_top_pagination_panel div class: 'pagination_top' do @@ -36,6 +37,49 @@ def build_top_pagination_panel end end end + + def page_entries_info(options = {}) + if options[:entry_name] + entry_name = options[:entry_name] + entries_name = options[:entries_name] || entry_name.pluralize + elsif collection_is_empty? + entry_name = I18n.t 'active_admin.pagination.entry', count: 1, default: 'entry' + entries_name = I18n.t 'active_admin.pagination.entry', count: 2, default: 'entries' + else + key = "activerecord.models.#{collection.first.class.model_name.i18n_key}" + entry_name = I18n.t key, count: 1, default: collection.first.class.name.underscore.sub('_', ' ') + entries_name = I18n.t key, count: collection.size, default: entry_name.pluralize + end + + if @display_total + if collection.total_pages < 2 + case collection_size + when 0 + I18n.t('active_admin.pagination.empty', model: entries_name) + when 1 + I18n.t('active_admin.pagination.one', model: entry_name) + else + I18n.t('active_admin.pagination.one_page', model: entries_name, n: collection.total_count) + end + else + offset = collection_offset + total = collection.total_count + I18n.t 'active_admin.pagination.multiple', + model: entries_name, + total:, + from: offset + 1, + to: offset + current_page_collection_size + end + else + # Do not display total count, in order to prevent a `SELECT count(*)`. + # To do so we must not call `collection.total_pages` + offset = (collection.current_page - 1) * collection.limit_value + I18n.t 'active_admin.pagination.multiple_without_total', + model: entries_name, + from: offset + 1, + to: offset + collection_size + end + end end end end diff --git a/spec/features/system/network_prefixes/new_network_prefix_spec.rb b/spec/features/system/network_prefixes/new_network_prefix_spec.rb index bb87caaeb..ec2a6c7af 100644 --- a/spec/features/system/network_prefixes/new_network_prefix_spec.rb +++ b/spec/features/system/network_prefixes/new_network_prefix_spec.rb @@ -13,7 +13,7 @@ visit new_system_network_prefix_path aa_form.set_text 'Prefix', '123' - aa_form.select_chosen 'Network', network.display_name + fill_in_chosen 'Network', with: network.name, ajax: true end it 'creates record' do