diff options
author | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-07-01 22:47:10 +0200 |
---|---|---|
committer | Benjamin Kellermann <Benjamin.Kellermann@gmx.de> | 2009-07-01 22:47:10 +0200 |
commit | 2dc0e9bd872a59205e597a8c9a1e6f340f5c86a2 (patch) | |
tree | 5398757f6fd33c757460188c100f8e1313d975d4 | |
parent | e44d4f91fc2e9b6b2142da071fce980ef0d6ee53 (diff) |
first try to implement DateTime
-rwxr-xr-x | config.cgi | 3 | ||||
-rw-r--r-- | datepoll.rb | 150 | ||||
-rw-r--r-- | dudle.css | 9 | ||||
-rw-r--r-- | participate.rb | 2 | ||||
-rw-r--r-- | poll.rb | 18 |
5 files changed, 142 insertions, 40 deletions
@@ -42,6 +42,7 @@ else table.add_remove_column($cgi["add_remove_column"],$cgi["columndescription"]) if $cgi.include?("add_remove_column") table.toggle_hidden if $cgi.include?("toggle_hidden") end +table.init $htmlout += <<HTMLHEAD <head> @@ -82,9 +83,7 @@ INVITEDELETE $htmlout +=<<ADD_REMOVE <div id='add_remove_column'> <fieldset><legend>add/remove column</legend> -<form method='post' action=''> #{table.add_remove_column_htmlform} -</form> </fieldset> </div> ADD_REMOVE diff --git a/datepoll.rb b/datepoll.rb index 5d78cec..d16a225 100644 --- a/datepoll.rb +++ b/datepoll.rb @@ -6,57 +6,86 @@ require "date" require "poll" +load "time.rb" class DatePoll < Poll + def init + #FIXME: quick 'n' dirty hack, because Time <=> Date is not possible and yaml loads Time instead of DateTime! + #better solution would be to overwrite <=> + @head.each{|k,v| + if k.class == Time + @head.delete(k) + @head[DateTime.parse(k.to_s)]=v + end + } + end def sort_data fields datefields = fields.collect{|field| - field == "timestamp" || field == "name" ? field : Date.parse(field) + field == "timestamp" || field == "name" ? field : DateTime.parse(field) } super datefields end - def head_to_html(config = false) - ret = "<tr><td></td>\n" - monthhead = Hash.new(0) - @head.sort.each{|curdate,curdescription| - monthhead["#{curdate.year}-#{curdate.mon.to_s.rjust(2,"0")} "] += 1 + # returns a sorted array, containing the big units and how often each small is in the big one + # small and big must be formated for strftime + # ex: head_count("%Y-%m", "-%d") returns an array like [["2009-03",2],["2009-04",3]] + def head_count(big,small) + ret = Hash.new(0) + @head.keys.collect{|curdate| + DateTime.parse(curdate.strftime(big + small)) + }.uniq.each{|day| + ret[day.strftime(big)] += 1 } - monthhead.sort.each{|title,count| + ret.sort + end + + def head_to_html(config = false) + ret = "<tr><td></td>" + head_count("%Y-%m","-%d %H:%M%Z").each{|title,count| year, month = title.split("-").collect{|e| e.to_i} ret += "<th colspan='#{count}'>#{Date::ABBR_MONTHNAMES[month]} #{year}</th>\n" } - ret += "</tr><tr><th><a href='?sort=name'>Name</a></th>\n" - @head.sort.each{|curdate,curdescription| - ret += "<th><a href='?sort=#{curdate.to_s}'>#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day}</a></th>\n" + ret += "</tr><tr><td></td>" + head_count("%Y-%m-%d", " %H:%M%Z").each{|title,count| + curdate = Date.parse(title) + ret += "<th colspan='#{count}'>#{curdate.strftime("%a, %d")}</th>\n" + } + ret += "</tr><tr><th><a href='?sort=name'>Name</a></th>" + @head.keys.sort.each{|curdate| + if curdate.class == Date + ret += "<th><a href='?sort=#{curdate.to_s}'>---</a></th>\n" + else + ret += "<th><a href='?sort=#{curdate.to_s}'>#{curdate.strftime("%H:%M")}</a></th>\n" + end } - ret += "<th><a href='.'>Last Edit</a></th>\n" - ret += "</tr>\n" - ret + ret += "<th><a href='.'>Last Edit</a></th></tr>" + ret end def add_remove_column_htmlform if $cgi.include?("add_remove_column_month") begin - startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1") + startdate = DateTime.parse("#{$cgi["add_remove_column_month"]}-1") rescue ArgumentError olddate = $cgi.params["add_remove_column_month"][1] case $cgi["add_remove_column_month"] when CGI.unescapeHTML(YEARBACK) - startdate = Date.parse("#{olddate}-1")-365 + startdate = DateTime.parse("#{olddate}-1")-365 when CGI.unescapeHTML(MONTHBACK) - startdate = Date.parse("#{olddate}-1")-1 + startdate = DateTime.parse("#{olddate}-1")-1 when CGI.unescapeHTML(MONTHFORWARD) - startdate = Date.parse("#{olddate}-1")+31 + startdate = DateTime.parse("#{olddate}-1")+31 when CGI.unescapeHTML(YEARFORWARD) - startdate = Date.parse("#{olddate}-1")+366 + startdate = DateTime.parse("#{olddate}-1")+366 else exit end - startdate = Date.parse("#{startdate.year}-#{startdate.month}-1") + startdate = DateTime.parse(startdate.strftime("%Y-%m-1")) end else - startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1") + startdate = DateTime.parse(Date.today.strftime("%Y-%m-1")) end ret = <<END -<div> +<form method='post' action=''> +<div style="float: left; margin-right: 20px"> <table><tr> END def navi val @@ -70,7 +99,7 @@ END ret += "</tr><tr>\n" - 7.times{|i| ret += "<th>#{Date::ABBR_DAYNAMES[(i+1)%7]}</th>" } + 7.times{|i| ret += "<th class='weekday'>#{Date::ABBR_DAYNAMES[(i+1)%7]}</th>" } ret += "</tr><tr>\n" ((startdate.wday+7-1)%7).times{ @@ -89,16 +118,78 @@ END </tr></table> <input type='hidden' name='add_remove_column_month' value='#{startdate.strftime("%Y-%m")}' /> </div> +</form> +END + + ret += "<div><table><tr>" + + head_count("%Y-%m", "-%d").each{|title,count| + year,month = title.split("-").collect{|e| e.to_i} + ret += "<th colspan='#{count}'>#{Date::ABBR_MONTHNAMES[month]} #{year}</th>\n" + } + + ret += "</tr><tr>" + + head_count("%Y-%m-%d","").each{|title,count| + curdate = Date.parse(title) + ret += "<th>#{curdate.strftime("%a, %d")}</th>\n" + } + + ret += "</tr>" + + ["00:00", "10:00","13:00","14:00","20:00"].each{|time| + ret +="<tr>\n" + @head.sort.collect{|day,descr| + Date.parse(day.strftime("%Y-%m-%d")) + }.uniq.each{|date| + timestamp = DateTime.parse("#{date} #{time} #{Time.now.zone}") + klasse = "notchoosen" + klasse = "disabled" if timestamp < DateTime.now + klasse = "choosen" if @head.include?(timestamp) + ret += <<END +<td class='calendarday'> + <form method='post' action="config.cgi"> + <div> + <!--Timestamp: #{timestamp.to_s} --> + <input class='#{klasse}' type='submit' name='add_remove_column' value='#{time}' /> + <input type='hidden' name='add_remove_column_day' value='#{timestamp.day}' /> + <input type='hidden' name='add_remove_column_month' value='#{timestamp.strftime("%Y-%m")}' /> + </div> + </form> +</td> +END + } + ret += "</tr>\n" + } + ret += <<END + </table> + <form method='post' action='config.cgi'> + <div> + <input name='add_remove_column' size='1' /> + <input name="add_remove_column" type="submit" value="Add Time" /> + </div> + </form> +</div> END ret end - def add_remove_column name,description - begin - parsed_name = Date.parse("#{$cgi["add_remove_column_month"]}-#{name}") - rescue ArgumentError - return false + def add_remove_column col,description + if $cgi.include?("add_remove_column_day") + begin + parsed_date = YAML::load(DateTime.parse("#{$cgi["add_remove_column_month"]}-#{$cgi["add_remove_column_day"]} #{col} #{Time.now.zone}").to_yaml) + day = Date.parse(parsed_date.to_s) + @head.delete(day) if @head.include?(day) + rescue ArgumentError + return false + end + else + begin + parsed_date = YAML::load(Date.parse("#{$cgi["add_remove_column_month"]}-#{col}").to_yaml) + rescue ArgumentError + return false + end end - add_remove_parsed_column(parsed_name,CGI.escapeHTML(description)) + add_remove_parsed_column(parsed_date,CGI.escapeHTML(description)) end end @@ -119,8 +210,9 @@ $cgi = CGI.new class DatePollTest < Test::Unit::TestCase def setup - @poll = DatePoll.new(SITE, false) + @poll = DatePoll.new(SITE) end + #TODO def test_add_remove_column assert(!@poll.add_remove_column("foo", "bar")) assert(!@poll.add_remove_column("31", "31.02.2008 ;--)")) @@ -23,14 +23,19 @@ input.historynavi{ background-color: white; color: blue; } +th.weekday{ + width: 2.5em; +} input.navigation, input.disabled, input.choosen, input.notchoosen { border-width: 1px; border-style: solid; border-color: black; padding: 0px; cursor: pointer; - width: 3.5em; - height: 3.5ex; + width: 100%; + height: 100%; +/* width: 3.5em; + height: 3.5ex;*/ } input.navigation { color: white; diff --git a/participate.rb b/participate.rb index feca58f..cb4bad6 100644 --- a/participate.rb +++ b/participate.rb @@ -31,6 +31,8 @@ else table.delete_comment($cgi["delete_comment"].to_i) if $cgi.include?("delete_comment") end +table.init + $htmlout += <<HEAD <head> <meta http-equiv="Content-Type" content="#{TYPE}; charset=#{CHARSET}" /> @@ -20,6 +20,8 @@ class Poll @comment = [] store "Poll #{name} created" end + def init + end def sort_data fields if fields.include?("name") until fields.pop == "name" @@ -230,13 +232,15 @@ ADDCOMMENT description = CGI.escapeHTML($cgi["columndescription"]) end return <<END -<div> - <label for='columntitle'>Columntitle: </label> - <input id='columntitle' size='16' type='text' value="#{title}" name='add_remove_column' /> - <label for='columndescription'>Description: </label> - <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' /> - <input type='submit' value='add/remove column' /> -</div> +<form method='post' action=''> + <div> + <label for='columntitle'>Columntitle: </label> + <input id='columntitle' size='16' type='text' value="#{title}" name='add_remove_column' /> + <label for='columndescription'>Description: </label> + <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' /> + <input type='submit' value='add/remove column' /> + </div> +</form> END end def add_participant(name, agreed) |