Commit 5bba97c1f649c49e8800878c2c4c10b739fb8d8b

Authored by Francisco Marcelo de Araújo Lima Júnior
1 parent 7c4fa34c
Exists in master

#community_dashboard - fixes

controllers/public/community_hub_plugin_public_controller.rb
@@ -50,14 +50,12 @@ class CommunityHubPluginPublicController < PublicController @@ -50,14 +50,12 @@ class CommunityHubPluginPublicController < PublicController
50 mediation_data = {} 50 mediation_data = {}
51 mediation_data.merge!(params[:article]) if params[:article] 51 mediation_data.merge!(params[:article]) if params[:article]
52 52
53 - mediation = TinyMceArticle.new(mediation_data) 53 + mediation = CommunityHubPlugin::Mediation.new(mediation_data)
  54 + mediation.name = CommunityHubPlugin::Mediation.timestamp
54 mediation.profile = profile 55 mediation.profile = profile
55 mediation.last_changed_by = user 56 mediation.last_changed_by = user
56 - mediation.name = mediation_timestamp  
57 - mediation.notify_comments = false  
58 - mediation.type = 'TinyMceArticle'  
59 - mediation.advertise = false  
60 mediation.created_by_id = user.id 57 mediation.created_by_id = user.id
  58 + mediation.source = 'local'
61 59
62 if mediation && mediation.save 60 if mediation && mediation.save
63 render :text => {'ok' => true}.to_json, :content_type => 'application/json' 61 render :text => {'ok' => true}.to_json, :content_type => 'application/json'
@@ -113,7 +111,7 @@ class CommunityHubPluginPublicController < PublicController @@ -113,7 +111,7 @@ class CommunityHubPluginPublicController < PublicController
113 def newer_articles 111 def newer_articles
114 latest_post = params[:latest_post] 112 latest_post = params[:latest_post]
115 hub = Article.find(params[:hub]) 113 hub = Article.find(params[:hub])
116 - posts = Article.find(:all, :order => "id desc", :conditions => ["id > :id and type = :type and parent_id = :hub", { :id => latest_post, :type => 'TinyMceArticle', :hub => hub.id }]) 114 + posts = CommunityHubPlugin::Mediation.find(:all, :order => "id desc", :conditions => ["id > :id and parent_id = :hub", { :id => latest_post, :hub => hub.id }])
117 115
118 if !posts.empty? 116 if !posts.empty?
119 oldest_post = posts.last.id 117 oldest_post = posts.last.id
@@ -158,11 +156,13 @@ class CommunityHubPluginPublicController < PublicController @@ -158,11 +156,13 @@ class CommunityHubPluginPublicController < PublicController
158 def pin_message 156 def pin_message
159 if logged_in? 157 if logged_in?
160 if (!params[:hub].blank? && !params[:message].blank?) 158 if (!params[:hub].blank? && !params[:message].blank?)
  159 +
161 begin 160 begin
162 hub = Article.find(params[:hub]) 161 hub = Article.find(params[:hub])
163 rescue 162 rescue
164 hub = nil 163 hub = nil
165 end 164 end
  165 +
166 if hub && hub.mediator?(user) 166 if hub && hub.mediator?(user)
167 begin 167 begin
168 message = Comment.find(params[:message]) 168 message = Comment.find(params[:message])
@@ -171,42 +171,37 @@ class CommunityHubPluginPublicController < PublicController @@ -171,42 +171,37 @@ class CommunityHubPluginPublicController < PublicController
171 end 171 end
172 172
173 if message 173 if message
174 - mediation = TinyMceArticle.new  
175 - mediation.profile = hub.profile  
176 - mediation.parent = hub  
177 -  
178 author = message.author.blank? ? user : message.author 174 author = message.author.blank? ? user : message.author
179 175
  176 + mediation = CommunityHubPlugin::Mediation.new
  177 + mediation.name = CommunityHubPlugin::Mediation.timestamp
  178 +
  179 + mediation.profile = hub.profile
180 mediation.last_changed_by = author 180 mediation.last_changed_by = author
181 mediation.created_by_id = author.id 181 mediation.created_by_id = author.id
182 -  
183 - mediation.name = mediation_timestamp  
184 mediation.body = message.body 182 mediation.body = message.body
185 - mediation.notify_comments = false  
186 - mediation.type = 'TinyMceArticle'  
187 - mediation.advertise = false 183 + mediation.parent_id = hub.id
188 mediation.source = 'local' 184 mediation.source = 'local'
189 185
190 - if mediation.save 186 + if mediation && mediation.save
191 187
192 if ( message.title == 'hub-message-twitter' ) 188 if ( message.title == 'hub-message-twitter' )
193 mediation.source = 'twitter' 189 mediation.source = 'twitter'
194 mediation.author_name = message.name 190 mediation.author_name = message.name
195 - mediation.external_link = message.profile_picture  
196 - elsif ( message.title == 'hub-message-facebook' )  
197 - mediation.source = 'facebook'  
198 - mediation.author_name = message.name 191 + mediation.profile_picture = message.profile_picture
  192 + mediation.save
199 end 193 end
200 194
201 - mediation.save  
202 -  
203 hub.pinned_messages += [message.id] unless hub.pinned_messages.include?(message.id) 195 hub.pinned_messages += [message.id] unless hub.pinned_messages.include?(message.id)
204 hub.pinned_mediations += [mediation.id] unless hub.pinned_mediations.include?(mediation.id) 196 hub.pinned_mediations += [mediation.id] unless hub.pinned_mediations.include?(mediation.id)
205 - if hub.save 197 +
  198 + if hub && hub.save
206 render :text => {'ok' => true}.to_json, :content_type => 'application/json' 199 render :text => {'ok' => true}.to_json, :content_type => 'application/json'
207 return true 200 return true
208 end 201 end
  202 +
209 end 203 end
  204 +
210 end 205 end
211 end 206 end
212 end 207 end
@@ -217,11 +212,6 @@ class CommunityHubPluginPublicController < PublicController @@ -217,11 +212,6 @@ class CommunityHubPluginPublicController < PublicController
217 212
218 protected 213 protected
219 214
220 - def mediation_timestamp  
221 - "hub-mediation-#{(Time.now.to_f * 1000).to_i}"  
222 - end  
223 -  
224 -  
225 def message_timestamp 215 def message_timestamp
226 "hub-message-#{(Time.now.to_f * 1000).to_i}" 216 "hub-message-#{(Time.now.to_f * 1000).to_i}"
227 end 217 end
lib/community_hub_plugin/mediation.rb 0 → 100644
@@ -0,0 +1,15 @@ @@ -0,0 +1,15 @@
  1 +class CommunityHubPlugin::Mediation < Article
  2 +
  3 + before_save do |mediation|
  4 + mediation.advertise = false
  5 + mediation.notify_comments = false
  6 + nil
  7 + end
  8 +
  9 + settings_items :profile_picture, :type => :string, :default => ""
  10 +
  11 + def self.timestamp
  12 + "hub-mediation-#{(Time.now.to_f * 1000).to_i}"
  13 + end
  14 +
  15 +end
views/community_hub_plugin_public/_mediation.rhtml
@@ -7,7 +7,7 @@ @@ -7,7 +7,7 @@
7 7
8 <li class="avatar"> 8 <li class="avatar">
9 <% if mediation.source == 'twitter' %> 9 <% if mediation.source == 'twitter' %>
10 - <%= image_tag(mediation.external_link, :alt => "Twitter") %> 10 + <%= image_tag(mediation.profile_picture, :alt => "Twitter") %>
11 <% elsif mediation.source == 'facebook' %> 11 <% elsif mediation.source == 'facebook' %>
12 <%= image_tag('/plugins/community_hub/icons/logo_facebook_50x50.png', :alt => "Facebook") %> 12 <%= image_tag('/plugins/community_hub/icons/logo_facebook_50x50.png', :alt => "Facebook") %>
13 <% else %> 13 <% else %>
views/community_hub_plugin_public/_post.rhtml
@@ -14,7 +14,7 @@ @@ -14,7 +14,7 @@
14 </li> 14 </li>
15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li> 15 <li class="message"><span class="author"><%= post.author_name %>:</span> <%= post.body %></li>
16 16
17 - <% if mediator?(hub) %> 17 + <% if mediator?(hub) && post.title != 'hub-message-facebook' %>
18 <li class="mediation-bar"> 18 <li class="mediation-bar">
19 <ul> 19 <ul>
20 <li class="pin"> 20 <li class="pin">