effective_organizations 0.0.4 → 0.0.8

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: 1680db25ffadd9aedde1cda52429e5b4d42ee4b2c6c2a16a801631099b7e3db6
4
- data.tar.gz: b0ba4cfb29be4714b411101f2c2a50e073a433458c69453f0f032d73b0bcbc4d
3
+ metadata.gz: 71f3a2d048f4c02e6388c77579b8c0ba2f348eb08574fcb9137759dceb0b5caa
4
+ data.tar.gz: c5fe4918cf3116a728c6d0bb6ae0acd4146f4ebd2148b9012dc905041a70523e
5
5
  SHA512:
6
- metadata.gz: cbb3f71d72a698486a909e5c7cb418adb1862254d4d1b3868ab4be56ce6a14c4fc18e7e6f3d1c71649700a7186f3ceeb144ef7fe866f5d5a7e71fe7589bbace4
7
- data.tar.gz: 4e3bd0d65a5b370d3f8ad1284dc660720af0bc5b39165c82b265ac421d75ddab6dc1246f63aeba5aebed32f6c77298f211073671420dcbbb9abf8dac3709615a
6
+ metadata.gz: 92bac27ea6827e568a9ec4ca409feb38e8b162e4b213ea63c7451570be3bc51aa03ee6fd89a6c4ef85da4307e74f19b1157ceafbaa87a9ca1bb25d8f94ba1f4c
7
+ data.tar.gz: 1a1fd5f3e02af92f13f4c303c12e11e08226e7dfb4f4e244d22b6785f8409493254cbe2b7d5c96000d5c9bb1705215e10b9cd1914828ceecf63d5acb2c336d8c
@@ -11,11 +11,24 @@ class EffectiveRepresentativesDatatable < Effective::Datatable
11
11
 
12
12
  col :roles, search: roles_collection
13
13
 
14
- actions_col
14
+ unless attributes[:actions] == false
15
+ actions_col
16
+ end
17
+
15
18
  end
16
19
 
17
20
  collection do
18
- Effective::Representative.deep.all.where(organization: current_user.organizations)
21
+ scope = Effective::Representative.deep.all.where(organization: current_user.organizations)
22
+
23
+ if attributes[:organization_id]
24
+ scope = scope.where(organization_id: attributes[:organization_id])
25
+ end
26
+
27
+ if attributes[:user_id]
28
+ scope = scope.where(user_id: attributes[:user_id])
29
+ end
30
+
31
+ scope
19
32
  end
20
33
 
21
34
  def roles_collection
@@ -6,11 +6,7 @@ module EffectiveOrganizationsOrganization
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module Base
9
- def effective_organizations_organization(users_source_type: nil)
10
- @effective_organizations_organization_opts = {
11
- users_source_type: users_source_type
12
- }
13
-
9
+ def effective_organizations_organization
14
10
  include ::EffectiveOrganizationsOrganization
15
11
  end
16
12
  end
@@ -32,8 +28,7 @@ module EffectiveOrganizationsOrganization
32
28
  has_many :representatives, -> { Effective::Representative.sorted },
33
29
  class_name: 'Effective::Representative', inverse_of: :organization, dependent: :delete_all
34
30
 
35
- has_many :users, through: :representatives,
36
- source_type: (@effective_organizations_organization_opts[:users_source_type] || (name.start_with?('Effective') ? '::User' : "#{name.split('::').first}::Organization"))
31
+ accepts_nested_attributes_for :representatives, allow_destroy: true
37
32
 
38
33
  effective_resource do
39
34
  title :string
@@ -54,8 +49,17 @@ module EffectiveOrganizationsOrganization
54
49
 
55
50
  # Instance Methods
56
51
 
57
- def to_s
58
- title.presence || 'New Organization'
52
+ def representative(user:)
53
+ representatives.find { |rep| rep.user_id == user.id }
54
+ end
55
+
56
+ # Find or build
57
+ def build_representative(user:)
58
+ representative(user: user) || representatives.build(user: user)
59
+ end
60
+
61
+ def users
62
+ representatives.reject(&:marked_for_destruction?).map(&:user)
59
63
  end
60
64
 
61
65
  end
@@ -6,11 +6,7 @@ module EffectiveOrganizationsUser
6
6
  extend ActiveSupport::Concern
7
7
 
8
8
  module Base
9
- def effective_organizations_user(organizations_source_type: nil)
10
- @effective_organizations_user_opts = {
11
- organizations_source_type: organizations_source_type
12
- }
13
-
9
+ def effective_organizations_user
14
10
  include ::EffectiveOrganizationsUser
15
11
  end
16
12
  end
@@ -20,17 +16,25 @@ module EffectiveOrganizationsUser
20
16
  end
21
17
 
22
18
  included do
23
- # My teams
24
19
  has_many :representatives, -> { Effective::Representative.sorted },
25
20
  class_name: 'Effective::Representative', inverse_of: :user, dependent: :delete_all
26
21
 
27
- # App scoped
28
- has_many :organizations, through: :representatives,
29
- source_type: @effective_organizations_user_opts[:organizations_source_type] || "#{name.split('::').first}::Organization"
22
+ accepts_nested_attributes_for :representatives, allow_destroy: true
30
23
  end
31
24
 
25
+ # Instance Methods
26
+
32
27
  def representative(organization:)
33
28
  representatives.find { |rep| rep.organization_id == organization.id }
34
29
  end
35
30
 
31
+ # Find or build
32
+ def build_representative(organization:)
33
+ representative(organization: organization) || representatives.build(organization: organization)
34
+ end
35
+
36
+ def organizations
37
+ representatives.reject(&:marked_for_destruction?).map(&:organization)
38
+ end
39
+
36
40
  end
@@ -4,7 +4,7 @@
4
4
  %p You belong to #{pluralize(current_user.organizations.length, 'organization')}
5
5
 
6
6
  - datatable = EffectiveResources.best('EffectiveOrganizationsDatatable').new(self, namespace: :effective)
7
- = render_datatable(datatable)
7
+ = render_datatable(datatable, simple: true)
8
8
 
9
9
  - else
10
10
  %p You do not belong to any organizations.
@@ -7,5 +7,5 @@
7
7
 
8
8
  - if organization.persisted?
9
9
  %h2 Representatives
10
- - datatable = EffectiveRepresentativesDatatable.new(organization_id: organization.id)
10
+ - datatable = EffectiveRepresentativesDatatable.new(organization: organization)
11
11
  = render_inline_datatable(datatable)
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrganizations
2
- VERSION = '0.0.4'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_organizations
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-12-15 00:00:00.000000000 Z
11
+ date: 2021-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails