From 1420a7d3278c8fac42efa2bbb194971afd029de8 Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Tue, 4 Nov 2008 05:10:00 +0100 Subject: added sort feature --- poll.rb | 53 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 21 deletions(-) (limited to 'poll.rb') diff --git a/poll.rb b/poll.rb index e60ff23..7ece36a 100755 --- a/poll.rb +++ b/poll.rb @@ -13,32 +13,26 @@ class Poll @comment = [] store "Poll #{name} created" end + def sort_data field + @data.sort{|x,y| + if field == "name" + x[0] <=> y[0] + elsif x[1][field].nil? or y[1][field].nil? + x[1][field].to_s <=> y[1][field].to_s + else + x[1][field] <=> y[1][field] + end + } + end def head_to_html - ret = "\n" + ret = "Name\n" @head.sort.each{|columntitle,columndescription| - ret += "#{columntitle}\n" + ret += "#{columntitle}\n" } - ret += "Last Edit\n" + ret += "Last Edit\n" ret += "\n" ret end - def add_remove_column_htmlform - return < -
add/remove column -
-
- - - - - -
-
-
- -END - end def to_html ret = "
\n" ret += "
\n" @@ -46,7 +40,7 @@ END ret += head_to_html - @data.sort{|x,y| x[1]["timestamp"] <=> y[1]["timestamp"]}.each{|participant,poll| + sort_data($cgi.include?("sort") ? $cgi["sort"] : "timestamp").each{|participant,poll| ret += "\n" ret += "#{participant}\n" @head.sort.each{|columntitle,columndescription| @@ -155,6 +149,23 @@ COMMENT ret += "
\n" ret end + def add_remove_column_htmlform + return < +
add/remove column + +
+ + + + + +
+ +
+ +END + end def add_participant(name, agreed) htmlname = CGI.escapeHTML(name.strip) @data[htmlname] = {"timestamp" => Time.now} -- cgit v1.2.3