Commit 2f9962a53239a89e624582828c9c1961be7c5cbf
1 parent
bdd5ef3e
Exists in
master
and in
27 other branches
relevant_content: remove trailing spaces
Showing
5 changed files
with
130 additions
and
130 deletions
Show diff stats
plugins/relevant_content/lib/ext/article.rb
| 1 | require_dependency 'article' | 1 | require_dependency 'article' |
| 2 | 2 | ||
| 3 | class Article | 3 | class Article |
| 4 | - | 4 | + |
| 5 | named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] | 5 | named_scope :relevant_content, :conditions => ["(articles.type != 'UploadedFile' and articles.type != 'Blog' and articles.type != 'RssFeed') OR articles.type is NULL"] |
| 6 | 6 | ||
| 7 | def self.most_accessed(owner, limit = nil) | 7 | def self.most_accessed(owner, limit = nil) |
| 8 | - if owner.kind_of?(Environment) | 8 | + if owner.kind_of?(Environment) |
| 9 | result = Article.relevant_content.find( | 9 | result = Article.relevant_content.find( |
| 10 | :all, | 10 | :all, |
| 11 | :order => 'hits desc', | 11 | :order => 'hits desc', |
| 12 | :limit => limit, | 12 | :limit => limit, |
| 13 | - :conditions => ["hits > 0"] | 13 | + :conditions => ["hits > 0"] |
| 14 | ) | 14 | ) |
| 15 | result.paginate({:page => 1, :per_page => limit}) | 15 | result.paginate({:page => 1, :per_page => limit}) |
| 16 | else | 16 | else |
| 17 | #Owner is a profile | 17 | #Owner is a profile |
| 18 | result = Article.relevant_content.find( | 18 | result = Article.relevant_content.find( |
| 19 | - :all, | 19 | + :all, |
| 20 | :order => 'hits desc', | 20 | :order => 'hits desc', |
| 21 | :limit => limit, | 21 | :limit => limit, |
| 22 | - :conditions => ["profile_id = ? and hits > 0", owner.id] | 22 | + :conditions => ["profile_id = ? and hits > 0", owner.id] |
| 23 | ) | 23 | ) |
| 24 | result.paginate({:page => 1, :per_page => limit}) | 24 | result.paginate({:page => 1, :per_page => limit}) |
| 25 | - end | 25 | + end |
| 26 | end | 26 | end |
| 27 | 27 | ||
| 28 | def self.most_commented_relevant_content(owner, limit) | 28 | def self.most_commented_relevant_content(owner, limit) |
| 29 | - | ||
| 30 | - if owner.kind_of?(Environment) | 29 | + |
| 30 | + if owner.kind_of?(Environment) | ||
| 31 | result = Article.relevant_content.find( | 31 | result = Article.relevant_content.find( |
| 32 | :all, | 32 | :all, |
| 33 | :order => 'comments_count desc', | 33 | :order => 'comments_count desc', |
| 34 | :limit => limit, | 34 | :limit => limit, |
| 35 | - :conditions => ["comments_count > 0"] | 35 | + :conditions => ["comments_count > 0"] |
| 36 | ) | 36 | ) |
| 37 | result.paginate({:page => 1, :per_page => limit}) | 37 | result.paginate({:page => 1, :per_page => limit}) |
| 38 | else | 38 | else |
| 39 | #Owner is a profile | 39 | #Owner is a profile |
| 40 | result = Article.relevant_content.find( | 40 | result = Article.relevant_content.find( |
| 41 | - :all, | 41 | + :all, |
| 42 | :order => 'comments_count desc', | 42 | :order => 'comments_count desc', |
| 43 | :limit => limit, | 43 | :limit => limit, |
| 44 | - :conditions => ["profile_id = ? and comments_count > 0", owner.id] | 44 | + :conditions => ["profile_id = ? and comments_count > 0", owner.id] |
| 45 | ) | 45 | ) |
| 46 | result.paginate({:page => 1, :per_page => limit}) | 46 | result.paginate({:page => 1, :per_page => limit}) |
| 47 | - end | ||
| 48 | - end | ||
| 49 | - | 47 | + end |
| 48 | + end | ||
| 49 | + | ||
| 50 | def self.articles_columns | 50 | def self.articles_columns |
| 51 | Article.column_names.map {|c| "articles.#{c}"} .join(",") | 51 | Article.column_names.map {|c| "articles.#{c}"} .join(",") |
| 52 | end | 52 | end |
| 53 | - | 53 | + |
| 54 | def self.more_positive_votes(owner, limit = nil) | 54 | def self.more_positive_votes(owner, limit = nil) |
| 55 | - if owner.kind_of?(Environment) | 55 | + if owner.kind_of?(Environment) |
| 56 | result = Article.find( | 56 | result = Article.find( |
| 57 | :all, | 57 | :all, |
| 58 | - :select => articles_columns, | 58 | + :select => articles_columns, |
| 59 | :order => 'sum(vote) desc', | 59 | :order => 'sum(vote) desc', |
| 60 | :group => 'voteable_id, ' + articles_columns, | 60 | :group => 'voteable_id, ' + articles_columns, |
| 61 | :limit => limit, | 61 | :limit => limit, |
| 62 | - :having => ['sum(vote) > 0'], | ||
| 63 | - :conditions => {'votes.voteable_type' => 'Article'}, | 62 | + :having => ['sum(vote) > 0'], |
| 63 | + :conditions => {'votes.voteable_type' => 'Article'}, | ||
| 64 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' | 64 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' |
| 65 | - ) | 65 | + ) |
| 66 | result.paginate({:page => 1, :per_page => limit}) | 66 | result.paginate({:page => 1, :per_page => limit}) |
| 67 | else | 67 | else |
| 68 | #Owner is a profile | 68 | #Owner is a profile |
| 69 | result = Article.find( | 69 | result = Article.find( |
| 70 | :all, | 70 | :all, |
| 71 | - :select => articles_columns, | 71 | + :select => articles_columns, |
| 72 | :order => 'sum(vote) desc', | 72 | :order => 'sum(vote) desc', |
| 73 | :group => 'voteable_id, ' + articles_columns, | 73 | :group => 'voteable_id, ' + articles_columns, |
| 74 | :limit => limit, | 74 | :limit => limit, |
| 75 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 75 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 76 | - :having => ['sum(vote) > 0'], | ||
| 77 | - :conditions => ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article'] | 76 | + :having => ['sum(vote) > 0'], |
| 77 | + :conditions => ["profile_id = ? and votes.voteable_type = ? ", owner.id, 'Article'] | ||
| 78 | ) | 78 | ) |
| 79 | result.paginate({:page => 1, :per_page => limit}) | 79 | result.paginate({:page => 1, :per_page => limit}) |
| 80 | end | 80 | end |
| 81 | end | 81 | end |
| 82 | - | 82 | + |
| 83 | def self.more_negative_votes(owner, limit = nil) | 83 | def self.more_negative_votes(owner, limit = nil) |
| 84 | - if owner.kind_of?(Environment) | 84 | + if owner.kind_of?(Environment) |
| 85 | result = Article.find( | 85 | result = Article.find( |
| 86 | :all, | 86 | :all, |
| 87 | - :select => articles_columns, | 87 | + :select => articles_columns, |
| 88 | :order => 'sum(vote) asc', | 88 | :order => 'sum(vote) asc', |
| 89 | :group => 'voteable_id, ' + articles_columns, | 89 | :group => 'voteable_id, ' + articles_columns, |
| 90 | :limit => limit, | 90 | :limit => limit, |
| 91 | - :having => ['sum(vote) < 0'], | 91 | + :having => ['sum(vote) < 0'], |
| 92 | :conditions => {'votes.voteable_type' => 'Article'}, | 92 | :conditions => {'votes.voteable_type' => 'Article'}, |
| 93 | - :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' | 93 | + :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id' |
| 94 | ) | 94 | ) |
| 95 | result.paginate({:page => 1, :per_page => limit}) | 95 | result.paginate({:page => 1, :per_page => limit}) |
| 96 | else | 96 | else |
| 97 | #Owner is a profile | 97 | #Owner is a profile |
| 98 | result = Article.find( | 98 | result = Article.find( |
| 99 | :all, | 99 | :all, |
| 100 | - :select => articles_columns, | 100 | + :select => articles_columns, |
| 101 | :order => 'sum(vote) asc', | 101 | :order => 'sum(vote) asc', |
| 102 | :group => 'voteable_id, ' + articles_columns, | 102 | :group => 'voteable_id, ' + articles_columns, |
| 103 | :limit => limit, | 103 | :limit => limit, |
| 104 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 104 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 105 | - :having => ['sum(vote) < 0'], | ||
| 106 | - :conditions => ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id] | 105 | + :having => ['sum(vote) < 0'], |
| 106 | + :conditions => ["profile_id = ? and votes.voteable_type = 'Article' ", owner.id] | ||
| 107 | ) | 107 | ) |
| 108 | result.paginate({:page => 1, :per_page => limit}) | 108 | result.paginate({:page => 1, :per_page => limit}) |
| 109 | end | 109 | end |
| 110 | end | 110 | end |
| 111 | - | 111 | + |
| 112 | def self.most_liked(owner, limit = nil) | 112 | def self.most_liked(owner, limit = nil) |
| 113 | - if owner.kind_of?(Environment) | 113 | + if owner.kind_of?(Environment) |
| 114 | result = Article.find( | 114 | result = Article.find( |
| 115 | :all, | 115 | :all, |
| 116 | - :select => articles_columns, | 116 | + :select => articles_columns, |
| 117 | :order => 'count(voteable_id) desc', | 117 | :order => 'count(voteable_id) desc', |
| 118 | :group => 'voteable_id, ' + articles_columns, | 118 | :group => 'voteable_id, ' + articles_columns, |
| 119 | :limit => limit, | 119 | :limit => limit, |
| 120 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 120 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 121 | :conditions => ["votes.voteable_type = 'Article' and vote > 0"] | 121 | :conditions => ["votes.voteable_type = 'Article' and vote > 0"] |
| 122 | - ) | 122 | + ) |
| 123 | result.paginate({:page => 1, :per_page => limit}) | 123 | result.paginate({:page => 1, :per_page => limit}) |
| 124 | else | 124 | else |
| 125 | #Owner is a profile | 125 | #Owner is a profile |
| 126 | result = Article.find( | 126 | result = Article.find( |
| 127 | :all, | 127 | :all, |
| 128 | - :select => articles_columns, | 128 | + :select => articles_columns, |
| 129 | :order => 'count(voteable_id) desc', | 129 | :order => 'count(voteable_id) desc', |
| 130 | :group => 'voteable_id, ' + articles_columns, | 130 | :group => 'voteable_id, ' + articles_columns, |
| 131 | :limit => limit, | 131 | :limit => limit, |
| 132 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 132 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 133 | - :conditions => ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id] | 133 | + :conditions => ["votes.voteable_type = 'Article' and vote > 0 and profile_id = ? ", owner.id] |
| 134 | ) | 134 | ) |
| 135 | result.paginate({:page => 1, :per_page => limit}) | 135 | result.paginate({:page => 1, :per_page => limit}) |
| 136 | end | 136 | end |
| 137 | end | 137 | end |
| 138 | - | 138 | + |
| 139 | def self.most_disliked(owner, limit = nil) | 139 | def self.most_disliked(owner, limit = nil) |
| 140 | - if owner.kind_of?(Environment) | 140 | + if owner.kind_of?(Environment) |
| 141 | result = Article.find( | 141 | result = Article.find( |
| 142 | :all, | 142 | :all, |
| 143 | :order => 'count(voteable_id) desc', | 143 | :order => 'count(voteable_id) desc', |
| 144 | :group => 'voteable_id, ' + articles_columns, | 144 | :group => 'voteable_id, ' + articles_columns, |
| 145 | :limit => limit, | 145 | :limit => limit, |
| 146 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 146 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 147 | - :conditions => ["votes.voteable_type = 'Article' and vote < 0"] | 147 | + :conditions => ["votes.voteable_type = 'Article' and vote < 0"] |
| 148 | ) | 148 | ) |
| 149 | result.paginate({:page => 1, :per_page => limit}) | 149 | result.paginate({:page => 1, :per_page => limit}) |
| 150 | else | 150 | else |
| 151 | #Owner is a profile | 151 | #Owner is a profile |
| 152 | result = Article.find( | 152 | result = Article.find( |
| 153 | - :all, | 153 | + :all, |
| 154 | :order => 'count(voteable_id) desc', | 154 | :order => 'count(voteable_id) desc', |
| 155 | :group => 'voteable_id, ' + articles_columns, | 155 | :group => 'voteable_id, ' + articles_columns, |
| 156 | :limit => limit, | 156 | :limit => limit, |
| 157 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 157 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 158 | - :conditions => ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id] | 158 | + :conditions => ["votes.voteable_type = 'Article' and vote < 0 and profile_id = ? ", owner.id] |
| 159 | ) | 159 | ) |
| 160 | result.paginate({:page => 1, :per_page => limit}) | 160 | result.paginate({:page => 1, :per_page => limit}) |
| 161 | end | 161 | end |
| 162 | end | 162 | end |
| 163 | - | 163 | + |
| 164 | def self.most_voted(owner, limit = nil) | 164 | def self.most_voted(owner, limit = nil) |
| 165 | - if owner.kind_of?(Environment) | 165 | + if owner.kind_of?(Environment) |
| 166 | result = Article.find( | 166 | result = Article.find( |
| 167 | :all, | 167 | :all, |
| 168 | - :select => articles_columns, | 168 | + :select => articles_columns, |
| 169 | :order => 'count(voteable_id) desc', | 169 | :order => 'count(voteable_id) desc', |
| 170 | :group => 'voteable_id, ' + articles_columns, | 170 | :group => 'voteable_id, ' + articles_columns, |
| 171 | :limit => limit, | 171 | :limit => limit, |
| 172 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 172 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 173 | :conditions => ["votes.voteable_type = 'Article'"] | 173 | :conditions => ["votes.voteable_type = 'Article'"] |
| 174 | - ) | 174 | + ) |
| 175 | result.paginate({:page => 1, :per_page => limit}) | 175 | result.paginate({:page => 1, :per_page => limit}) |
| 176 | else | 176 | else |
| 177 | #Owner is a profile | 177 | #Owner is a profile |
| 178 | result = Article.find( | 178 | result = Article.find( |
| 179 | :all, | 179 | :all, |
| 180 | - :select => articles_columns, | 180 | + :select => articles_columns, |
| 181 | :order => 'count(voteable_id) desc', | 181 | :order => 'count(voteable_id) desc', |
| 182 | :group => 'voteable_id, ' + articles_columns, | 182 | :group => 'voteable_id, ' + articles_columns, |
| 183 | :limit => limit, | 183 | :limit => limit, |
| 184 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', | 184 | :joins => 'INNER JOIN votes ON articles.id = votes.voteable_id', |
| 185 | - :conditions => ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id] | 185 | + :conditions => ["votes.voteable_type = 'Article' and profile_id = ? ", owner.id] |
| 186 | ) | 186 | ) |
| 187 | result.paginate({:page => 1, :per_page => limit}) | 187 | result.paginate({:page => 1, :per_page => limit}) |
| 188 | end | 188 | end |
| 189 | end | 189 | end |
| 190 | - | ||
| 191 | - | ||
| 192 | - | ||
| 193 | - | ||
| 194 | -end | ||
| 195 | \ No newline at end of file | 190 | \ No newline at end of file |
| 191 | + | ||
| 192 | + | ||
| 193 | + | ||
| 194 | + | ||
| 195 | +end | ||
| 196 | \ No newline at end of file | 196 | \ No newline at end of file |
plugins/relevant_content/lib/relevant_content_plugin.rb
| 1 | class RelevantContentPlugin < Noosfero::Plugin | 1 | class RelevantContentPlugin < Noosfero::Plugin |
| 2 | - | 2 | + |
| 3 | def self.plugin_name | 3 | def self.plugin_name |
| 4 | "Relevant Content Plugin" | 4 | "Relevant Content Plugin" |
| 5 | end | 5 | end |
| @@ -16,6 +16,6 @@ class RelevantContentPlugin < Noosfero::Plugin | @@ -16,6 +16,6 @@ class RelevantContentPlugin < Noosfero::Plugin | ||
| 16 | 16 | ||
| 17 | def stylesheet? | 17 | def stylesheet? |
| 18 | true | 18 | true |
| 19 | - end | 19 | + end |
| 20 | 20 | ||
| 21 | end | 21 | end |
plugins/relevant_content/lib/relevant_content_plugin/relevant_content_block.rb
| @@ -12,80 +12,80 @@ class RelevantContentPlugin::RelevantContentBlock < Block | @@ -12,80 +12,80 @@ class RelevantContentPlugin::RelevantContentBlock < Block | ||
| 12 | end | 12 | end |
| 13 | 13 | ||
| 14 | settings_items :limit, :type => :integer, :default => 5 | 14 | settings_items :limit, :type => :integer, :default => 5 |
| 15 | - settings_items :show_most_read, :type => :integer, :default => 1 | ||
| 16 | - settings_items :show_most_commented, :type => :integer, :default => 1 | ||
| 17 | - settings_items :show_most_liked, :type => :integer, :default => 1 | ||
| 18 | - settings_items :show_most_disliked, :type => :integer, :default => 0 | ||
| 19 | - settings_items :show_most_voted, :type => :integer, :default => 1 | 15 | + settings_items :show_most_read, :type => :integer, :default => 1 |
| 16 | + settings_items :show_most_commented, :type => :integer, :default => 1 | ||
| 17 | + settings_items :show_most_liked, :type => :integer, :default => 1 | ||
| 18 | + settings_items :show_most_disliked, :type => :integer, :default => 0 | ||
| 19 | + settings_items :show_most_voted, :type => :integer, :default => 1 | ||
| 20 | 20 | ||
| 21 | include ActionController::UrlWriter | 21 | include ActionController::UrlWriter |
| 22 | def content(args={}) | 22 | def content(args={}) |
| 23 | 23 | ||
| 24 | - content = block_title(title) | ||
| 25 | - | 24 | + content = block_title(title) |
| 25 | + | ||
| 26 | if self.show_most_read != 0 | 26 | if self.show_most_read != 0 |
| 27 | - docs = Article.most_accessed(owner, self.limit) | ||
| 28 | - if !docs.blank? | 27 | + docs = Article.most_accessed(owner, self.limit) |
| 28 | + if !docs.blank? | ||
| 29 | subcontent = "" | 29 | subcontent = "" |
| 30 | - subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n" | ||
| 31 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 32 | - content += content_tag(:div, subcontent, :class=>"block mread") + "\n" | ||
| 33 | - end | 30 | + subcontent += content_tag(:span, _("Most read articles"), :class=>"title mread") + "\n" |
| 31 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 32 | + content += content_tag(:div, subcontent, :class=>"block mread") + "\n" | ||
| 33 | + end | ||
| 34 | end | 34 | end |
| 35 | 35 | ||
| 36 | if self.show_most_commented != 0 | 36 | if self.show_most_commented != 0 |
| 37 | docs = Article.most_commented_relevant_content(owner, self.limit) | 37 | docs = Article.most_commented_relevant_content(owner, self.limit) |
| 38 | - if !docs.blank? | ||
| 39 | - subcontent = "" | ||
| 40 | - subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n" | ||
| 41 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | 38 | + if !docs.blank? |
| 39 | + subcontent = "" | ||
| 40 | + subcontent += content_tag(:span, _("Most commented articles"), :class=>"title mcommented") + "\n" | ||
| 41 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 42 | content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n" | 42 | content += content_tag(:div, subcontent, :class=>"block mcommented") + "\n" |
| 43 | end | 43 | end |
| 44 | end | 44 | end |
| 45 | 45 | ||
| 46 | - if owner.kind_of?(Environment) | 46 | + if owner.kind_of?(Environment) |
| 47 | env = owner | 47 | env = owner |
| 48 | else | 48 | else |
| 49 | env = owner.environment | 49 | env = owner.environment |
| 50 | end | 50 | end |
| 51 | - | 51 | + |
| 52 | if env.plugin_enabled?(VotePlugin) | 52 | if env.plugin_enabled?(VotePlugin) |
| 53 | if self.show_most_liked != 0 | 53 | if self.show_most_liked != 0 |
| 54 | docs = Article.more_positive_votes(owner, self.limit) | 54 | docs = Article.more_positive_votes(owner, self.limit) |
| 55 | - if !docs.blank? | ||
| 56 | - subcontent = "" | ||
| 57 | - subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n" | ||
| 58 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | 55 | + if !docs.blank? |
| 56 | + subcontent = "" | ||
| 57 | + subcontent += content_tag(:span, _("Most liked articles"), :class=>"title mliked") + "\n" | ||
| 58 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 59 | content += content_tag(:div, subcontent, :class=>"block mliked") + "\n" | 59 | content += content_tag(:div, subcontent, :class=>"block mliked") + "\n" |
| 60 | end | 60 | end |
| 61 | end | 61 | end |
| 62 | if self.show_most_disliked != 0 | 62 | if self.show_most_disliked != 0 |
| 63 | docs = Article.more_negative_votes(owner, self.limit) | 63 | docs = Article.more_negative_votes(owner, self.limit) |
| 64 | - if !docs.blank? | ||
| 65 | - subcontent = "" | ||
| 66 | - subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n" | ||
| 67 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 68 | - content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n" | 64 | + if !docs.blank? |
| 65 | + subcontent = "" | ||
| 66 | + subcontent += content_tag(:span, _("Most disliked articles"), :class=>"title mdisliked") + "\n" | ||
| 67 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 68 | + content += content_tag(:div, subcontent, :class=>"block mdisliked") + "\n" | ||
| 69 | end | 69 | end |
| 70 | end | 70 | end |
| 71 | - | 71 | + |
| 72 | if self.show_most_voted != 0 | 72 | if self.show_most_voted != 0 |
| 73 | docs = Article.most_voted(owner, self.limit) | 73 | docs = Article.most_voted(owner, self.limit) |
| 74 | - if !docs.blank? | 74 | + if !docs.blank? |
| 75 | subcontent = "" | 75 | subcontent = "" |
| 76 | - subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n" | ||
| 77 | - subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 78 | - content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n" | 76 | + subcontent += content_tag(:span, _("Most voted articles"), :class=>"title mvoted") + "\n" |
| 77 | + subcontent += content_tag(:ul, docs.map {|item| content_tag('li', link_to(h(item.title), item.url))}.join("\n")) | ||
| 78 | + content += content_tag(:div, subcontent, :class=>"block mvoted") + "\n" | ||
| 79 | end | 79 | end |
| 80 | - end | 80 | + end |
| 81 | end | 81 | end |
| 82 | return content | 82 | return content |
| 83 | - end | ||
| 84 | - | 83 | + end |
| 84 | + | ||
| 85 | def timeout | 85 | def timeout |
| 86 | 4.hours | 86 | 4.hours |
| 87 | - end | ||
| 88 | - | 87 | + end |
| 88 | + | ||
| 89 | def self.expire_on | 89 | def self.expire_on |
| 90 | { :profile => [:article], :environment => [:article] } | 90 | { :profile => [:article], :environment => [:article] } |
| 91 | end | 91 | end |
plugins/relevant_content/test/unit/relevant_content_block_test.rb
| @@ -5,10 +5,10 @@ require 'comment_controller' | @@ -5,10 +5,10 @@ require 'comment_controller' | ||
| 5 | class CommentController; def rescue_action(e) raise e end; end | 5 | class CommentController; def rescue_action(e) raise e end; end |
| 6 | 6 | ||
| 7 | class RelevantContentBlockTest < ActiveSupport::TestCase | 7 | class RelevantContentBlockTest < ActiveSupport::TestCase |
| 8 | - | 8 | + |
| 9 | include AuthenticatedTestHelper | 9 | include AuthenticatedTestHelper |
| 10 | fixtures :users, :environments | 10 | fixtures :users, :environments |
| 11 | - | 11 | + |
| 12 | def setup | 12 | def setup |
| 13 | @controller = CommentController.new | 13 | @controller = CommentController.new |
| 14 | @request = ActionController::TestRequest.new | 14 | @request = ActionController::TestRequest.new |
| @@ -18,15 +18,15 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -18,15 +18,15 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 18 | @environment = @profile.environment | 18 | @environment = @profile.environment |
| 19 | end | 19 | end |
| 20 | attr_reader :profile, :environment | 20 | attr_reader :profile, :environment |
| 21 | - | ||
| 22 | - | ||
| 23 | - | 21 | + |
| 22 | + | ||
| 23 | + | ||
| 24 | should 'have a default title' do | 24 | should 'have a default title' do |
| 25 | relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new | 25 | relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new |
| 26 | block = Block.new | 26 | block = Block.new |
| 27 | assert_not_equal block.default_title, relevant_content_block.default_title | 27 | assert_not_equal block.default_title, relevant_content_block.default_title |
| 28 | end | 28 | end |
| 29 | - | 29 | + |
| 30 | should 'have a help tooltip' do | 30 | should 'have a help tooltip' do |
| 31 | relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new | 31 | relevant_content_block = RelevantContentPlugin::RelevantContentBlock.new |
| 32 | block = Block.new | 32 | block = Block.new |
| @@ -36,7 +36,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -36,7 +36,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 36 | should 'describe itself' do | 36 | should 'describe itself' do |
| 37 | assert_not_equal Block.description, RelevantContentPlugin::RelevantContentBlock.description | 37 | assert_not_equal Block.description, RelevantContentPlugin::RelevantContentBlock.description |
| 38 | end | 38 | end |
| 39 | - | 39 | + |
| 40 | should 'is editable' do | 40 | should 'is editable' do |
| 41 | block = RelevantContentPlugin::RelevantContentBlock.new | 41 | block = RelevantContentPlugin::RelevantContentBlock.new |
| 42 | assert block.editable? | 42 | assert block.editable? |
| @@ -51,19 +51,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -51,19 +51,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 51 | Article.most_accessed(Environment.default, 5) | 51 | Article.most_accessed(Environment.default, 5) |
| 52 | } | 52 | } |
| 53 | end | 53 | end |
| 54 | - | 54 | + |
| 55 | should 'not raise an exception when finding the most commented content' do | 55 | should 'not raise an exception when finding the most commented content' do |
| 56 | assert_nothing_raised{ | 56 | assert_nothing_raised{ |
| 57 | Article.most_commented_relevant_content(Environment.default, 5) | 57 | Article.most_commented_relevant_content(Environment.default, 5) |
| 58 | } | 58 | } |
| 59 | end | 59 | end |
| 60 | - | 60 | + |
| 61 | should 'not raise an exception when finding the most liked content' do | 61 | should 'not raise an exception when finding the most liked content' do |
| 62 | - begin | 62 | + begin |
| 63 | Environment.default.enable_plugin(:vote) | 63 | Environment.default.enable_plugin(:vote) |
| 64 | rescue | 64 | rescue |
| 65 | - puts "Unable to activate vote plugin" | ||
| 66 | - end | 65 | + puts "Unable to activate vote plugin" |
| 66 | + end | ||
| 67 | if Environment.default.plugin_enabled?(:vote) | 67 | if Environment.default.plugin_enabled?(:vote) |
| 68 | assert_nothing_raised{ | 68 | assert_nothing_raised{ |
| 69 | Article.most_liked(Environment.default, 5) | 69 | Article.most_liked(Environment.default, 5) |
| @@ -72,11 +72,11 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -72,11 +72,11 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 72 | end | 72 | end |
| 73 | 73 | ||
| 74 | should 'not raise an exception when finding the most disliked content' do | 74 | should 'not raise an exception when finding the most disliked content' do |
| 75 | - begin | 75 | + begin |
| 76 | Environment.default.enable_plugin(:vote) | 76 | Environment.default.enable_plugin(:vote) |
| 77 | rescue | 77 | rescue |
| 78 | puts "Unable to activate vote plugin" | 78 | puts "Unable to activate vote plugin" |
| 79 | - end | 79 | + end |
| 80 | if Environment.default.plugin_enabled?(:vote) | 80 | if Environment.default.plugin_enabled?(:vote) |
| 81 | assert_nothing_raised{ | 81 | assert_nothing_raised{ |
| 82 | Article.most_disliked(Environment.default, 5) | 82 | Article.most_disliked(Environment.default, 5) |
| @@ -84,13 +84,13 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -84,13 +84,13 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 84 | end | 84 | end |
| 85 | end | 85 | end |
| 86 | 86 | ||
| 87 | - | 87 | + |
| 88 | should 'not raise an exception when finding the more positive votes' do | 88 | should 'not raise an exception when finding the more positive votes' do |
| 89 | - begin | 89 | + begin |
| 90 | Environment.default.enable_plugin(:vote) | 90 | Environment.default.enable_plugin(:vote) |
| 91 | rescue | 91 | rescue |
| 92 | - puts "Unable to activate vote plugin" | ||
| 93 | - end | 92 | + puts "Unable to activate vote plugin" |
| 93 | + end | ||
| 94 | if Environment.default.plugin_enabled?(:vote) | 94 | if Environment.default.plugin_enabled?(:vote) |
| 95 | assert_nothing_raised{ | 95 | assert_nothing_raised{ |
| 96 | Article.more_positive_votes(Environment.default, 5) | 96 | Article.more_positive_votes(Environment.default, 5) |
| @@ -99,18 +99,18 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -99,18 +99,18 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 99 | end | 99 | end |
| 100 | 100 | ||
| 101 | should 'not raise an exception when finding the most voted' do | 101 | should 'not raise an exception when finding the most voted' do |
| 102 | - begin | 102 | + begin |
| 103 | Environment.default.enable_plugin(:vote) | 103 | Environment.default.enable_plugin(:vote) |
| 104 | rescue | 104 | rescue |
| 105 | puts "Unable to activate vote plugin" | 105 | puts "Unable to activate vote plugin" |
| 106 | - end | 106 | + end |
| 107 | if Environment.default.plugin_enabled?(:vote) | 107 | if Environment.default.plugin_enabled?(:vote) |
| 108 | assert_nothing_raised{ | 108 | assert_nothing_raised{ |
| 109 | Article.most_voted(Environment.default, 5) | 109 | Article.most_voted(Environment.default, 5) |
| 110 | } | 110 | } |
| 111 | end | 111 | end |
| 112 | end | 112 | end |
| 113 | - | 113 | + |
| 114 | should 'find the most voted' do | 114 | should 'find the most voted' do |
| 115 | 115 | ||
| 116 | article = fast_create(Article, {:name=>'2 votes'}) | 116 | article = fast_create(Article, {:name=>'2 votes'}) |
| @@ -118,19 +118,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -118,19 +118,19 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 118 | person = fast_create(Person) | 118 | person = fast_create(Person) |
| 119 | person.vote_for(article) | 119 | person.vote_for(article) |
| 120 | end | 120 | end |
| 121 | - | 121 | + |
| 122 | article = fast_create(Article, {:name=>'10 votes'}) | 122 | article = fast_create(Article, {:name=>'10 votes'}) |
| 123 | for i in 0..10 | 123 | for i in 0..10 |
| 124 | person = fast_create(Person) | 124 | person = fast_create(Person) |
| 125 | person.vote_for(article) | 125 | person.vote_for(article) |
| 126 | end | 126 | end |
| 127 | - | 127 | + |
| 128 | article = fast_create(Article, {:name=>'5 votes'}) | 128 | article = fast_create(Article, {:name=>'5 votes'}) |
| 129 | for i in 0..5 | 129 | for i in 0..5 |
| 130 | person = fast_create(Person) | 130 | person = fast_create(Person) |
| 131 | person.vote_for(article) | 131 | person.vote_for(article) |
| 132 | end | 132 | end |
| 133 | - | 133 | + |
| 134 | articles = Article.most_voted(Environment.default, 5) | 134 | articles = Article.most_voted(Environment.default, 5) |
| 135 | assert_equal '10 votes', articles.first.name | 135 | assert_equal '10 votes', articles.first.name |
| 136 | assert_equal '2 votes', articles.last.name | 136 | assert_equal '2 votes', articles.last.name |
| @@ -147,7 +147,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -147,7 +147,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 147 | person = fast_create(Person) | 147 | person = fast_create(Person) |
| 148 | person.vote_for(article) | 148 | person.vote_for(article) |
| 149 | end | 149 | end |
| 150 | - | 150 | + |
| 151 | article = fast_create(Article, {:name=>'10 votes for 5 votes against'}) | 151 | article = fast_create(Article, {:name=>'10 votes for 5 votes against'}) |
| 152 | for i in 0..10 | 152 | for i in 0..10 |
| 153 | person = fast_create(Person) | 153 | person = fast_create(Person) |
| @@ -157,7 +157,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -157,7 +157,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 157 | person = fast_create(Person) | 157 | person = fast_create(Person) |
| 158 | person.vote_against(article) | 158 | person.vote_against(article) |
| 159 | end | 159 | end |
| 160 | - | 160 | + |
| 161 | article = fast_create(Article, {:name=>'2 votes against'}) | 161 | article = fast_create(Article, {:name=>'2 votes against'}) |
| 162 | for i in 0..2 | 162 | for i in 0..2 |
| 163 | person = fast_create(Person) | 163 | person = fast_create(Person) |
| @@ -169,12 +169,12 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -169,12 +169,12 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 169 | person = fast_create(Person) | 169 | person = fast_create(Person) |
| 170 | person.vote_for(article) | 170 | person.vote_for(article) |
| 171 | end | 171 | end |
| 172 | - | 172 | + |
| 173 | articles = Article.more_positive_votes(Environment.default, 5) | 173 | articles = Article.more_positive_votes(Environment.default, 5) |
| 174 | assert_equal '7 votes for', articles.first.name | 174 | assert_equal '7 votes for', articles.first.name |
| 175 | assert_equal '23 votes for 20 votes against', articles.last.name | 175 | assert_equal '23 votes for 20 votes against', articles.last.name |
| 176 | end | 176 | end |
| 177 | - | 177 | + |
| 178 | should 'list the most negative' do | 178 | should 'list the most negative' do |
| 179 | 179 | ||
| 180 | article = fast_create(Article, {:name=>'23 votes for 29 votes against'}) | 180 | article = fast_create(Article, {:name=>'23 votes for 29 votes against'}) |
| @@ -186,7 +186,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -186,7 +186,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 186 | person = fast_create(Person) | 186 | person = fast_create(Person) |
| 187 | person.vote_for(article) | 187 | person.vote_for(article) |
| 188 | end | 188 | end |
| 189 | - | 189 | + |
| 190 | article = fast_create(Article, {:name=>'10 votes for 15 votes against'}) | 190 | article = fast_create(Article, {:name=>'10 votes for 15 votes against'}) |
| 191 | for i in 0..10 | 191 | for i in 0..10 |
| 192 | person = fast_create(Person) | 192 | person = fast_create(Person) |
| @@ -196,7 +196,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -196,7 +196,7 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 196 | person = fast_create(Person) | 196 | person = fast_create(Person) |
| 197 | person.vote_against(article) | 197 | person.vote_against(article) |
| 198 | end | 198 | end |
| 199 | - | 199 | + |
| 200 | article = fast_create(Article, {:name=>'2 votes against'}) | 200 | article = fast_create(Article, {:name=>'2 votes against'}) |
| 201 | for i in 0..2 | 201 | for i in 0..2 |
| 202 | person = fast_create(Person) | 202 | person = fast_create(Person) |
| @@ -208,10 +208,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | @@ -208,10 +208,10 @@ class RelevantContentBlockTest < ActiveSupport::TestCase | ||
| 208 | person = fast_create(Person) | 208 | person = fast_create(Person) |
| 209 | person.vote_for(article) | 209 | person.vote_for(article) |
| 210 | end | 210 | end |
| 211 | - | 211 | + |
| 212 | articles = Article.more_negative_votes(Environment.default, 5) | 212 | articles = Article.more_negative_votes(Environment.default, 5) |
| 213 | assert_equal '23 votes for 29 votes against', articles.first.name | 213 | assert_equal '23 votes for 29 votes against', articles.first.name |
| 214 | assert_equal '2 votes against', articles.last.name | 214 | assert_equal '2 votes against', articles.last.name |
| 215 | end | 215 | end |
| 216 | - | 216 | + |
| 217 | end | 217 | end |
plugins/relevant_content/views/box_organizer/relevant_content_plugin/_relevant_content_block.rhtml
| 1 | <div id='edit-relevant-content-block'> | 1 | <div id='edit-relevant-content-block'> |
| 2 | - <%= labelled_form_field _('Limit of items per category'), text_field(:block, :limit, :size => 3) %> | 2 | + <%= labelled_form_field _('Limit of items per category'), text_field(:block, :limit, :size => 3) %> |
| 3 | <%= labelled_check_box _('Display most accessed content'), "block[show_most_read]", 1 ,@block.show_most_read != 0 %><BR> | 3 | <%= labelled_check_box _('Display most accessed content'), "block[show_most_read]", 1 ,@block.show_most_read != 0 %><BR> |
| 4 | <%= labelled_check_box _('Display most commented content'), "block[show_most_commented]", 1 ,@block.show_most_commented != 0 %><BR> | 4 | <%= labelled_check_box _('Display most commented content'), "block[show_most_commented]", 1 ,@block.show_most_commented != 0 %><BR> |
| 5 | - <%= labelled_check_box _('Display most liked content'), "block[show_most_liked]", 1 ,@block.show_most_liked != 0 %><BR> | ||
| 6 | - <%= labelled_check_box _('Display most voted content'), "block[show_most_voted]", 1 ,@block.show_most_voted != 0 %><BR> | ||
| 7 | - <%= labelled_check_box _('Display most disliked content'), "block[show_most_disliked]", 1 , @block.show_most_disliked != 0 %><BR> | 5 | + <%= labelled_check_box _('Display most liked content'), "block[show_most_liked]", 1 ,@block.show_most_liked != 0 %><BR> |
| 6 | + <%= labelled_check_box _('Display most voted content'), "block[show_most_voted]", 1 ,@block.show_most_voted != 0 %><BR> | ||
| 7 | + <%= labelled_check_box _('Display most disliked content'), "block[show_most_disliked]", 1 , @block.show_most_disliked != 0 %><BR> | ||
| 8 | </div> | 8 | </div> |
| 9 | 9 | ||
| 10 | 10 | ||
| 11 | - | 11 | + |
| 12 | 12 |