klastera 1.4.0.1 → 1.4.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a400414db24740d7888bd0627051715a8b81c6d6f481e15b3819958b043a984f
4
- data.tar.gz: 782575cb6ffd02a17dc9318878bc9b3b678e98760feb936038f18dd73dd99326
3
+ metadata.gz: 2c6ed8465fe9fcf78e96af1ad4d137ecdc867cc26242e0c4aada31557668b5db
4
+ data.tar.gz: 045d77f5c652c11aa1badd03c404c26b07a04ddd8d7bd7886b72ba47195d9339
5
5
  SHA512:
6
- metadata.gz: c5fe5cd793facd2af1ed367485daaac3822b7f2dda768d90d5aa92e5bc2a296860585d220076de1277e4bc0b5716daa4c560f9d93cc1464ff0839fb48cfa4ba8
7
- data.tar.gz: 9c01bd79e3df23f2e514ed9aab6b7e0c544a74bde7e2e88f98e18977d8e20833815e05ea0b85d36f9e72818ffe3edf34ee8c9ced19f5d81de7b4876f22a70e98
6
+ metadata.gz: 70bb42f25ded9aa221049e3d2fc25a88eb467514f562a99b5ffbc26e575a9bbf692e41af450201d82f00452f7d924e5b4f3a71409539d091ab60397de65fc379
7
+ data.tar.gz: 53e3902628bfac1f1353e0d6760483df4d82a51aa4ee32066c579e23b81bdb3832ab3ef9fc79ccff94d576971958ca4d00a8920ed7860ba7df1356c894b3c2c4
@@ -14,7 +14,7 @@ module Klastera::Concerns::ClusterUser
14
14
  #
15
15
  def clusters_of(organization,and_user=nil)
16
16
  and_user_id = and_user.present? ? { users: { id: and_user } } : {}
17
- ::Cluster.eager_load(cluster_users: :user).where({ organization_id: organization }.merge(and_user_id) )
17
+ ::Cluster.eager_load(cluster_users: :user).where({ organization_id: organization }.order(order: :asc).merge(and_user_id) )
18
18
  end
19
19
 
20
20
  ##
@@ -5,6 +5,7 @@ module Klastera
5
5
 
6
6
  extend ActiveSupport::Concern
7
7
 
8
+ UNCLUSTERED_POSITION = 9999
8
9
  UNCLUSTERED_ENTITY = 'without_cluster'.freeze
9
10
  KLSTR_HELPERS = %i[ cluster_user cluster_organization cluster_list cluster_scope cluster_scope_through_of user_clusters_string_list ].freeze
10
11
 
@@ -29,13 +30,15 @@ module Klastera
29
30
  if organization.is_in_cluster_mode? && user.cannot_skip_cluster_clause?
30
31
  active_record_collection = ::ClusterUser.clusters_of(organization,user)
31
32
  else
32
- active_record_collection = ::Cluster.where({ organization_id: organization })
33
+ active_record_collection = ::Cluster.where({ organization_id: organization }).order(order: :asc)
33
34
  end
34
35
 
35
36
  active_record_collection = active_record_collection.order(order: :asc)
36
37
 
37
38
  if include_unclustered && organization.optional_suborganization_mode? # For show and use modes only
38
- active_record_collection << ::Cluster.new({nid: UNCLUSTERED_ENTITY, name: I18n.t("klastera.#{UNCLUSTERED_ENTITY}")})
39
+ active_record_collection.append(
40
+ ::Cluster.new({nid: UNCLUSTERED_ENTITY, name: I18n.t("klastera.#{UNCLUSTERED_ENTITY}")}, order: UNCLUSTERED_POSITION )
41
+ )
39
42
  end
40
43
  active_record_collection
41
44
  end
@@ -85,7 +88,7 @@ module Klastera
85
88
  if cluster_filter.present?
86
89
  cluster_ids = cluster_filter.is_a?(Array) ? cluster_filter : [cluster_filter]
87
90
  elsif force_cluster_clause
88
- cluster_ids = ::ClusterUser.clusters_of(organization,user).map(&:id).sort
91
+ cluster_ids = ::ClusterUser.clusters_of(organization,user).map(&:id)
89
92
  end
90
93
  # We will avoid the query unless cluster_ids is having values OR force_cluster_clause is set (see method description)
91
94
  if cluster_ids.present? || force_cluster_clause
@@ -117,22 +120,37 @@ module Klastera
117
120
  unclusterized_scope.where("#{relation}_id" => cluster_scope!(cluster_entity_klass, user, organization, cluster_filter, force_cluster_clause))
118
121
  end
119
122
 
120
- # 
123
+ #
121
124
  # Returns an array with a clusterized scoped result and its grouped version
122
125
  #
123
126
  def group_by_cluster_scope!(scope_klass, user, organization, cluster_filter=[], scope_scopes=[])
124
127
  cluster_ids = cluster_filter.is_a?(Array) ? cluster_filter : [cluster_filter]
125
- kluster_scope = cluster_scope!(scope_klass, user, organization, cluster_ids, organization.optional_suborganization_mode? )
128
+ kluster_scope = cluster_scope!(scope_klass, user, organization, cluster_ids, organization.is_in_cluster_mode? )
129
+
126
130
  scope_scopes.each do |tuple_scope|
127
131
  scope_name, scope_arg = tuple_scope
128
132
  kluster_scope = scope_arg.present? ? kluster_scope.send(scope_name,scope_arg) : kluster_scope.send(scope_name)
129
133
  end
130
- [
131
- kluster_scope,
132
- kluster_scope.order(:cluster_id).group_by do |e|
133
- e.cluster.present? ? e.cluster.name : I18n.t("klastera.#{UNCLUSTERED_ENTITY}")
134
+
135
+ group_by_block = ->(o) {
136
+ if organization.is_in_cluster_mode?
137
+ o.cluster.present? ? o.cluster.name : UNCLUSTERED_POSITION
138
+ else
139
+ I18n.t("klastera.group_by_cluster_scope.#{scope_klass.model_name.plural}")
134
140
  end
135
- ]
141
+ }
142
+
143
+ grouped_cluster_scope = kluster_scope.group_by(&group_by_block).sort_by{|k,v|k.to_s}
144
+
145
+ grouped_cluster_scope.dup.each do |group|
146
+ if group.first == UNCLUSTERED_POSITION
147
+ grouped_cluster_scope.delete(group)
148
+ group[0] = I18n.t("klastera.#{UNCLUSTERED_ENTITY}")
149
+ grouped_cluster_scope.append(group)
150
+ end
151
+ end
152
+
153
+ [ kluster_scope, grouped_cluster_scope ]
136
154
  end
137
155
  end
138
156
 
@@ -1,3 +1,3 @@
1
1
  module Klastera
2
- VERSION = "1.4.0.1"
2
+ VERSION = "1.4.0.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klastera
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.0.1
4
+ version: 1.4.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gino Barahona
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-07-30 00:00:00.000000000 Z
11
+ date: 2020-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails