klastera 1.2.3 → 1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/models/klastera/concerns/cluster.rb +1 -0
- data/app/models/klastera/concerns/cluster_filter.rb +1 -4
- data/app/models/klastera/concerns/cluster_user.rb +20 -36
- data/app/models/klastera/concerns/clusterizable.rb +15 -5
- data/app/views/layouts/klastera/_cluster_entity_fields.html.erb +1 -1
- data/app/views/layouts/klastera/_cluster_filter.html.erb +1 -1
- data/app/views/layouts/klastera/_cluster_selector.html.erb +1 -1
- data/app/views/layouts/klastera/_nested_cluster_entity.html.erb +3 -1
- data/config/locales/es.yml +1 -0
- data/lib/klastera.rb +140 -137
- data/lib/klastera/version.rb +2 -2
- data/lib/tasks/klastera_tasks.rake +5 -0
- metadata +2 -3
- data/app/helpers/klastera/clusters_helper.rb +0 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 999d5c067d080b90f56c82a36cbeb286e08000bf09af922845bdd67df023d16c
|
4
|
+
data.tar.gz: e4e105b33d55b228cc4d515e0167586b7b962218860d78593a29f6a71b436712
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6902637aaf11219cff0b3ed2f9dcdf1f86c74d2e6c43211d683c559177da39498220d5fca6b987418b936a89c6b08dde5d49a0014d0b86d1fe3c258612912f92
|
7
|
+
data.tar.gz: 1ec8aad0c6793c426c01969bcdb9f04deed692b06499b0726ee047f13932fda3fe5046067432604947cf85e68662269569d61c482971b8855595a92dc87d1d29
|
@@ -11,6 +11,7 @@ module Klastera::Concerns::Cluster
|
|
11
11
|
MODES = [ :required_suborganization, :optional_suborganization, :optional_filter ].freeze
|
12
12
|
|
13
13
|
belongs_to :organization, class_name: Klastera.organization_class
|
14
|
+
has_many :cluster_users
|
14
15
|
|
15
16
|
scope :of, -> (organization,except_ids=[]) {
|
16
17
|
_scope = where(organization: organization)
|
@@ -4,11 +4,8 @@ module Klastera::Concerns::ClusterFilter
|
|
4
4
|
included do
|
5
5
|
include ActiveModel::Model
|
6
6
|
include ActiveModel::Validations::Callbacks
|
7
|
-
attr_accessor :cluster_id
|
8
7
|
|
9
|
-
|
10
|
-
self.cluster_id == 'without_cluster' ? nil : self.cluster_id
|
11
|
-
end
|
8
|
+
attr_accessor :cluster_id
|
12
9
|
end
|
13
10
|
|
14
11
|
module ClassMethods
|
@@ -3,55 +3,39 @@ module Klastera::Concerns::ClusterUser
|
|
3
3
|
|
4
4
|
included do
|
5
5
|
self.table_name = 'cluster_users'
|
6
|
-
|
7
6
|
belongs_to :user
|
8
7
|
belongs_to :cluster
|
9
|
-
|
10
8
|
validates :cluster_id, presence: true
|
11
|
-
|
12
|
-
scope :of, -> (user,organization) {
|
13
|
-
Rails.logger.warn("DON'T USE THIS SCOPE DIRECTLY: Use ::ClusterUser.clusters_from class method instead!")
|
14
|
-
includes(:cluster).where(user_id: user, "clusters.organization_id": organization)
|
15
|
-
}
|
16
9
|
end
|
17
10
|
|
18
11
|
module ClassMethods
|
12
|
+
##
|
13
|
+
# Return a Cluster::ActiveRecord_Relation of organization (and) user
|
14
|
+
#
|
15
|
+
def clusters_of(organization,and_user=nil)
|
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) )
|
18
|
+
end
|
19
19
|
|
20
20
|
##
|
21
|
-
|
22
|
-
|
23
|
-
def
|
24
|
-
|
25
|
-
organization_cluster_ids = ::Cluster.of(organization).map(&:id)
|
26
|
-
::ClusterUser.includes(:user).where(cluster_id: organization_cluster_ids).each do |cluster_user|
|
27
|
-
user_id = cluster_user.user_id || :uncluster
|
28
|
-
users_hash[user_id] ||= []
|
29
|
-
users_hash[user_id] << cluster_user.cluster_id
|
30
|
-
end
|
31
|
-
users_hash
|
21
|
+
# Return a User::ActiveRecord_Relation of organization (and) user
|
22
|
+
#
|
23
|
+
def users_of(organization)
|
24
|
+
::User.eager_load(:cluster_users).where(users: { organization_id: organization } )
|
32
25
|
end
|
33
26
|
|
34
27
|
##
|
35
|
-
#
|
28
|
+
# Return a hash of users and its clusters
|
36
29
|
#
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
# TODO: resolve it without quering twice
|
45
|
-
clusters_id = ::ClusterUser.of(user,organization).map(&:cluster_id)
|
46
|
-
clusters = ::Cluster.where(id: clusters_id)
|
47
|
-
# Add a empty cluster instance to handle models without a cluster assignation. Only for use and show modes
|
48
|
-
if organization.optional_mode?
|
49
|
-
clusters << ::Cluster.new({nid: :without_cluster, name: I18n.t('klastera.without_cluster')})
|
50
|
-
end
|
51
|
-
else
|
52
|
-
clusters = ::Cluster.of(organization)
|
30
|
+
def users_hash_of(organization)
|
31
|
+
users = {}
|
32
|
+
rows = self.users_of(organization).pluck("users.id AS user_id","cluster_users.cluster_id").uniq
|
33
|
+
rows.each do |row|
|
34
|
+
user_id = row.first
|
35
|
+
users[user_id] ||= []
|
36
|
+
users[user_id] << row.last
|
53
37
|
end
|
54
|
-
|
38
|
+
users
|
55
39
|
end
|
56
40
|
end
|
57
41
|
end
|
@@ -9,10 +9,7 @@ module Klastera::Concerns::Clusterizable
|
|
9
9
|
|
10
10
|
validates :cluster_id, presence: true, if: proc { self.try(:cluster_id) && self.organization.required_suborganization_mode? }
|
11
11
|
validate :at_least_one_cluster_entity, if: proc { self.organization.required_suborganization_mode? }
|
12
|
-
|
13
|
-
scope :related_clusters, ->() {
|
14
|
-
includes(:cluster_entities).where("cluster_entities.entity_id = #{self.table_name}.id")
|
15
|
-
}
|
12
|
+
validate :uniqueness_of_cluster_entity_record
|
16
13
|
|
17
14
|
def at_least_one_cluster_entity
|
18
15
|
if cluster_entities.length == 0 || cluster_entities.reject{|cluster_entity| cluster_entity._destroy == true}.empty?
|
@@ -20,8 +17,15 @@ module Klastera::Concerns::Clusterizable
|
|
20
17
|
end
|
21
18
|
end
|
22
19
|
|
20
|
+
##
|
21
|
+
# This is a legacy method and we don't recommend using it.
|
22
|
+
# Implement directly Klastera.entity_clusters_string_list instead of this method.
|
23
|
+
# TODO: In order to deprecate it, you will need to perform some changes in the main app
|
24
|
+
##
|
23
25
|
def clusters_string_separated_by(separator,attribute=:name)
|
24
|
-
|
26
|
+
Klastera.entity_clusters_string_list!(
|
27
|
+
self.cluster_entities, separator, attribute
|
28
|
+
)
|
25
29
|
end
|
26
30
|
|
27
31
|
def has_one_cluster_entity
|
@@ -29,6 +33,12 @@ module Klastera::Concerns::Clusterizable
|
|
29
33
|
return errors.add(:cluster_entities, I18n.t('klastera.messages.has_one_cluster_entity'))
|
30
34
|
end
|
31
35
|
end
|
36
|
+
|
37
|
+
def uniqueness_of_cluster_entity_record
|
38
|
+
if cluster_entities.map(&:cluster_id).uniq.size != cluster_entities.size
|
39
|
+
return errors.add(:cluster_entities, I18n.t('klastera.messages.duplicated_cluster_entity') )
|
40
|
+
end
|
41
|
+
end
|
32
42
|
end
|
33
43
|
|
34
44
|
module ClassMethods
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<tr class="nested-fields">
|
2
2
|
<td class="field">
|
3
|
-
<%= f.select :cluster_id,
|
3
|
+
<%= f.select :cluster_id, @clusters_session.map{|c|[c.name,c.id]}, { include_blank: true }, { class: 'form-control' } %>
|
4
4
|
</td>
|
5
5
|
<td class="action vertical-align-middle text-center" width="44">
|
6
6
|
<%= link_to_remove_association f, class: 'btn btn-danger btn-xs text-danger' do %>
|
@@ -7,7 +7,7 @@
|
|
7
7
|
<%=yield(f) if block_given? %>
|
8
8
|
|
9
9
|
<% if cluster_organization.is_in_cluster_mode? %>
|
10
|
-
<% cluster_collection =
|
10
|
+
<% cluster_collection = cluster_of_my_own.map{|c|[c.name,(c.id||c.nid)]} %>
|
11
11
|
<% if cluster_collection.size > 1 %>
|
12
12
|
<div class="inline-label-control-block">
|
13
13
|
<%= f.input :cluster_id, collection: cluster_collection, prompt: t('klastera.clusters.all'), label: false, wrapper: false %>
|
@@ -4,7 +4,7 @@
|
|
4
4
|
%>
|
5
5
|
<% if cluster_organization.is_in_cluster_mode? || other_visibility_reason %>
|
6
6
|
<%
|
7
|
-
cluster_collection = @
|
7
|
+
cluster_collection = @clusters_session || cluster_of_my_own
|
8
8
|
label = t('klastera.cluster.title')
|
9
9
|
%>
|
10
10
|
<% if f.nil? %>
|
@@ -1,4 +1,5 @@
|
|
1
|
-
<% if cluster_organization.is_in_cluster_mode?
|
1
|
+
<% if cluster_organization.is_in_cluster_mode? %>
|
2
|
+
<% @clusters_session = cluster_of_my_own %>
|
2
3
|
<div class="col-xs-12">
|
3
4
|
<% if hide_title||=false %>
|
4
5
|
<div class="form-group file required <%=f.object.class.name.parameterize%>_cluster_entity<%=' has-error' if f.object.errors.has_key?(:cluster_entities)%>">
|
@@ -26,6 +27,7 @@
|
|
26
27
|
<table id="cluster-entities" class="table table-striped">
|
27
28
|
<tbody class="cluster-entity-rows">
|
28
29
|
<%= f.fields_for :cluster_entities do |cluster_entity|%>
|
30
|
+
<% next unless @clusters_session.map(&:id).include?(cluster_entity.try(:object).try(:cluster_id)) %>
|
29
31
|
<%= render 'layouts/klastera/cluster_entity_fields', f: cluster_entity %>
|
30
32
|
<% end %>
|
31
33
|
</body>
|
data/config/locales/es.yml
CHANGED
@@ -61,6 +61,7 @@ es:
|
|
61
61
|
at_least_one_cluster_entity: Debe agregar al menos un cluster
|
62
62
|
record_action_successfully: Registro %{a} exitosamente
|
63
63
|
cant_delete_the_last_record_in_required_suborganization_mode: No se puede eliminar el único cluster de esta organización
|
64
|
+
duplicated_cluster_entity: Hay un cluster duplicado
|
64
65
|
new_cluster_id:
|
65
66
|
nil: Cluster no existe
|
66
67
|
same: Cluster no puede ser el mismo
|
data/lib/klastera.rb
CHANGED
@@ -5,8 +5,17 @@ module Klastera
|
|
5
5
|
|
6
6
|
extend ActiveSupport::Concern
|
7
7
|
|
8
|
+
UNCLUSTERED_ENTITY = 'without_cluster'
|
9
|
+
KLSTR_HELPERS = %i[
|
10
|
+
cluster_user cluster_organization user_has_more_than_one_cluster cluster_scope cluster_of_my_own
|
11
|
+
user_clusters_string_list set_collection_before_group_by_entity
|
12
|
+
]
|
13
|
+
|
8
14
|
class << self
|
9
15
|
|
16
|
+
##
|
17
|
+
#
|
18
|
+
#
|
10
19
|
def set_cluster_entities_attributes!(entity,array_cluster_ids)
|
11
20
|
cluster_entities_attributes = {}
|
12
21
|
entity_cluster_entities = entity.try(:cluster_entities) || []
|
@@ -29,90 +38,77 @@ module Klastera
|
|
29
38
|
cluster_entities_attributes
|
30
39
|
end
|
31
40
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
def
|
36
|
-
self.filter_clusterized_collection_with!(
|
37
|
-
organization,
|
38
|
-
cluster_id,
|
39
|
-
self.cluster_scope!(user,organization,scope,includes)
|
40
|
-
)
|
41
|
-
end
|
42
|
-
|
43
|
-
#
|
44
|
-
# In order to this works, active_record_collection argument
|
45
|
-
# should be passed through cluster_scope! method before.
|
46
|
-
#
|
47
|
-
def filter_clusterized_collection_with!(cluster_organization,cluster_id,active_record_collection)
|
48
|
-
if cluster_organization.is_in_cluster_mode?
|
49
|
-
if cluster_id.present?
|
50
|
-
cluster_array = [cluster_id]
|
51
|
-
# Based on force/use/show definition we don't really need this validation.
|
52
|
-
# A force cluster organization won't return an entity out of a cluster, but
|
53
|
-
# we don't know if the clusterized entities are fully definition-compliant.
|
54
|
-
cluster_array << nil if cluster_organization.optional_suborganization_mode?
|
55
|
-
active_record_collection = active_record_collection.joins(:cluster_entities).where("cluster_entities.cluster_id": cluster_array)
|
56
|
-
end
|
57
|
-
# you may use a block only with clusterizable data
|
58
|
-
yield(active_record_collection) if block_given?
|
59
|
-
end
|
60
|
-
active_record_collection
|
61
|
-
end
|
62
|
-
|
63
|
-
#
|
64
|
-
#
|
65
|
-
#
|
66
|
-
def set_collection_before_group_by_entity!(cluster_organization,active_record_collection,model_class,entity_params)
|
41
|
+
##
|
42
|
+
#
|
43
|
+
#
|
44
|
+
def set_collection_before_group_by_entity!(active_record_collection,entity_params,organization)
|
67
45
|
entity_params_keys = [:entity_name,:entity_attribute,:entity_id,:entity_id_attribute,:unamed]
|
46
|
+
entity_params[:entity_id] ||= nil #Ensures the entity_id attribute presence even if there is no filter
|
68
47
|
entity_params = entity_params.slice(*entity_params_keys).values
|
69
|
-
|
48
|
+
model_class = active_record_collection.model.base_class
|
49
|
+
model_relations = model_class.reflections.keys
|
50
|
+
if model_relations.include?(entity_params[0])
|
70
51
|
entity_params << "#{entity_params[0]}_id".to_sym
|
71
52
|
if entity_params[0] == 'cluster'
|
72
|
-
entity_params << :unclustered if
|
73
|
-
active_record_collection = Klastera.
|
74
|
-
|
53
|
+
entity_params << :unclustered if organization.is_in_cluster_mode?
|
54
|
+
active_record_collection = Klastera.filter_clusterized!(
|
55
|
+
active_record_collection,
|
75
56
|
entity_params[2],
|
76
|
-
|
57
|
+
organization
|
77
58
|
)
|
78
59
|
end
|
79
|
-
yield(
|
80
|
-
active_record_collection,
|
81
|
-
entity_params_keys.zip(entity_params).to_h)
|
60
|
+
yield( active_record_collection, entity_params_keys.zip(entity_params).to_h )
|
82
61
|
end
|
83
62
|
end
|
84
63
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
def
|
89
|
-
|
64
|
+
#
|
65
|
+
# In order to this work, the active_record_collection argument should be a cluster_scope! return.
|
66
|
+
#
|
67
|
+
def filter_clusterized!(active_record_collection,cluster_id,organization)
|
68
|
+
if organization.is_in_cluster_mode? && cluster_id.present?
|
69
|
+
# Ensures that an array of ids is used in the statement
|
70
|
+
cluster_array = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
|
71
|
+
# If we receive a UNCLUSTERED_ENTITY request, it means that we should filter by entities without clusters.
|
72
|
+
# The optional_mode?(show/use) condition add to this method an ambivalent use,
|
73
|
+
# where you can filter a unique value or multiple including NULL ones.
|
74
|
+
cluster_array << nil if cluster_array.delete(UNCLUSTERED_ENTITY) || organization.optional_mode?
|
75
|
+
active_record_collection = active_record_collection.where(cluster_entities: { cluster_id: cluster_array.uniq })
|
76
|
+
# You should use a block with clusterable data only
|
77
|
+
yield(active_record_collection) if block_given?
|
78
|
+
end
|
79
|
+
active_record_collection
|
90
80
|
end
|
91
81
|
|
92
82
|
##
|
93
|
-
#
|
94
|
-
# organization if the cluster mode is not active.
|
83
|
+
# If the cluster mode is not active, this returns a scope filtered by clusters of its organization/users/cluster
|
95
84
|
#
|
96
|
-
def cluster_scope!(user,organization,
|
85
|
+
def cluster_scope!(scope,user,organization,cluster_id=nil)
|
97
86
|
scope_klass = scope_class(scope).where(organization_id: organization)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
cluster_ids =
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
scope_klass =
|
87
|
+
if organization.is_in_cluster_mode?
|
88
|
+
|
89
|
+
if cluster_id.present?
|
90
|
+
# Ensures that an array of id is used in the statement
|
91
|
+
cluster_ids = cluster_id.is_a?(Array) ? cluster_id : [cluster_id]
|
92
|
+
else
|
93
|
+
clusters = cluster_of!(user,organization)
|
94
|
+
cluster_ids = clusters.map(&:id).compact
|
95
|
+
end
|
96
|
+
|
97
|
+
scope_klass = scope_klass.select("DISTINCT ON (#{scope.table_name}.id) #{scope.table_name}.id, #{scope.table_name}.*")
|
98
|
+
|
99
|
+
if organization.required_suborganization_mode?
|
100
|
+
scope_klass = scope_klass.joins(:cluster_entities).where( cluster_entities: { cluster_id: cluster_ids } )
|
101
|
+
else
|
102
|
+
or_these_cluster_ids = cluster_ids.present? ? " OR cluster_entities.cluster_id IN (#{cluster_ids.join(",")})" : ""
|
103
|
+
scope_klass = scope_klass.joins("
|
104
|
+
LEFT OUTER JOIN cluster_entities
|
105
|
+
ON entity_id = #{scope.table_name}.id
|
106
|
+
AND entity_type = '#{scope}'
|
107
|
+
").where("cluster_entities.id IS NULL#{or_these_cluster_ids}")
|
115
108
|
end
|
109
|
+
|
110
|
+
# Provisional fix to avoid unresolved SQL clashes with the main application due to DISTINCT ON clause
|
111
|
+
scope_klass = scope_class(scope).eager_load(:cluster_entities).where(id: scope_klass.map(&:id), organization_id: organization)
|
116
112
|
end
|
117
113
|
scope_klass
|
118
114
|
end
|
@@ -129,67 +125,44 @@ module Klastera
|
|
129
125
|
end
|
130
126
|
|
131
127
|
##
|
132
|
-
# Returns a
|
133
|
-
#
|
128
|
+
# Returns a Cluster::ActiveRecord_Relation if the organization is using the cluster mode.
|
134
129
|
# Use this only to get current_user/organization clusters
|
135
|
-
# understanding this wont be useful out of a cluster mode context.
|
136
130
|
#
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
131
|
+
def cluster_of!(user,organization)
|
132
|
+
# A cluster user with role Root or Admin retrieve every cluster of its organizations
|
133
|
+
and_this_user = user.can_admin_clusters? ? nil : user
|
134
|
+
# We weill return a cluster active record collection that can be filtered
|
135
|
+
active_record_collection = ::ClusterUser.clusters_of(organization,and_this_user)
|
136
|
+
# Add a empty cluster instance to handle models without a cluster assignation.
|
137
|
+
if organization.optional_mode? # For use and show modes only
|
138
|
+
active_record_collection << ::Cluster.new({nid: UNCLUSTERED_ENTITY, name: I18n.t("klastera.#{UNCLUSTERED_ENTITY}")})
|
143
139
|
end
|
144
|
-
|
140
|
+
active_record_collection
|
145
141
|
end
|
146
|
-
end
|
147
142
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
hide_action :cluster_scope
|
161
|
-
hide_action :cluster_scope=
|
162
|
-
hide_action :user_cluster
|
163
|
-
hide_action :user_cluster=
|
164
|
-
hide_action :cluster_user
|
165
|
-
hide_action :cluster_user=
|
166
|
-
hide_action :cluster_organization
|
167
|
-
hide_action :cluster_organization=
|
168
|
-
hide_action :cluster_clusters
|
169
|
-
hide_action :cluster_clusters=
|
170
|
-
hide_action :cluster_scope_filtered
|
171
|
-
hide_action :cluster_scope_filtered=
|
172
|
-
hide_action :user_has_more_than_one_cluster
|
173
|
-
hide_action :user_has_more_than_one_cluster=
|
174
|
-
hide_action :clusters_from
|
175
|
-
hide_action :clusters_from=
|
143
|
+
##
|
144
|
+
# Return a string with cluster attribute separated by separator argument
|
145
|
+
# A array of cluster ids can be passed fo filter the result
|
146
|
+
#
|
147
|
+
def entity_clusters_string_list!(cluster_entities,separator,attribute=:name,allowed_cluster_ids=nil)
|
148
|
+
_cluster_entities = cluster_entities.reject(&:nil?)
|
149
|
+
if allowed_cluster_ids.is_a?(Array)
|
150
|
+
_cluster_entities.select!{|ce| allowed_cluster_ids.include?(ce.cluster_id)}
|
151
|
+
end
|
152
|
+
_cluster_entities.map do |ce|
|
153
|
+
ce.cluster.try(attribute)
|
154
|
+
end.compact.join(separator)
|
176
155
|
end
|
177
|
-
before_action :set_the_lonely_cluster, only: %i[ create update ]
|
178
|
-
end
|
179
156
|
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
157
|
+
##
|
158
|
+
# cluster_of! needs a user and a organization. that why we perfomed this logic here
|
159
|
+
#
|
160
|
+
def user_clusters_string_list!(user,organization,cluster_entities,separator,attribute=:name)
|
161
|
+
@clusters_session ||= self.cluster_of!(user,organization)
|
162
|
+
self.entity_clusters_string_list!(cluster_entities, separator, attribute, @clusters_session.map(&:id))
|
186
163
|
end
|
187
164
|
end
|
188
165
|
|
189
|
-
def cluster_scope(scope,includes=[])
|
190
|
-
Klastera.cluster_scope!(cluster_user,cluster_organization,scope,includes)
|
191
|
-
end
|
192
|
-
|
193
166
|
def cluster_user
|
194
167
|
current_user
|
195
168
|
end
|
@@ -198,27 +171,18 @@ module Klastera
|
|
198
171
|
current_organization
|
199
172
|
end
|
200
173
|
|
201
|
-
def cluster_clusters
|
202
|
-
Klastera.session_clusters(cluster_user,cluster_organization)
|
203
|
-
end
|
204
|
-
|
205
|
-
def cluster_scope_filtered(scope,cluster_id,includes=[])
|
206
|
-
Klastera.cluster_scope_filtered!(
|
207
|
-
scope,
|
208
|
-
cluster_id,
|
209
|
-
cluster_user,
|
210
|
-
cluster_organization,
|
211
|
-
includes
|
212
|
-
)
|
213
|
-
end
|
214
|
-
|
215
174
|
def user_has_more_than_one_cluster
|
216
|
-
@
|
217
|
-
@
|
175
|
+
@clusters_session ||= cluster_of_my_own
|
176
|
+
@clusters_session.size > 1
|
218
177
|
end
|
219
178
|
|
220
|
-
def
|
221
|
-
|
179
|
+
def set_the_lonely_cluster
|
180
|
+
form_model = @form_record ? model_name_from_record_or_class(@form_record).param_key : params[:controller].singularize
|
181
|
+
parameters = params.require( form_model ) rescue nil
|
182
|
+
lonely_cluster = parameters.blank? ? false : parameters.permit( :lonely_cluster ).present?
|
183
|
+
if lonely_cluster
|
184
|
+
params[form_model][:cluster_id] = cluster_of_my_own.first.try(:id)
|
185
|
+
end
|
222
186
|
end
|
223
187
|
|
224
188
|
def set_cluster_filter
|
@@ -234,4 +198,43 @@ module Klastera
|
|
234
198
|
def cluster_filter_permit_params
|
235
199
|
[ :cluster_id ].concat( ::ClusterFilter.attributes )
|
236
200
|
end
|
201
|
+
|
202
|
+
def filter_clusterized(active_record_collection,cluster_id)
|
203
|
+
Klastera.filter_clusterized!(active_record_collection, cluster_id, cluster_organization)
|
204
|
+
end
|
205
|
+
|
206
|
+
def cluster_scope(scope,cluster_id=nil)
|
207
|
+
Klastera.cluster_scope!(scope, cluster_user, cluster_organization, cluster_id)
|
208
|
+
end
|
209
|
+
|
210
|
+
def cluster_of_my_own
|
211
|
+
Klastera.cluster_of!(cluster_user, cluster_organization)
|
212
|
+
end
|
213
|
+
|
214
|
+
def user_clusters_string_list(object_entity,separator,attribute=:name)
|
215
|
+
Klastera.user_clusters_string_list!(
|
216
|
+
cluster_user,
|
217
|
+
cluster_organization,
|
218
|
+
object_entity.try(:cluster_entities),
|
219
|
+
separator,
|
220
|
+
attribute
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
def set_collection_before_group_by_entity(active_record_collection,entity_params,&block)
|
225
|
+
Klastera.set_collection_before_group_by_entity!(active_record_collection, params, cluster_organization, &block)
|
226
|
+
end
|
227
|
+
|
228
|
+
included do
|
229
|
+
Klastera::KLSTR_HELPERS.each do |action|
|
230
|
+
if respond_to?(:helper_method)
|
231
|
+
helper_method(action)
|
232
|
+
end
|
233
|
+
if respond_to?(:hide_action)
|
234
|
+
hide_action(helper)
|
235
|
+
hide_action("#{helper}=")
|
236
|
+
end
|
237
|
+
end
|
238
|
+
before_action :set_the_lonely_cluster, only: %i[ create update ]
|
239
|
+
end
|
237
240
|
end
|
data/lib/klastera/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Klastera
|
2
|
-
VERSION = "1.
|
3
|
-
end
|
2
|
+
VERSION = "1.3"
|
3
|
+
end
|
@@ -13,6 +13,11 @@ namespace :klastera do
|
|
13
13
|
klass = args.entity.constantize
|
14
14
|
ActiveRecord::Base.transaction do
|
15
15
|
klass.where.not(cluster_id: nil).each do |entity|
|
16
|
+
if entity.cluster.blank?
|
17
|
+
puts "Cluster ID #{entity.cluster_id} was not found!"
|
18
|
+
puts "skip..."
|
19
|
+
next
|
20
|
+
end
|
16
21
|
Klastera::ClusterEntity.create(entity: entity, cluster: entity.cluster)
|
17
22
|
end
|
18
23
|
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
|
+
version: '1.3'
|
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-06-
|
11
|
+
date: 2020-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -54,7 +54,6 @@ files:
|
|
54
54
|
- app/controllers/klastera/application_controller.rb
|
55
55
|
- app/controllers/klastera/clusters_controller.rb
|
56
56
|
- app/helpers/klastera/application_helper.rb
|
57
|
-
- app/helpers/klastera/clusters_helper.rb
|
58
57
|
- app/models/klastera/cluster.rb
|
59
58
|
- app/models/klastera/cluster_entity.rb
|
60
59
|
- app/models/klastera/cluster_filter.rb
|