Commit 2837298a1968f86bea0a139a4e7214d84b76765b
1 parent
cef870cc
Exists in
master
and in
29 other branches
Use type_name method for faceted search
Showing
17 changed files
with
90 additions
and
34 deletions
Show diff stats
app/models/article.rb
@@ -2,6 +2,12 @@ require 'hpricot' | @@ -2,6 +2,12 @@ require 'hpricot' | ||
2 | 2 | ||
3 | class Article < ActiveRecord::Base | 3 | class Article < ActiveRecord::Base |
4 | 4 | ||
5 | + # use for internationalizable human type names in search facets | ||
6 | + # reimplement on subclasses | ||
7 | + def self.type_name | ||
8 | + _('Content') | ||
9 | + end | ||
10 | + | ||
5 | track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target | 11 | track_actions :create_article, :after_create, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && !a.image? }, :custom_target => :action_tracker_target |
6 | track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && (a.body_changed? || a.name_changed?) }, :custom_target => :action_tracker_target | 12 | track_actions :update_article, :before_update, :keep_params => [:name, :url], :if => Proc.new { |a| a.is_trackable? && (a.body_changed? || a.name_changed?) }, :custom_target => :action_tracker_target |
7 | track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.is_trackable? }, :custom_target => :action_tracker_target | 13 | track_actions :remove_article, :before_destroy, :keep_params => [:name], :if => Proc.new { |a| a.is_trackable? }, :custom_target => :action_tracker_target |
@@ -571,33 +577,10 @@ class Article < ActiveRecord::Base | @@ -571,33 +577,10 @@ class Article < ActiveRecord::Base | ||
571 | 577 | ||
572 | private | 578 | private |
573 | 579 | ||
574 | - def self.f_type_proc(klass) | ||
575 | - klass.constantize | ||
576 | - h = { | ||
577 | - 'UploadedFile' => _("Uploaded File"), | ||
578 | - 'TextArticle' => _("Text"), | ||
579 | - 'Folder' => _("Folder"), | ||
580 | - 'Event' => _("Event"), | ||
581 | - 'EnterpriseHomepage' => ("Homepage"), | ||
582 | - 'Gallery' => ("Gallery"), | ||
583 | - 'Blog' => ("Blog"), | ||
584 | - 'Forum' => ("Forum") | ||
585 | - } | ||
586 | - h[klass] | ||
587 | - end | ||
588 | - def self.f_profile_type_proc(klass) | ||
589 | - h = { | ||
590 | - 'Enterprise' => _("Enterprise"), | ||
591 | - 'Community' => _("Community"), | ||
592 | - 'Person' => ("Person"), | ||
593 | - 'BscPlugin::Bsc' => ("BSC") | ||
594 | - } | ||
595 | - h[klass] | ||
596 | - end | ||
597 | - | ||
598 | # FIXME: workaround for development env. | 580 | # FIXME: workaround for development env. |
599 | # Subclasses aren't (re)loaded, and acts_as_solr | 581 | # Subclasses aren't (re)loaded, and acts_as_solr |
600 | # depends on subclasses method to search | 582 | # depends on subclasses method to search |
583 | + # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245 | ||
601 | UploadedFile | 584 | UploadedFile |
602 | TextArticle | 585 | TextArticle |
603 | TinyMceArticle | 586 | TinyMceArticle |
@@ -609,20 +592,28 @@ class Article < ActiveRecord::Base | @@ -609,20 +592,28 @@ class Article < ActiveRecord::Base | ||
609 | Forum | 592 | Forum |
610 | Event | 593 | Event |
611 | 594 | ||
595 | + def self.f_type_proc(klass) | ||
596 | + klass.constantize.type_name | ||
597 | + end | ||
598 | + def self.f_profile_type_proc(klass) | ||
599 | + klass.constantize.type_name | ||
600 | + end | ||
601 | + | ||
612 | def f_type | 602 | def f_type |
613 | - case self.class.to_s | 603 | + #join common types |
604 | + case self.class.name | ||
614 | when 'TinyMceArticle', 'TextileArticle' | 605 | when 'TinyMceArticle', 'TextileArticle' |
615 | - 'TextArticle' | 606 | + TextArticle.name |
616 | else | 607 | else |
617 | - self.class.to_s | 608 | + self.class.name |
618 | end | 609 | end |
619 | end | 610 | end |
611 | + def f_profile_type | ||
612 | + self.profile.class.name | ||
613 | + end | ||
620 | def f_published_at | 614 | def f_published_at |
621 | self.published_at | 615 | self.published_at |
622 | end | 616 | end |
623 | - def f_profile_type | ||
624 | - self.profile.class.to_s | ||
625 | - end | ||
626 | def f_category | 617 | def f_category |
627 | self.categories.collect(&:name) | 618 | self.categories.collect(&:name) |
628 | end | 619 | end |
app/models/blog.rb
@@ -9,6 +9,10 @@ class Blog < Folder | @@ -9,6 +9,10 @@ class Blog < Folder | ||
9 | end | 9 | end |
10 | alias_method_chain :posts, :no_folders | 10 | alias_method_chain :posts, :no_folders |
11 | 11 | ||
12 | + def self.type_name | ||
13 | + _('Blog') | ||
14 | + end | ||
15 | + | ||
12 | def self.short_description | 16 | def self.short_description |
13 | _('Blog') | 17 | _('Blog') |
14 | end | 18 | end |
app/models/community.rb
app/models/enterprise.rb
@@ -2,6 +2,10 @@ | @@ -2,6 +2,10 @@ | ||
2 | # only enterprises can offer products and services. | 2 | # only enterprises can offer products and services. |
3 | class Enterprise < Organization | 3 | class Enterprise < Organization |
4 | 4 | ||
5 | + def self.type_name | ||
6 | + _('Enterprise') | ||
7 | + end | ||
8 | + | ||
5 | N_('Enterprise') | 9 | N_('Enterprise') |
6 | 10 | ||
7 | has_many :products, :dependent => :destroy, :order => 'name ASC' | 11 | has_many :products, :dependent => :destroy, :order => 'name ASC' |
app/models/enterprise_homepage.rb
app/models/event.rb
app/models/folder.rb
app/models/forum.rb
@@ -2,6 +2,10 @@ class Forum < Folder | @@ -2,6 +2,10 @@ class Forum < Folder | ||
2 | 2 | ||
3 | acts_as_having_posts :order => 'updated_at DESC' | 3 | acts_as_having_posts :order => 'updated_at DESC' |
4 | 4 | ||
5 | + def self.type_name | ||
6 | + _('Forum') | ||
7 | + end | ||
8 | + | ||
5 | def self.short_description | 9 | def self.short_description |
6 | _('Forum') | 10 | _('Forum') |
7 | end | 11 | end |
app/models/gallery.rb
app/models/person.rb
1 | # A person is the profile of an user holding all relationships with the rest of the system | 1 | # A person is the profile of an user holding all relationships with the rest of the system |
2 | class Person < Profile | 2 | class Person < Profile |
3 | 3 | ||
4 | + def self.type_name | ||
5 | + _('Person') | ||
6 | + end | ||
7 | + | ||
4 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} | 8 | acts_as_trackable :after_add => Proc.new {|p,t| notify_activity(t)} |
5 | acts_as_accessor | 9 | acts_as_accessor |
6 | 10 |
app/models/profile.rb
@@ -3,6 +3,12 @@ | @@ -3,6 +3,12 @@ | ||
3 | # which by default is the one returned by Environment:default. | 3 | # which by default is the one returned by Environment:default. |
4 | class Profile < ActiveRecord::Base | 4 | class Profile < ActiveRecord::Base |
5 | 5 | ||
6 | + # use for internationalizable human type names in search facets | ||
7 | + # reimplement on subclasses | ||
8 | + def self.type_name | ||
9 | + _('Profile') | ||
10 | + end | ||
11 | + | ||
6 | module Roles | 12 | module Roles |
7 | def self.admin(env_id) | 13 | def self.admin(env_id) |
8 | find_role('admin', env_id) | 14 | find_role('admin', env_id) |
@@ -843,10 +849,8 @@ private :generate_url, :url_options | @@ -843,10 +849,8 @@ private :generate_url, :url_options | ||
843 | def f_type | 849 | def f_type |
844 | self.class.name | 850 | self.class.name |
845 | end | 851 | end |
846 | - def self.f_type_proc(id) | ||
847 | - {'Enterprise' => _('Enterprise'), | ||
848 | - 'BscPlugin::Bsc' => _('BSC') | ||
849 | - }[id] | 852 | + def self.f_type_proc(klass) |
853 | + klass.constantize.type_name | ||
850 | end | 854 | end |
851 | def name_sort | 855 | def name_sort |
852 | name | 856 | name |
app/models/raw_html_article.rb
app/models/rss_feed.rb
app/models/text_article.rb
@@ -3,6 +3,10 @@ class TextArticle < Article | @@ -3,6 +3,10 @@ class TextArticle < Article | ||
3 | 3 | ||
4 | xss_terminate :only => [ :name ], :on => 'validation' | 4 | xss_terminate :only => [ :name ], :on => 'validation' |
5 | 5 | ||
6 | + def self.type_name | ||
7 | + _('Article') | ||
8 | + end | ||
9 | + | ||
6 | include Noosfero::TranslatableContent | 10 | include Noosfero::TranslatableContent |
7 | 11 | ||
8 | def self.icon_name(article = nil) | 12 | def self.icon_name(article = nil) |
app/models/textile_article.rb
app/models/tiny_mce_article.rb
app/models/uploaded_file.rb
@@ -4,6 +4,10 @@ | @@ -4,6 +4,10 @@ | ||
4 | # of the file itself is kept. (FIXME?) | 4 | # of the file itself is kept. (FIXME?) |
5 | class UploadedFile < Article | 5 | class UploadedFile < Article |
6 | 6 | ||
7 | + def self.type_name | ||
8 | + _('File') | ||
9 | + end | ||
10 | + | ||
7 | track_actions :upload_image, :after_create, :keep_params => ["view_url", "thumbnail_path", "parent.url", "parent.name"], :if => Proc.new { |a| a.published? && a.image? && !a.parent.nil? && a.parent.gallery? } | 11 | track_actions :upload_image, :after_create, :keep_params => ["view_url", "thumbnail_path", "parent.url", "parent.name"], :if => Proc.new { |a| a.published? && a.image? && !a.parent.nil? && a.parent.gallery? } |
8 | 12 | ||
9 | include ShortFilename | 13 | include ShortFilename |