egov_utils 1.0.2 → 1.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 999501817d4aa5533235375d0d182b3816dcbe25126e0b26649e8b121b505f3b
4
- data.tar.gz: 030b79099740eb57801b9380908d57501607affc5c002e88c494e66bcfa70a3a
3
+ metadata.gz: 39d1cac9552de528bbd6fb76ab0f766289d3b0cbe795e2b5de0b0ac48558619a
4
+ data.tar.gz: ae2f54428922bd3a8ff814e243ceacad6fc65e06dee028351dcb64baf771a64b
5
5
  SHA512:
6
- metadata.gz: d363f4c2a920a0b09234b68281c6a7da47b23347971d27f426968404ebfd653e07cd359d9c08d34439608f4d174d23bb6cece844cb4daa1abf5d83731850ce47
7
- data.tar.gz: be24f8cd519b9812ef06d63e128a9bbe4fdd5ca09d2c261dbf128646c3ecb1fa30eabd4c9048269132ee1e66f867c7ae9c3daeaf78fe805e5ffb700b2a5c640f
6
+ metadata.gz: 13f02bb9e196af53330637d00e8127de164b19284f99988edcbfed14f0722449f04a70bb24dfcf7f93d08780b3eef8ad746e9923a51cc9bcc4b1e7558b4ac436
7
+ data.tar.gz: 9f3036d67042d62b3ec567e01da3fdbc60dc8a904026f883c60608d923e124a673a76d63f12dd9c81d149a3347389337aeafbad68ad529cbd3eef2703eae0b13
@@ -78,6 +78,7 @@ window.eGovUtilities =
78
78
  initSelect2: ($container)->
79
79
  $container ||= $(document)
80
80
  $('[data-provide="select2"]', $container).select2(width: null)
81
+ $('[data-provide="select2"]', $container).trigger("select2:initialized")
81
82
 
82
83
  destroySelect2: ($container)->
83
84
  $container ||= $(document)
@@ -1,7 +1,7 @@
1
1
  module EgovUtils
2
2
  class PeopleController < ApplicationController
3
3
 
4
- load_and_authorize_resource
4
+ load_and_authorize_resource only: :index
5
5
 
6
6
  def index
7
7
  @people_schema = PersonSchema.new
@@ -9,8 +9,8 @@ module EgovUtils
9
9
  respond_to do |format|
10
10
  if params['_type'] == 'query'
11
11
  format.json{ render json: {
12
- results: @people_schema.entities.includes(:residence).collect do |p|
13
- {id: p.id, text: p.to_s, residence: p.residence.to_s}
12
+ results: @people_schema.entities.includes(:residence, :addresses).collect do |p|
13
+ {id: p.id, text: p.to_s, residence: p.residence.to_s, addresses: p.addresses}
14
14
  end
15
15
  }}
16
16
  else
@@ -22,5 +22,21 @@ module EgovUtils
22
22
  def show
23
23
  end
24
24
 
25
+ def addresses
26
+ addresses = Address.where(person_id: params[:person_id])
27
+
28
+ render json: {
29
+ results: addresses.map do |a|
30
+ {
31
+ id: a.id,
32
+ text: a.to_s,
33
+ street: a.street,
34
+ number: a.number,
35
+ postcode: a.postcode,
36
+ city: a.city
37
+ }
38
+ end
39
+ }
40
+ end
25
41
  end
26
42
  end
@@ -1,7 +1,10 @@
1
1
  module EgovUtils
2
2
  class Person < ApplicationRecord
3
3
 
4
- belongs_to :residence, class_name: 'EgovUtils::Address', optional: true
4
+ # This is kept for accepts_nested_attributes_for compatibility, but
5
+ # overloaded below.
6
+ has_one :residence, class_name: 'EgovUtils::Address'
7
+ has_many :addresses
5
8
  has_one :natural_person, dependent: :destroy
6
9
  has_one :legal_person, dependent: :destroy
7
10
 
@@ -22,6 +25,14 @@ module EgovUtils
22
25
  end
23
26
  end
24
27
 
28
+ def residence
29
+ addresses.order(created_at: :desc).first
30
+ end
31
+
32
+ def residence=(address)
33
+ addresses << address
34
+ end
35
+
25
36
  def to_s
26
37
  person_entity.to_s
27
38
  end
data/config/routes.rb CHANGED
@@ -12,7 +12,9 @@ EgovUtils::Engine.routes.draw do
12
12
  get :confirm, on: :member
13
13
  end
14
14
 
15
- resources :people
15
+ resources :people do
16
+ get :addresses
17
+ end
16
18
 
17
19
  resources :groups do
18
20
  member do
@@ -0,0 +1,20 @@
1
+ class MigratePersonResidenceToAddresses < ActiveRecord::Migration[6.1]
2
+ def up
3
+ add_column :egov_utils_addresses, :person_id, :bigint, index: true
4
+ add_foreign_key :egov_utils_addresses, :egov_utils_people, column: :person_id
5
+
6
+ execute <<-SQL
7
+ UPDATE egov_utils_addresses
8
+ SET person_id = egov_utils_people.id
9
+ FROM egov_utils_people
10
+ WHERE egov_utils_addresses.id = egov_utils_people.residence_id;
11
+ SQL
12
+
13
+ remove_index :egov_utils_people, :residence_id
14
+ remove_column :egov_utils_people, :residence_id
15
+ end
16
+
17
+ def down
18
+ raise ActiveRecord::IrreversibleMigration
19
+ end
20
+ end
@@ -1,3 +1,3 @@
1
1
  module EgovUtils
2
- VERSION = '1.0.2'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: egov_utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ondřej Ezr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-05-16 00:00:00.000000000 Z
11
+ date: 2022-07-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -616,6 +616,7 @@ files:
616
616
  - db/migrate/20180403150556_create_egov_utils_legal_people.rb
617
617
  - db/migrate/20180424143207_add_titles_to_natural_people.rb
618
618
  - db/migrate/20220331113917_add_days_before_inactive_to_egov_utils_users.rb
619
+ - db/migrate/20220624070709_migrate_person_residence_to_addresses.rb
619
620
  - lib/azahara_schema_currency.rb
620
621
  - lib/azahara_schema_currency/aggregation_attribute_patch.rb
621
622
  - lib/azahara_schema_currency/association_attribute_patch.rb