aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2008-11-04 05:10:00 +0100
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2008-11-04 05:10:00 +0100
commit1420a7d3278c8fac42efa2bbb194971afd029de8 (patch)
tree79c2ab6e7542673b7fc3b63d07c939b1b77c8840
parent3c1d48f5da7f1af8523fe85885c0ec9959a6317c (diff)
added sort feature
-rwxr-xr-xdatepoll.rb20
-rw-r--r--dudle.css4
-rwxr-xr-xpoll.rb53
3 files changed, 52 insertions, 25 deletions
diff --git a/datepoll.rb b/datepoll.rb
index 34e2397..c9d8c66 100755
--- a/datepoll.rb
+++ b/datepoll.rb
@@ -5,6 +5,18 @@ require "date"
require "poll"
class DatePoll < Poll
+ def sort_data field
+ @data.sort{|x,y|
+ if field == "name"
+ x[0] <=> y[0]
+ elsif field == "timestamp"
+ x[1][field] <=> y[1][field]
+ else
+ datefield = Date.parse(field)
+ x[1][datefield].to_s <=> y[1][datefield].to_s
+ end
+ }
+ end
def head_to_html
ret = "<tr><td></td>\n"
monthhead = Hash.new(0)
@@ -15,11 +27,11 @@ class DatePoll < Poll
year, month = title.split("-").collect{|e| e.to_i}
ret += "<th colspan='#{count}'>#{Date::ABBR_MONTHNAMES[month]} #{year}</th>\n"
}
- ret += "</tr><tr><td></td>\n"
+ ret += "</tr><tr><th><a href='?sort=name'>Name</a></th>\n"
@head.sort.each{|curdate,curdescription|
- ret += "<th>#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day}</th>\n"
+ ret += "<th><a href='?sort=#{curdate.to_s}'>#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day}</a></th>\n"
}
- ret += "<th>Last Edit</th>\n"
+ ret += "<th><a href='.'>Last Edit</a></th>\n"
ret += "</tr>\n"
ret
end
@@ -28,7 +40,7 @@ class DatePoll < Poll
begin
startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1")
rescue ArgumentError
- olddate = $cgi.params["add_remove_column_month"][1]
+ olddate = $cgi.params["add_remove_column_month"][1]
case $cgi["add_remove_column_month"]
when YEARBACK
startdate = Date.parse("#{olddate}-1")-365
diff --git a/dudle.css b/dudle.css
index 826c2f3..6abf3bc 100644
--- a/dudle.css
+++ b/dudle.css
@@ -50,6 +50,10 @@ th {
background-color:black;
font-weight: normal;
}
+th a{
+ color: white;
+ text-decoration: none;
+}
td.date {
color: Gray;
text-align: left;
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 = "<tr><td></td>\n"
+ ret = "<tr><th><a href='?sort=name'>Name</a></th>\n"
@head.sort.each{|columntitle,columndescription|
- ret += "<th title='#{columndescription}'>#{columntitle}</th>\n"
+ ret += "<th title='#{columndescription}'><a href='?sort=#{columntitle}'>#{columntitle}</a></th>\n"
}
- ret += "<th>Last Edit</th>\n"
+ ret += "<th><a href='.'>Last Edit</a></th>\n"
ret += "</tr>\n"
ret
end
- def add_remove_column_htmlform
- return <<END
-<div id='add_remove_column'>
-<fieldset><legend>add/remove column</legend>
-<form method='post' action='.'>
-<div>
- <label for='columntitle'>Columntitle: </label>
- <input id='columntitle' size='16' type='text' value='#{$cgi["add_remove_column"]}' name='add_remove_column' />
- <label for='columndescription'>Description: </label>
- <input id='columndescription' size='30' type='text' value='#{$cgi["columndescription"]}' name='columndescription' />
- <input type='submit' value='add/remove column' />
-</div>
-</form>
-</fieldset>
-</div>
-END
- end
def to_html
ret = "<div id='polltable'>\n"
ret += "<form method='post' action='.'>\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 += "<tr>\n"
ret += "<td class='name'>#{participant}</td>\n"
@head.sort.each{|columntitle,columndescription|
@@ -155,6 +149,23 @@ COMMENT
ret += "</div>\n"
ret
end
+ def add_remove_column_htmlform
+ return <<END
+<div id='add_remove_column'>
+<fieldset><legend>add/remove column</legend>
+<form method='post' action='.'>
+<div>
+ <label for='columntitle'>Columntitle: </label>
+ <input id='columntitle' size='16' type='text' value='#{$cgi["add_remove_column"]}' name='add_remove_column' />
+ <label for='columndescription'>Description: </label>
+ <input id='columndescription' size='30' type='text' value='#{$cgi["columndescription"]}' name='columndescription' />
+ <input type='submit' value='add/remove column' />
+</div>
+</form>
+</fieldset>
+</div>
+END
+ end
def add_participant(name, agreed)
htmlname = CGI.escapeHTML(name.strip)
@data[htmlname] = {"timestamp" => Time.now}