diff options
-rwxr-xr-x | datepoll.rb | 20 | ||||
-rw-r--r-- | dudle.css | 4 | ||||
-rwxr-xr-x | poll.rb | 53 |
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 @@ -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; @@ -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} |