effective_organizations 0.0.6 → 0.1.0

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: a2ee1cb9ffc7df883ea343966168245ab3d77ba59ef9753a20d825702ba46aaa
4
- data.tar.gz: fcd8f65d9dbc66c5073077e6bd7fe9f48774c4444d965c7c4ce95d09c3d97935
3
+ metadata.gz: 0ed8ea76f6be605f32e951431171d7be4d5c9885adf3adaa51ebd223ad2faa95
4
+ data.tar.gz: '08a0fa735dc997d95203d90abd6c5657855b6e957b00802800222cf8cfe00d5c'
5
5
  SHA512:
6
- metadata.gz: a34485e30e3d66f85cb4dff1ed2ccd6656134ac5171c2ceae64e8fc30336144c1ac6c9889dab98b018dbdad0c2b3bda96e583f70583a9907f09eaf1ed4ebe1a0
7
- data.tar.gz: fb7e677000619da597b0b43f5ae827211d2d55fca0d51326559b27bb7fc7fbd7b3155260afa37f7768360a0f695d2d80667dabc680414f2479582c645c438dac
6
+ metadata.gz: 31c96c8af942654f9d314326363228f2cead96f47cd0f7e32f256d7a2362e7e5601bdeb35be78c5bf102c8bfa21d6adfe61664cb991e1d10effe2de937aeef36
7
+ data.tar.gz: 62ebff63f53a735bb6d185648611d40f717dd469ea03f7f5cb62be5c6027d0248f10f77a38fc8ae2f8bea82d3c2eac9887ead68d847c8fffecaf71032d83d399
@@ -6,7 +6,7 @@ module Admin
6
6
  include Effective::CrudController
7
7
 
8
8
  resource_scope -> { EffectiveOrganizations.Organization.deep.all }
9
- datatable -> { Admin::EffectiveOrganizationsDatatable.new }
9
+ datatable -> { EffectiveResources.best('Admin::EffectiveOrganizationsDatatable').new }
10
10
 
11
11
  private
12
12
 
@@ -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
@@ -34,9 +30,6 @@ module EffectiveOrganizationsOrganization
34
30
 
35
31
  accepts_nested_attributes_for :representatives, allow_destroy: true
36
32
 
37
- has_many :users, through: :representatives,
38
- source_type: (@effective_organizations_organization_opts[:users_source_type] || (name.start_with?('Effective') ? '::User' : "#{name.split('::').first}::Organization"))
39
-
40
33
  effective_resource do
41
34
  title :string
42
35
  category :string
@@ -56,10 +49,6 @@ module EffectiveOrganizationsOrganization
56
49
 
57
50
  # Instance Methods
58
51
 
59
- def to_s
60
- title.presence || 'New Organization'
61
- end
62
-
63
52
  def representative(user:)
64
53
  representatives.find { |rep| rep.user_id == user.id }
65
54
  end
@@ -69,4 +58,8 @@ module EffectiveOrganizationsOrganization
69
58
  representative(user: user) || representatives.build(user: user)
70
59
  end
71
60
 
61
+ def users
62
+ representatives.reject(&:marked_for_destruction?).map(&:user)
63
+ end
64
+
72
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,19 +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
22
  accepts_nested_attributes_for :representatives, allow_destroy: true
28
-
29
- # App scoped
30
- has_many :organizations, through: :representatives,
31
- source_type: @effective_organizations_user_opts[:organizations_source_type] || "#{name.split('::').first}::Organization"
32
23
  end
33
24
 
25
+ # Instance Methods
26
+
34
27
  def representative(organization:)
35
28
  representatives.find { |rep| rep.organization_id == organization.id }
36
29
  end
37
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
+
38
40
  end
@@ -1,10 +1,10 @@
1
1
  %h2 Organizations
2
2
 
3
3
  - if current_user.organizations.present?
4
- %p You belong to #{pluralize(current_user.organizations.length, 'organization')}
4
+ %p You are a representative for #{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
- %p You do not belong to any organizations.
10
+ %p You are not a representative. When you create an organization, or if someone else adds you to their organization, we'll show them here.
@@ -1,3 +1,3 @@
1
1
  module EffectiveOrganizations
2
- VERSION = '0.0.6'.freeze
2
+ VERSION = '0.1.0'.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.6
4
+ version: 0.1.0
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-20 00:00:00.000000000 Z
11
+ date: 2022-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails