Skip to content

Commit

Permalink
add ability to sort destinations by network type by customer order (#…
Browse files Browse the repository at this point in the history
…1682)

Co-authored-by: artemlutsenko <[email protected]>
  • Loading branch information
BigG1947 and artemlutsenko authored Jan 16, 2025
1 parent cecd7ef commit 39d08d6
Show file tree
Hide file tree
Showing 10 changed files with 185 additions and 50 deletions.
5 changes: 4 additions & 1 deletion app/admin/system/network_types.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:name,
:uuid

permit_params :name
permit_params :name, :sorting_priority

filter :id
filter :uuid_equals, label: 'UUID'
Expand All @@ -18,13 +18,15 @@
index do
id_column
column :name
column :sorting_priority
column :uuid
end

show do
attributes_table do
row :id
row :name
row :sorting_priority
row :uuid
end
end
Expand All @@ -33,6 +35,7 @@
f.semantic_errors *f.object.errors.attribute_names
f.inputs form_title do
f.input :name
f.input :sorting_priority
end
f.actions
end
Expand Down
7 changes: 4 additions & 3 deletions app/models/system/network_type.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#
# Table name: sys.network_types
#
# id :integer(2) not null, primary key
# name :string not null
# uuid :uuid not null
# id :integer(2) not null, primary key
# name :string not null
# sorting_priority :integer(2) default(999), not null
# uuid :uuid not null
#
# Indexes
#
Expand Down
8 changes: 6 additions & 2 deletions app/resources/api/rest/admin/destination_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ def self.creatable_fields(context)
end

def self.sortable_fields(_context = nil)
super + %i[country.name network.name]
super + %i[country.name network.name network_type.sorting_priority]
end

# related to issue https://github.com/cerebris/jsonapi-resources/issues/1409
def self.sort_records(records, order_options, context = {})
local_records = records
custom_sort_fields = %w[country.name network.name]
custom_sort_fields = %w[country.name network.name network_type.sorting_priority]

order_options.each_pair do |field, direction|
case field.to_s
Expand All @@ -101,6 +101,10 @@ def self.sort_records(records, order_options, context = {})
when 'network.name'
local_records = local_records.left_joins(:network).order("networks.name #{direction}")
order_options.delete('network.name')
when 'network_type.sorting_priority'
type_sorting = System::NetworkType.order(sorting_priority: direction).pluck(:id)
local_records = local_records.left_joins(:network).in_order_of(:'networks.type_id', type_sorting)
order_options.delete('network_type.sorting_priority')
else
local_records = apply_sort(local_records, order_options.except(*custom_sort_fields), context)
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class AddSortingPriorityToNetworkTypes < ActiveRecord::Migration[7.0]
def up
add_column :network_types, :sorting_priority, :smallint, default: 999, null: false
end

def down
remove_column :network_types, :sorting_priority
end
end
18 changes: 17 additions & 1 deletion db/network_types.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,64 @@
- id: 1
name: Unknown
uuid: d088d41e-52f7-11ea-a7a7-525400429a0c
sorting_priority: 150
- id: 2
name: Landline
uuid: 706ab0ee-f258-11ed-b425-00ffaa112233
sorting_priority: 10
- id: 3
name: Mobile
uuid: 706ab648-f258-11ed-b425-00ffaa112233
sorting_priority: 20
- id: 4
name: National
uuid: 706ab80a-f258-11ed-b425-00ffaa112233
sorting_priority: 130
- id: 5
name: Shared Cost
uuid: 706ab9b8-f258-11ed-b425-00ffaa112233
sorting_priority: 40
- id: 6
name: Toll-Free
uuid: 706abb48-f258-11ed-b425-00ffaa112233
sorting_priority: 30
- id: 7
name: Special Services
uuid: 706abcce-f258-11ed-b425-00ffaa112233
sorting_priority: 50
- id: 8
name: Short Code
uuid: 1ee3eda4-585f-11ee-9c63-2e13d2150000
sorting_priority: 100
- id: 9
name: Emergency
uuid: 22a20534-585f-11ee-a021-2e13d2150000
sorting_priority: 140
- id: 10
name: UIFN
uuid: baa5f68c-f27f-4649-acd2-e2b080b33906
sorting_priority: 80
- id: 11
name: Premium-rate, global telecommunication service
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af6
sorting_priority: 70
- id: 12
name: Paging
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af4
sorting_priority: 120
- id: 13
name: Supplementary services
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af3
sorting_priority: 60
- id: 14
name: Mobile/Paging
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af2
sorting_priority: 110
- id: 15
name: Satellite
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af1
sorting_priority: 90
- id: 16
name: Country Code
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af0
uuid: 52bfa8f7-383a-4bcf-90b4-43e4b3087af0
sorting_priority: 160
6 changes: 4 additions & 2 deletions db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -45127,7 +45127,8 @@ ALTER SEQUENCE sys.network_prefixes_id_seq OWNED BY sys.network_prefixes.id;
CREATE TABLE sys.network_types (
id smallint NOT NULL,
name character varying NOT NULL,
uuid uuid DEFAULT public.uuid_generate_v1() NOT NULL
uuid uuid DEFAULT public.uuid_generate_v1() NOT NULL,
sorting_priority smallint DEFAULT 999 NOT NULL
);


Expand Down Expand Up @@ -50187,6 +50188,7 @@ INSERT INTO "public"."schema_migrations" (version) VALUES
('20241216165130'),
('20241218154326'),
('20241231160003'),
('20250104221004');
('20250104221004'),
('20250115133012');


Loading

0 comments on commit 39d08d6

Please sign in to comment.