app/controllers/elt_controller.rb in parlement-0.12 vs app/controllers/elt_controller.rb in parlement-0.13
- old
+ new
@@ -12,10 +12,11 @@
def show
params[:id] = params[:id].gsub(/.html/, '')
@elt = Elt.find(params[:id])
@title = @elt.subject
@title += " (parlement)" if !@title.downcase.include? "parlement"
+
render :layout => 'top'
rescue ActiveRecord::RecordNotFound => e
flash[:error] = _("Element %s does not exist") % params[:id]
headers["Status"] = "301 Moved Permanently"
@@ -35,10 +36,72 @@
def listByVote
@elt = Elt.find params[:id] unless @elt
render :partial => 'listByVote'
end
+ def listVisitors
+ @elt = Elt.find params[:id] unless @elt
+ render :partial => 'listVisitors'
+ end
+
+ def listSubscribers
+ @elt = Elt.find params[:id] unless @elt
+ render :partial => '/subscriber/list'
+ end
+
+ def updateView
+ session[:lastUpdatedView] ||= Time.now - 10
+ acts = ""
+ visits = Visit.count \
+ :joins => "JOIN elts e1 ON e1.id = '#{params[:id]}' \
+ JOIN elts e2 ON visits.elt_id = e2.id \
+ AND ((e1.lft <= e2.lft AND e2.rgt <= e1.rgt) \
+ OR (e1.lft > e2.lft AND e2.rgt > e1.rgt))",
+ :conditions => "visits.updated_on >= '#{session[:lastUpdatedView]}'"
+ acts += "new Ajax.Updater('listVisitors', '/elt/listVisitors/#{params[:id]}', \
+ {asynchronous:true, evalScripts:true}); \
+ " if visits > 0
+
+ subscribers = Subscription.count \
+ :joins => "JOIN elts e1 ON e1.id = '#{params[:id]}' \
+ JOIN elts e2 ON subscriptions.elt_id = e2.id \
+ AND ((e1.lft <= e2.lft AND e2.rgt <= e1.rgt) \
+ OR (e1.lft > e2.lft AND e2.rgt > e1.rgt))",
+ :conditions => "subscriptions.created_on >= '#{session[:lastUpdatedView]}'"
+ acts += "new Ajax.Updater('listSubscribers', '/elt/listSubscribers/#{params[:id]}', \
+ {asynchronous:true, evalScripts:true}); \
+ " if subscribers > 0
+
+ elts = Elt.count \
+ :joins => "LEFT JOIN choices ON choices.elt_id = elts.id \
+ JOIN elts e2 ON elts.lft <= e2.lft AND e2.rgt <= elts.rgt",
+ :conditions => "elts.id = '#{params[:id]}' \
+ AND e2.created_on >= '#{session[:lastUpdatedView]}'"
+ acts += "new Ajax.Updater('listByDate', '/elt/listByDate/#{params[:id]}', \
+ {asynchronous:true, evalScripts:true});" \
+ + "new Ajax.Updater('listByVote', '/elt/listByVote/#{params[:id]}', \
+ {asynchronous:true, evalScripts:true}); \
+ " if subscribers > 0
+
+ if person = session[:person]
+ visit = Visit.find_by_person_id_and_elt_id(person, params[:id])
+ if visit and person.last_login and person.last_login > visit.created_on then
+ logger.info "New visit"
+ visit.destroy
+ visit = nil
+ end
+ visit = Visit.new(:person => person, :elt_id => params[:id]) unless visit
+ visit.filter = filter
+ visit.save!
+ end
+
+ logger.info "#{visits} visits, #{subscribers} subscribers, #{elts} elts"
+ session[:lastUpdatedView] = Time.now
+ render :inline => " \
+ <script type=\"text/javascript\">#{acts}</script>"
+ end
+
def rss
params[:id] = params[:id].gsub(/.rss/, '')
headers["Content-Type"] = "text/xml; charset=utf-8"
@elt = Elt.find(params[:id]) if @elt == nil
end
@@ -49,11 +112,10 @@
@elt = Elt.find(params[:id]) if @elt == nil
end
# Used to initialise the elt, its subject mainly
def new
- @elt = Elt.new
- @elt.parent = Elt.find(params[:id])
+ @elt = Elt.new(:parent_id => params[:id], :body => "")
if @elt.parent.subject.include? 'Re: '
@elt.subject = @elt.parent.subject
else
@elt.subject = 'Re: '+@elt.parent.subject