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 | 2 | |
3 | 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 | 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 | 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 | 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 | 577 | |
572 | 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 | 580 | # FIXME: workaround for development env. |
599 | 581 | # Subclasses aren't (re)loaded, and acts_as_solr |
600 | 582 | # depends on subclasses method to search |
583 | + # see http://stackoverflow.com/questions/4138957/activerecordsubclassnotfound-error-when-using-sti-in-rails/4139245 | |
601 | 584 | UploadedFile |
602 | 585 | TextArticle |
603 | 586 | TinyMceArticle |
... | ... | @@ -609,20 +592,28 @@ class Article < ActiveRecord::Base |
609 | 592 | Forum |
610 | 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 | 602 | def f_type |
613 | - case self.class.to_s | |
603 | + #join common types | |
604 | + case self.class.name | |
614 | 605 | when 'TinyMceArticle', 'TextileArticle' |
615 | - 'TextArticle' | |
606 | + TextArticle.name | |
616 | 607 | else |
617 | - self.class.to_s | |
608 | + self.class.name | |
618 | 609 | end |
619 | 610 | end |
611 | + def f_profile_type | |
612 | + self.profile.class.name | |
613 | + end | |
620 | 614 | def f_published_at |
621 | 615 | self.published_at |
622 | 616 | end |
623 | - def f_profile_type | |
624 | - self.profile.class.to_s | |
625 | - end | |
626 | 617 | def f_category |
627 | 618 | self.categories.collect(&:name) |
628 | 619 | end | ... | ... |
app/models/blog.rb
app/models/community.rb
app/models/enterprise.rb
app/models/enterprise_homepage.rb
app/models/event.rb
app/models/folder.rb
app/models/forum.rb
app/models/gallery.rb
app/models/person.rb
app/models/profile.rb
... | ... | @@ -3,6 +3,12 @@ |
3 | 3 | # which by default is the one returned by Environment:default. |
4 | 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 | 12 | module Roles |
7 | 13 | def self.admin(env_id) |
8 | 14 | find_role('admin', env_id) |
... | ... | @@ -843,10 +849,8 @@ private :generate_url, :url_options |
843 | 849 | def f_type |
844 | 850 | self.class.name |
845 | 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 | 854 | end |
851 | 855 | def name_sort |
852 | 856 | name | ... | ... |
app/models/raw_html_article.rb
app/models/rss_feed.rb
app/models/text_article.rb
app/models/textile_article.rb
app/models/tiny_mce_article.rb
app/models/uploaded_file.rb
... | ... | @@ -4,6 +4,10 @@ |
4 | 4 | # of the file itself is kept. (FIXME?) |
5 | 5 | class UploadedFile < Article |
6 | 6 | |
7 | + def self.type_name | |
8 | + _('File') | |
9 | + end | |
10 | + | |
7 | 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 | 13 | include ShortFilename | ... | ... |