parlement 0.12 → 0.13

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,5 +1,21 @@
1
1
  - parlement changelog
2
2
 
3
+ == Version 0.13 ==
4
+
5
+ Better filtering. Periodical updating of visitors, subscribers and elements
6
+ lists.
7
+
8
+ * do not filter out the top element
9
+ * filtered elements are now only displayed as simple clickable >
10
+ * correction, no more showing the subscriptionLink even when it is not already
11
+ present
12
+ * lists didn't refer to the proper div id, resulting in the creation of
13
+ infinitely nested div over time
14
+ * possibility to preview then modify, in two distinct steps
15
+ * visits, subscribers and elements lists updated every 10s
16
+ * lists only display elements whose rating is above the filter
17
+ * new feed icon, placed alongside the associated box title
18
+
3
19
  == Version 0.12
4
20
 
5
21
  Internationalization
data/MEMORY CHANGED
@@ -1,3 +1,7 @@
1
+ TODO
2
+ * factorise paginations
3
+ * new and preview using tabs
4
+
1
5
  What is below is just for future personal reference...
2
6
 
3
7
  http://www.ajaxchat.org/chat/
data/README CHANGED
@@ -14,6 +14,7 @@ On debian, here are the commands used to setup a parlement server:
14
14
  # apt-get install libpgsql-ruby
15
15
  # apt-get install irb
16
16
  # apt-get install rdoc
17
+ # apt-get install rake
17
18
 
18
19
  Basically this install postgresql, ruby and the ruby driver to psql. Ruby on
19
20
  Rails is database agnostic, parlement will be sometimes in the future.
@@ -100,6 +100,9 @@ class AccountController < UserController
100
100
  if session[:person]
101
101
  cookies[:person_name] = { :value => session[:person].name, :expires => 3.years.from_now }
102
102
  cookies[:salted_password] = { :value => @user.salted_password, :expires => 3.years.from_now } if @user
103
+
104
+ @person.last_login = Time.now
105
+ @person.save
103
106
  end
104
107
 
105
108
  # To make sure the logout knows which elt's choices to update
@@ -5,6 +5,8 @@ require 'login_engine'
5
5
  require 'term/ansicolor'
6
6
 
7
7
  class ApplicationController < ActionController::Base
8
+ helper_method :filter
9
+
8
10
  include LoginEngine
9
11
  include Term::ANSIColor
10
12
 
@@ -32,8 +34,21 @@ class ApplicationController < ActionController::Base
32
34
  logger.info yellow { bold { "#{person.name} is back" } }
33
35
  session[:person] = person
34
36
  session[:user] = person.user
37
+
38
+ person.last_login = Time.now
39
+ person.save
35
40
  end
36
41
  end
37
42
  end
43
+
44
+ def filter
45
+ if request.cookies['filter'] && request.cookies['filter'][0]
46
+ filter = request.cookies['filter'][0].to_i - 1
47
+ filter = nil unless filter >= 0
48
+ else
49
+ filter = 0
50
+ end
51
+ filter
52
+ end
38
53
  end
39
54
 
@@ -14,6 +14,7 @@ class EltController < ApplicationController
14
14
  @elt = Elt.find(params[:id])
15
15
  @title = @elt.subject
16
16
  @title += " (parlement)" if !@title.downcase.include? "parlement"
17
+
17
18
  render :layout => 'top'
18
19
 
19
20
  rescue ActiveRecord::RecordNotFound => e
@@ -37,6 +38,68 @@ class EltController < ApplicationController
37
38
  render :partial => 'listByVote'
38
39
  end
39
40
 
41
+ def listVisitors
42
+ @elt = Elt.find params[:id] unless @elt
43
+ render :partial => 'listVisitors'
44
+ end
45
+
46
+ def listSubscribers
47
+ @elt = Elt.find params[:id] unless @elt
48
+ render :partial => '/subscriber/list'
49
+ end
50
+
51
+ def updateView
52
+ session[:lastUpdatedView] ||= Time.now - 10
53
+ acts = ""
54
+ visits = Visit.count \
55
+ :joins => "JOIN elts e1 ON e1.id = '#{params[:id]}' \
56
+ JOIN elts e2 ON visits.elt_id = e2.id \
57
+ AND ((e1.lft <= e2.lft AND e2.rgt <= e1.rgt) \
58
+ OR (e1.lft > e2.lft AND e2.rgt > e1.rgt))",
59
+ :conditions => "visits.updated_on >= '#{session[:lastUpdatedView]}'"
60
+ acts += "new Ajax.Updater('listVisitors', '/elt/listVisitors/#{params[:id]}', \
61
+ {asynchronous:true, evalScripts:true}); \
62
+ " if visits > 0
63
+
64
+ subscribers = Subscription.count \
65
+ :joins => "JOIN elts e1 ON e1.id = '#{params[:id]}' \
66
+ JOIN elts e2 ON subscriptions.elt_id = e2.id \
67
+ AND ((e1.lft <= e2.lft AND e2.rgt <= e1.rgt) \
68
+ OR (e1.lft > e2.lft AND e2.rgt > e1.rgt))",
69
+ :conditions => "subscriptions.created_on >= '#{session[:lastUpdatedView]}'"
70
+ acts += "new Ajax.Updater('listSubscribers', '/elt/listSubscribers/#{params[:id]}', \
71
+ {asynchronous:true, evalScripts:true}); \
72
+ " if subscribers > 0
73
+
74
+ elts = Elt.count \
75
+ :joins => "LEFT JOIN choices ON choices.elt_id = elts.id \
76
+ JOIN elts e2 ON elts.lft <= e2.lft AND e2.rgt <= elts.rgt",
77
+ :conditions => "elts.id = '#{params[:id]}' \
78
+ AND e2.created_on >= '#{session[:lastUpdatedView]}'"
79
+ acts += "new Ajax.Updater('listByDate', '/elt/listByDate/#{params[:id]}', \
80
+ {asynchronous:true, evalScripts:true});" \
81
+ + "new Ajax.Updater('listByVote', '/elt/listByVote/#{params[:id]}', \
82
+ {asynchronous:true, evalScripts:true}); \
83
+ " if subscribers > 0
84
+
85
+ if person = session[:person]
86
+ visit = Visit.find_by_person_id_and_elt_id(person, params[:id])
87
+ if visit and person.last_login and person.last_login > visit.created_on then
88
+ logger.info "New visit"
89
+ visit.destroy
90
+ visit = nil
91
+ end
92
+ visit = Visit.new(:person => person, :elt_id => params[:id]) unless visit
93
+ visit.filter = filter
94
+ visit.save!
95
+ end
96
+
97
+ logger.info "#{visits} visits, #{subscribers} subscribers, #{elts} elts"
98
+ session[:lastUpdatedView] = Time.now
99
+ render :inline => " \
100
+ <script type=\"text/javascript\">#{acts}</script>"
101
+ end
102
+
40
103
  def rss
41
104
  params[:id] = params[:id].gsub(/.rss/, '')
42
105
  headers["Content-Type"] = "text/xml; charset=utf-8"
@@ -51,8 +114,7 @@ class EltController < ApplicationController
51
114
 
52
115
  # Used to initialise the elt, its subject mainly
53
116
  def new
54
- @elt = Elt.new
55
- @elt.parent = Elt.find(params[:id])
117
+ @elt = Elt.new(:parent_id => params[:id], :body => "")
56
118
 
57
119
  if @elt.parent.subject.include? 'Re: '
58
120
  @elt.subject = @elt.parent.subject
@@ -17,12 +17,6 @@ class SubscriberController < ApplicationController
17
17
  Subscription.find_by_person_id_and_elt_id(session[:person].id, elt2.id).destroy
18
18
  logger.info yellow { "User #{session[:person].name} unsubscribed from #{elt2.subject}..." }
19
19
  else
20
- if cookies[:filter]
21
- filter = cookies[:filter].to_i - 1
22
- filter = nil unless filter >= 0
23
- else
24
- filter = 0
25
- end
26
20
  @elt.subscriptions.create :person => session[:person], :filter => filter
27
21
  logger.info yellow { "User #{session[:person].name} subscribed to #{@elt.id} with filter #{filter}..." }
28
22
  end
@@ -1,8 +1,33 @@
1
1
  module EltHelper
2
+ def countEltsAboveFilter
3
+ Elt.count_by_sql "\
4
+ SELECT COUNT(*) \
5
+ FROM (SELECT elts.id FROM elts \
6
+ LEFT JOIN choices ON choices.elt_id = elts.id \
7
+ WHERE lft > #{@elt.lft} AND rgt < #{@elt.rgt} \
8
+ GROUP BY elts.id \
9
+ HAVING SUM(value) >= #{filter||-10**10}) AS notUsed"
10
+ end
11
+
12
+ #
13
+ # Should we display an element's title
14
+ #
15
+ # The algo used is simple, display a title if it is not a simple reply to its
16
+ # parent
17
+ #
18
+ def displayTitle? elt
19
+ #elt.id and elt.subject.reverse.index(elt.parent.subject.reverse) != 0
20
+ elt.id and elt.parent and elt.subject and !elt.subject.empty? \
21
+ and elt.subject != elt.parent.subject \
22
+ and elt.parent.subject \
23
+ and elt.subject.downcase != elt.parent.subject.downcase \
24
+ and not elt.subject.sub(/(Re|RE|r�f|re|sv|aw):\s*/, '') == elt.parent.subject
25
+ end
26
+
2
27
  def format(data)
3
28
  # for italics /.../ to _..._ \
4
- #.gsub(/(\s+)\/([\w\s�������]*)\//, '\\1_\\2_') \
5
-
29
+ # .gsub(/(\s+)\/([\w\s�������]*)\//, '\\1_\\2_') \
30
+ #
6
31
  # On Date Time someone wrote: blockquote
7
32
  # Yahoo footer
8
33
  # Google footer
@@ -24,7 +49,7 @@ module EltHelper
24
49
  .gsub(/^\s\*(.*)\*/, '*\\1*') \
25
50
  .gsub(/^\b(.{2,50})$(\n)\b/, '\\1<br/>\\2') \
26
51
  .gsub(/\n*^\b(position\s*:\s*(\d*(\.\d+)?))\s*$\n*/, ' <span class="position">\1</span>') \
27
- if data != nil
52
+ if data != nil
28
53
 
29
54
  # Only show the n first paragraphs
30
55
  text.gsub!(/((?:(\n)(?:^.+$\n)*){#{NB_PARAGRAPH_TO_DISPLAY}})((?:.|\n)*)/,
@@ -55,20 +80,5 @@ module EltHelper
55
80
 
56
81
  textiled
57
82
  end
58
-
59
- #
60
- # Should we display an element's title
61
- #
62
- # The algo used is simple, display a title if it is not a simple reply to its
63
- # parent
64
- #
65
- def displayTitle? elt
66
- #elt.id and elt.subject.reverse.index(elt.parent.subject.reverse) != 0
67
- elt.id and elt.parent and elt.subject and !elt.subject.empty? \
68
- and elt.subject != elt.parent.subject \
69
- and elt.parent.subject \
70
- and elt.subject.downcase != elt.parent.subject.downcase \
71
- and not elt.subject.sub(/(Re|RE|r�f|re|sv|aw):\s*/, '') == elt.parent.subject
72
- end
73
83
  end
74
84
 
data/app/models/elt.rb CHANGED
@@ -25,6 +25,11 @@ class Elt < ActiveRecord::Base
25
25
  has_many :subscriptions, :dependent => :destroy
26
26
  has_many :subscribers, :through => :subscriptions, :source => :person
27
27
 
28
+ has_many :visits, :dependent => :destroy
29
+ has_many :visitors, :through => :visits, :source => :person
30
+ has_many :old_visits, :dependent => :destroy
31
+ has_many :old_visitors, :through => :old_visits, :source => :person
32
+
28
33
  acts_as_nested_set :order => "position is not null, position, last_activity DESC, created_on DESC"
29
34
  acts_as_tree :order => "position is not null, position, last_activity DESC, created_on DESC", :counter_cache => true
30
35
 
@@ -39,9 +44,9 @@ class Elt < ActiveRecord::Base
39
44
 
40
45
  def all_subscriptions
41
46
  if parent
42
- (subscriptions + parent.all_subscriptions).uniq
47
+ (subscriptions + parent.all_subscriptions).uniq
43
48
  else
44
- subscriptions
49
+ subscriptions
45
50
  end
46
51
  end
47
52
 
@@ -73,7 +78,7 @@ class Elt < ActiveRecord::Base
73
78
 
74
79
  parent.vote Regexp.last_match(1), person if body =~ /^\s*(-1|0|\+1)(\s|$)/
75
80
  if Regexp.last_match(1) and self.body.gsub(/(-1|0|\+1)/, '').strip.empty?
76
- # Hide simple votes
81
+ # Hide simple votes
77
82
  vote -1
78
83
  else
79
84
  vote if person
@@ -0,0 +1,4 @@
1
+ class OldVisit < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :elt
4
+ end
data/app/models/person.rb CHANGED
@@ -7,6 +7,10 @@ class Person < ActiveRecord::Base
7
7
  has_many :subscribed_elts, :through => :subscriptions, :source => :elt
8
8
  has_many :person_mails, :dependent => :destroy
9
9
  has_many :mails, :through => :person_mails, :source => :mail
10
+ has_many :visits, :dependent => :destroy
11
+ has_many :visited, :through => :visits, :source => :elt
12
+ has_many :old_visits, :dependent => :destroy
13
+ has_many :old_visited, :through => :old_visits, :source => :elt
10
14
 
11
15
  validates_presence_of :name, :on => :create
12
16
  validates_length_of :name, :within => 3..80, :on => :create
@@ -0,0 +1,4 @@
1
+ class Visit < ActiveRecord::Base
2
+ belongs_to :person
3
+ belongs_to :elt
4
+ end
@@ -1,3 +1,5 @@
1
+ <h3 class="boxTitle"><%= _('Identity')%></h3>
2
+
1
3
  <% flash.each do |key, value| %>
2
4
  <div class="<%= key %>"><%= value %></div>
3
5
  <% end %>
@@ -19,12 +21,18 @@
19
21
  <% end %>
20
22
 
21
23
  <% if @person = session[:person] %>
22
- <script language="JavaScript">Element.show($('subscriptionLink'));</script>
24
+ <script language="JavaScript">
25
+ if ($('subscriptionLink')) {
26
+ Element.show($('subscriptionLink'));
27
+ }
28
+ </script>
23
29
  <span class="logout">
24
30
  <%= link_to_remote('[X]',
25
31
  { :update => 'identity',
26
32
  :url => { :controller => 'account', :action => 'logout', :elt => @elt },
27
- :before => visual_effect(:BlindUp, 'identity', { :queue => 'login' })+visual_effect(:BlindUp, 'subscriptionLink', { :queue => 'login' })+";resetChoices();",
33
+ :before => visual_effect(:BlindUp, 'identity', { :queue => 'login' }) \
34
+ +visual_effect(:BlindUp, 'subscriptionLink', { :queue => 'login' }) \
35
+ +"resetChoices();",
28
36
  :loaded => visual_effect(:BlindDown, 'identity', { :queue => 'login' }) },
29
37
  { :href => url_for(:controller => 'account', :action => 'logout') }) %>
30
38
  </span>
@@ -41,7 +49,7 @@
41
49
  </div>
42
50
 
43
51
  <fieldset id="edit">
44
- <legend><%= _('Edit') %></legend>
52
+ <legend><%= _('Edit') %></legend>
45
53
  <% form_remote_tag(
46
54
  :update => 'identity',
47
55
  :url => { :controller => 'account', :action => 'setPassword' },
@@ -1,60 +1,76 @@
1
+ <%= link_to image_tag("/images/feed-icon-28x28.png"),
2
+ { :action => 'rss', :id => @elt }, :class => 'feed' %>
3
+ <h3 class="boxTitle"><%= _('Latest posts') %></h3>
4
+
1
5
  <%e_pages = ActionController::Pagination::Paginator.new(
2
- self, (@elt.rgt-@elt.lft-1)/2, LIST_LENGTH, params['page'])
3
- elts = Elt.find :all,
4
- :conditions => "lft > #{@elt.lft} AND rgt < #{@elt.rgt}",
5
- :order => 'elts.created_on DESC',
6
- :include => :person,
7
- :limit => e_pages.items_per_page,
8
- :offset => e_pages.current.offset %>
9
-
10
- <div id="listByDate">
11
- <% if e_pages.length > 1 %>
12
- <%= link_to_remote('|&lt;',
13
- { :update => 'listByDate',
14
- :url => { :action => 'listByDate', :id => @elt, :page => e_pages.last },
15
- :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
16
- :loading => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
17
- if e_pages.last != e_pages.current %>
18
- <%= link_to_remote('&lt;',
19
- { :update => 'listByDate',
20
- :url => { :action => 'listByDate', :id => @elt, :page => e_pages.current.next },
21
- :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
22
- :loading => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
23
- if e_pages.current.next and e_pages.current.next != e_pages.last %>
24
-
25
- <span class="pageCount"><%= e_pages.length-e_pages.current.to_i+1 %></span>
26
-
27
- <%= link_to_remote('&gt;',
28
- { :update => 'listByDate',
29
- :url => { :action => 'listByDate', :id => @elt, :page => e_pages.current.previous },
30
- :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
31
- :loading => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
32
- if e_pages.current.previous and e_pages.current.previous != e_pages.first %>
33
- <%= link_to_remote('&gt;|',
34
- { :update => 'listByDate',
35
- :url => { :action => 'listByDate', :id => @elt, :page => e_pages.first },
36
- :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
37
- :loading => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
38
- if e_pages.first != e_pages.current %>
39
- <% end %>
40
-
41
- <ul>
42
- <% elts.each do |elt| %>
43
- <li class="boxLine elt" title="<%= elt.created_on.strftime '%d/%m %H:%M' %>">
44
- <span class="created_on"><%= elt.created_on.strftime '%d/%m %H:%M' %></span>
45
- <% if elt.person %>
46
- <span class="author">
47
- &lt;<%= link_to elt.person.name, :controller => 'person', :action => 'show', :id => elt.person %>&gt;
48
- </span>
49
- <% elsif not displayTitle? elt %>
50
- <span class="author">&lt;<%= ANONYMOUS_POSTER %>&gt;</span>
51
- <% end %>
52
-
53
- <%= link_to elt.subject.gsub(/\[.*\]/, ''), :action => 'show', :id => elt %>
54
- </li>
55
- <% end %>
56
- </ul>
57
-
58
- <%= link_to image_tag("/images/webfeed.gif"), :action => 'rss', :id => @elt %>
59
- </div>
6
+ self, countEltsAboveFilter, LIST_LENGTH, params['page'])
7
+ elts = Elt.find_by_sql " \
8
+ SELECT SUM(value) AS resultLocal, elts.id, parent_id, elts.created_on, parent_id, \
9
+ elts_count, position, elts.person_id, subject, body, lft, rgt \
10
+ FROM elts \
11
+ LEFT JOIN choices ON choices.elt_id = elts.id \
12
+ WHERE lft > #{@elt.lft} AND rgt < #{@elt.rgt} \
13
+ GROUP BY elts.id, parent_id, elts.created_on, parent_id, elts_count, \
14
+ position, elts.person_id, subject, body, lft, rgt \
15
+ HAVING SUM(value) >= #{filter||-10**10} \
16
+ ORDER BY created_on DESC \
17
+ LIMIT #{e_pages.items_per_page} \
18
+ OFFSET #{e_pages.current.offset}" %>
19
+
20
+ <% if e_pages.length > 1 %>
21
+ <%= link_to_remote('|&lt;',
22
+ { :update => 'listByDate',
23
+ :url => { :action => 'listByDate', :id => @elt, :page => e_pages.last },
24
+ :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
25
+ :loaded => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
26
+ if e_pages.last != e_pages.current %>
27
+ <%= link_to_remote('&lt;',
28
+ { :update => 'listByDate',
29
+ :url => { :action => 'listByDate', :id => @elt, :page => e_pages.current.next },
30
+ :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
31
+ :loaded => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
32
+ if e_pages.current.next and e_pages.current.next != e_pages.last %>
33
+
34
+ <span class="pageCount"><%= e_pages.length-e_pages.current.to_i+1 %></span>
35
+
36
+ <%= link_to_remote('&gt;',
37
+ { :update => 'listByDate',
38
+ :url => { :action => 'listByDate', :id => @elt, :page => e_pages.current.previous },
39
+ :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
40
+ :loaded => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
41
+ if e_pages.current.previous and e_pages.current.previous != e_pages.first %>
42
+ <%= link_to_remote('&gt;|',
43
+ { :update => 'listByDate',
44
+ :url => { :action => 'listByDate', :id => @elt, :page => e_pages.first },
45
+ :before => visual_effect(:BlindUp, 'listByDate', { :queue => 'end' }),
46
+ :loaded => visual_effect(:BlindDown, 'listByDate', { :queue => 'end' }) }) \
47
+ if e_pages.first != e_pages.current %>
48
+ <% end %>
49
+
50
+ <ul>
51
+ <% elts.each do |elt| %>
52
+ <li class="boxLine elt" title="<%= elt.created_on.strftime '%d/%m %H:%M' %>">
53
+ <span class="created_on"><%= elt.created_on.strftime '%d/%m %H:%M' %></span>
54
+ <span>
55
+ <%= link_to_remote("%+d" % elt.resultlocal,
56
+ { :update => 'resultList_'+elt.id,
57
+ :position => :top,
58
+ :url => { :action => 'choices', :id => elt } },
59
+ { :class => 'result', :id => "resultList_#{ elt.id}",
60
+ :href => url_for(:controller => 'elt', :action => 'choices', :id => elt) }
61
+ ) if elt.resultlocal %>
62
+ </span>
63
+
64
+ <% if elt.person %>
65
+ <span class="author">
66
+ &lt;<%= link_to elt.person.name, :controller => 'person', :action => 'show', :id => elt.person %>&gt;
67
+ </span>
68
+ <% elsif not displayTitle? elt %>
69
+ <span class="author">&lt;<%= ANONYMOUS_POSTER %>&gt;</span>
70
+ <% end %>
71
+
72
+ <%= link_to elt.subject.gsub(/\[.*\]/, ''), :action => 'show', :id => elt %>
73
+ </li>
74
+ <% end %>
75
+ </ul>
60
76
 
@@ -1,73 +1,78 @@
1
- <%e_pages = ActionController::Pagination::Paginator.new(
2
- self, (@elt.rgt-@elt.lft-1)/2, LIST_LENGTH, params['page'])
3
- elts = Elt.find :all,
4
- :select => 'SUM(value) AS resultLocal, elts.id, parent_id, elts.created_on, parent_id,' \
5
- +'elts_count, position, elts.person_id, subject, body, lft, rgt',
6
- :conditions => "lft > #{@elt.lft} AND rgt < #{@elt.rgt}",
7
- :order => 'SUM(value) IS NULL, SUM(value) DESC, created_on DESC',
8
- :group => 'elts.id, parent_id, elts.created_on, parent_id, elts_count,' \
9
- +'position, elts.person_id, subject, body, lft, rgt',
10
- :limit => e_pages.items_per_page,
11
- :offset => e_pages.current.offset,
12
- :joins => "LEFT JOIN choices ON choices.elt_id = elts.id" %>
1
+ <%= link_to image_tag("/images/feed-icon-28x28.png"),
2
+ { :action => 'vote_rss', :id => @elt }, :class => 'feed' %>
3
+ <h3 class="boxTitle">
4
+ <%= _('Highest posts') %>
5
+ </h3>
13
6
 
14
- <div id="listByVote">
15
- <% if e_pages.length > 1 %>
16
- <%= link_to_remote('|&lt;',
17
- { :update => 'listByVote',
18
- :url => { :action => 'listByVote', :id => @elt, :page => e_pages.last },
19
- :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
20
- :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
21
- if e_pages.last != e_pages.current %>
22
- <%= link_to_remote('&lt;',
23
- { :update => 'listByVote',
24
- :url => { :action => 'listByVote', :id => @elt, :page => e_pages.current.next },
25
- :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
26
- :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
27
- if e_pages.current.next and e_pages.current.next != e_pages.last %>
7
+ <%e_pages = ActionController::Pagination::Paginator.new(
8
+ self, countEltsAboveFilter, LIST_LENGTH, params['page'])
9
+ elts = Elt.find_by_sql " \
10
+ SELECT SUM(value) AS resultLocal, elts.id, parent_id, elts.created_on, parent_id, \
11
+ elts_count, position, elts.person_id, subject, body, lft, rgt \
12
+ FROM elts \
13
+ LEFT JOIN choices ON choices.elt_id = elts.id \
14
+ WHERE lft > #{@elt.lft} AND rgt < #{@elt.rgt} \
15
+ GROUP BY elts.id, parent_id, elts.created_on, parent_id, elts_count, \
16
+ position, elts.person_id, subject, body, lft, rgt \
17
+ HAVING SUM(value) >= #{filter||-10**10} \
18
+ ORDER BY SUM(value) IS NULL, SUM(value) DESC, created_on DESC \
19
+ LIMIT #{e_pages.items_per_page} \
20
+ OFFSET #{e_pages.current.offset}" %>
28
21
 
29
- <span class="pageCount"><%= e_pages.length-e_pages.current.to_i+1 %></span>
22
+ <% if e_pages.length > 1 %>
23
+ <%= link_to_remote('|&lt;',
24
+ { :update => 'listByVote',
25
+ :url => { :action => 'listByVote', :id => @elt, :page => e_pages.last },
26
+ :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
27
+ :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
28
+ if e_pages.last != e_pages.current %>
29
+ <%= link_to_remote('&lt;',
30
+ { :update => 'listByVote',
31
+ :url => { :action => 'listByVote', :id => @elt, :page => e_pages.current.next },
32
+ :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
33
+ :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
34
+ if e_pages.current.next and e_pages.current.next != e_pages.last %>
30
35
 
31
- <%= link_to_remote('&gt;',
32
- { :update => 'listByVote',
33
- :url => { :action => 'listByVote', :id => @elt, :page => e_pages.current.previous },
34
- :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
35
- :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
36
- if e_pages.current.previous and e_pages.current.previous != e_pages.first %>
37
- <%= link_to_remote('&gt;|',
38
- { :update => 'listByVote',
39
- :url => { :action => 'listByVote', :id => @elt, :page => e_pages.first },
40
- :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
41
- :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
42
- if e_pages.first != e_pages.current %>
43
- <% end %>
36
+ <span class="pageCount"><%= e_pages.length-e_pages.current.to_i+1 %></span>
44
37
 
45
- <ul>
46
- <% elts.each do |elt| %>
47
- <li class="boxLine elt" title="<%= elt.created_on.strftime('%d/%m %H:%M') %>">
48
- <span>
49
- <%= link_to_remote("%+d" % elt.resultlocal,
50
- { :update => 'resultList_'+elt.id,
51
- :position => :top,
52
- :url => { :action => 'choices', :id => elt } },
53
- { :class => 'result', :id => "resultList_#{ elt.id}",
54
- :href => url_for(:controller => 'elt', :action => 'choices', :id => elt) }
55
- ) if elt.resultlocal %>
56
- </span>
38
+ <%= link_to_remote('&gt;',
39
+ { :update => 'listByVote',
40
+ :url => { :action => 'listByVote', :id => @elt, :page => e_pages.current.previous },
41
+ :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
42
+ :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
43
+ if e_pages.current.previous and e_pages.current.previous != e_pages.first %>
44
+ <%= link_to_remote('&gt;|',
45
+ { :update => 'listByVote',
46
+ :url => { :action => 'listByVote', :id => @elt, :page => e_pages.first },
47
+ :before => visual_effect(:BlindUp, 'listByVote', { :queue => 'end' }),
48
+ :loaded => visual_effect(:BlindDown, 'listByVote', { :queue => 'end' }) }) \
49
+ if e_pages.first != e_pages.current %>
50
+ <% end %>
57
51
 
58
- <% if elt.person %>
59
- <span class="author">
60
- &lt;<%= link_to(elt.person.name, :controller => 'person', :action => 'show', :id => elt.person) %>&gt;
61
- </span>
62
- <% elsif not displayTitle? elt %>
63
- <span class="author">&lt;<%= ANONYMOUS_POSTER %>&gt;</span>
64
- <% end %>
52
+ <ul>
53
+ <% elts.each do |elt| %>
54
+ <li class="boxLine elt" title="<%= elt.created_on.strftime '%d/%m %H:%M' %>">
55
+ <span class="created_on"><%= elt.created_on.strftime '%d/%m %H:%M' %></span>
56
+ <span>
57
+ <%= link_to_remote("%+d" % elt.resultlocal,
58
+ { :update => 'resultList_'+elt.id,
59
+ :position => :top,
60
+ :url => { :action => 'choices', :id => elt } },
61
+ { :class => 'result', :id => "resultList_#{ elt.id}",
62
+ :href => url_for(:controller => 'elt', :action => 'choices', :id => elt) }
63
+ ) if elt.resultlocal %>
64
+ </span>
65
65
 
66
- <%= link_to elt.subject.gsub(/\[.*\]/, ''), :action => 'show', :id => elt %>
67
- </li>
68
- <% end %>
69
- </ul>
66
+ <% if elt.person %>
67
+ <span class="author">
68
+ &lt;<%= link_to elt.person.name, :controller => 'person', :action => 'show', :id => elt.person %>&gt;
69
+ </span>
70
+ <% elsif not displayTitle? elt %>
71
+ <span class="author">&lt;<%= ANONYMOUS_POSTER %>&gt;</span>
72
+ <% end %>
70
73
 
71
- <%= link_to image_tag("/images/webfeed.gif"), :action => 'vote_rss', :id => @elt %>
72
- </div>
74
+ <%= link_to elt.subject.gsub(/\[.*\]/, ''), :action => 'show', :id => elt %>
75
+ </li>
76
+ <% end %>
77
+ </ul>
73
78