Commit 26332265f7b2e58aec32fe03dfb250dcadce3a4c
1 parent
48c5ed73
Exists in
master
and in
29 other branches
Remove solr and facets acts from profiles
Share code by placing them together into profile base class
Showing
4 changed files
with
56 additions
and
74 deletions
Show diff stats
app/models/community.rb
... | ... | @@ -79,25 +79,4 @@ class Community < Organization |
79 | 79 | {:title => __('Community Info and settings'), :icon => 'edit-profile-group'} |
80 | 80 | end |
81 | 81 | |
82 | - private | |
83 | - def f_territory | |
84 | - categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | |
85 | - end | |
86 | - def f_topic | |
87 | - categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | |
88 | - end | |
89 | - def f_network | |
90 | - categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | |
91 | - end | |
92 | - public | |
93 | - | |
94 | - acts_as_faceted :fields => { | |
95 | - :f_territory => {:label => _('Territories')}, | |
96 | - :f_topic => {:label => _('Thematics')}, | |
97 | - :f_network => {:label => _('Networks')}}, | |
98 | - :order => [:f_territory, :f_topic, :f_network] | |
99 | - | |
100 | - acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | |
101 | - :facets => facets.keys | |
102 | - | |
103 | 82 | end | ... | ... |
app/models/enterprise.rb
... | ... | @@ -162,28 +162,11 @@ class Enterprise < Organization |
162 | 162 | end |
163 | 163 | end |
164 | 164 | |
165 | - settings_items :enable_contact_us, :type => :boolean, :default => true | |
165 | + def control_panel_settings_button | |
166 | + {:title => __('Enterprise Info and settings'), :icon => 'edit-profile-enterprise'} | |
167 | + end | |
166 | 168 | |
167 | - private | |
168 | - def f_territory | |
169 | - categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | |
170 | - end | |
171 | - def f_topic | |
172 | - categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | |
173 | - end | |
174 | - def f_network | |
175 | - categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | |
176 | - end | |
177 | - public | |
178 | - | |
179 | - acts_as_faceted :fields => { | |
180 | - :f_territory => {:label => _('Territories')}, | |
181 | - :f_topic => {:label => _('Thematics')}, | |
182 | - :f_network => {:label => _('Networks')}}, | |
183 | - :order => [:f_territory, :f_topic, :f_network] | |
184 | - | |
185 | - acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | |
186 | - :facets => facets.keys | |
169 | + settings_items :enable_contact_us, :type => :boolean, :default => true | |
187 | 170 | |
188 | 171 | def enable_contact? |
189 | 172 | enable_contact_us | ... | ... |
app/models/person.rb
... | ... | @@ -414,27 +414,6 @@ class Person < Profile |
414 | 414 | user.save! |
415 | 415 | end |
416 | 416 | |
417 | - private | |
418 | - def f_territory | |
419 | - categories.find(:all, :conditions => {:parent_id => 5}).collect(&:name) | |
420 | - end | |
421 | - def f_topic | |
422 | - categories.find(:all, :conditions => {:parent_id => 1}).collect(&:name) | |
423 | - end | |
424 | - def f_network | |
425 | - categories.find(:all, :conditions => {:parent_id => 9}).collect(&:name) | |
426 | - end | |
427 | - public | |
428 | - | |
429 | - acts_as_faceted :fields => { | |
430 | - :f_territory => {:label => _('Territories')}, | |
431 | - :f_topic => {:label => _('Thematics')}, | |
432 | - :f_network => {:label => _('Networks')}}, | |
433 | - :order => [:f_territory, :f_topic, :f_network] | |
434 | - | |
435 | - acts_as_searchable :additional_fields => [ :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | |
436 | - :facets => facets.keys | |
437 | - | |
438 | 417 | protected |
439 | 418 | |
440 | 419 | def followed_by?(profile) | ... | ... |
app/models/profile.rb
... | ... | @@ -178,7 +178,7 @@ class Profile < ActiveRecord::Base |
178 | 178 | def top_level_categorization |
179 | 179 | ret = {} |
180 | 180 | self.profile_categorizations.each do |c| |
181 | - p = c.category.root_parent | |
181 | + p = c.category.top_ancestor | |
182 | 182 | ret[p] = (ret[p] || []) + [c.category] |
183 | 183 | end |
184 | 184 | ret |
... | ... | @@ -823,18 +823,59 @@ private :generate_url, :url_options |
823 | 823 | name |
824 | 824 | end |
825 | 825 | |
826 | - protected | |
826 | + private | |
827 | + def self.f_categories_label_proc(environment) | |
828 | + ids = environment.top_level_category_as_facet_ids | |
829 | + r = Category.find(ids) | |
830 | + map = {} | |
831 | + ids.map{ |id| map[id.to_s] = r.detect{|c| c.id == id}.name } | |
832 | + map | |
833 | + end | |
834 | + def self.f_categories_proc(facet, id) | |
835 | + id = id.to_i | |
836 | + c = Category.find(id) | |
837 | + c.name if c.top_ancestor.id == facet[:label_id].to_i or facet[:label_id] == 0 | |
838 | + end | |
839 | + def f_categories | |
840 | + category_ids | |
841 | + end | |
827 | 842 | |
828 | - def followed_by?(person) | |
829 | - person.is_member_of?(self) | |
830 | - end | |
843 | + def f_type | |
844 | + self.class.name | |
845 | + end | |
846 | + def self.f_type_proc(id) | |
847 | + {'Enterprise' => _('Enterprise'), | |
848 | + 'BscPlugin::Bsc' => _('BSC') | |
849 | + }[id] | |
850 | + end | |
851 | + public | |
831 | 852 | |
832 | - def display_private_info_to?(user) | |
833 | - if user.nil? | |
834 | - false | |
835 | - else | |
836 | - (user == self) || (user.is_admin?(self.environment)) || user.is_admin?(self) || user.memberships.include?(self) | |
837 | - end | |
853 | + acts_as_faceted :fields => { | |
854 | + :f_type => {:label => _('Type'), :type_if => proc { |klass| klass.kind_of?(Enterprise) }, :proc => proc { |id| f_type_proc(id) }}, | |
855 | + :f_categories => {:multi => true, :proc => proc {|facet, id| f_categories_proc(facet, id)}, | |
856 | + :label => proc { |env| f_categories_label_proc(env) }, :label_abbrev => proc { |env| f_categories_label_abbrev_proc(env) }}}, | |
857 | + :category_query => proc { |c| "f_categories:#{c.id}" }, | |
858 | + :order => [:f_type, :f_categories] | |
859 | + | |
860 | + acts_as_searchable :additional_fields => [ | |
861 | + :extra_data_for_index, {:name => {:type => :string, :as => :name_sort, :boost => 5.0}} ] + facets.keys.map{|i| {i => :facet}}, | |
862 | + :boost => proc {|p| 10 if p.enabled}, | |
863 | + :facets => facets.keys | |
864 | + | |
865 | + def control_panel_settings_button | |
866 | + {:title => _('Profile Info and settings'), :icon => 'edit-profile'} | |
867 | + end | |
868 | + | |
869 | + def followed_by?(person) | |
870 | + person.is_member_of?(self) | |
871 | + end | |
872 | + | |
873 | + def display_private_info_to?(user) | |
874 | + if user.nil? | |
875 | + false | |
876 | + else | |
877 | + (user == self) || (user.is_admin?(self.environment)) || user.is_admin?(self) || user.memberships.include?(self) | |
838 | 878 | end |
879 | + end | |
839 | 880 | |
840 | 881 | end | ... | ... |