From 2dc0e9bd872a59205e597a8c9a1e6f340f5c86a2 Mon Sep 17 00:00:00 2001 From: Benjamin Kellermann Date: Wed, 1 Jul 2009 22:47:10 +0200 Subject: first try to implement DateTime --- config.cgi | 3 +- datepoll.rb | 150 ++++++++++++++++++++++++++++++++++++++++++++++----------- dudle.css | 9 +++- participate.rb | 2 + poll.rb | 18 ++++--- 5 files changed, 142 insertions(+), 40 deletions(-) diff --git a/config.cgi b/config.cgi index bbfb0fd..aff410b 100755 --- a/config.cgi +++ b/config.cgi @@ -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 += < @@ -82,9 +83,7 @@ INVITEDELETE $htmlout +=<
add/remove column -
#{table.add_remove_column_htmlform} -
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 = "\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 = "" + head_count("%Y-%m","-%d %H:%M%Z").each{|title,count| year, month = title.split("-").collect{|e| e.to_i} ret += "#{Date::ABBR_MONTHNAMES[month]} #{year}\n" } - ret += "Name\n" - @head.sort.each{|curdate,curdescription| - ret += "#{Date::ABBR_DAYNAMES[curdate.wday]}, #{curdate.day}\n" + ret += "" + head_count("%Y-%m-%d", " %H:%M%Z").each{|title,count| + curdate = Date.parse(title) + ret += "#{curdate.strftime("%a, %d")}\n" + } + ret += "Name" + @head.keys.sort.each{|curdate| + if curdate.class == Date + ret += "---\n" + else + ret += "#{curdate.strftime("%H:%M")}\n" + end } - ret += "Last Edit\n" - ret += "\n" - ret + ret += "Last Edit" + 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 def navi val @@ -70,7 +99,7 @@ END ret += "\n" - 7.times{|i| ret += "" } + 7.times{|i| ret += "" } ret += "\n" ((startdate.wday+7-1)%7).times{ @@ -89,16 +118,78 @@ END
#{Date::ABBR_DAYNAMES[(i+1)%7]}#{Date::ABBR_DAYNAMES[(i+1)%7]}
+
+END + + ret += "
" + + head_count("%Y-%m", "-%d").each{|title,count| + year,month = title.split("-").collect{|e| e.to_i} + ret += "\n" + } + + ret += "" + + head_count("%Y-%m-%d","").each{|title,count| + curdate = Date.parse(title) + ret += "\n" + } + + ret += "" + + ["00:00", "10:00","13:00","14:00","20:00"].each{|time| + ret +="\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 + } + ret += "
\n" + } + ret += < +
+
+ + +
+ + 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 ;--)")) diff --git a/dudle.css b/dudle.css index 2d74432..179ae7a 100644 --- a/dudle.css +++ b/dudle.css @@ -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 += < diff --git a/poll.rb b/poll.rb index 3e634e1..00c2fe5 100644 --- a/poll.rb +++ b/poll.rb @@ -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 end def add_participant(name, agreed) -- cgit v1.2.3
#{Date::ABBR_MONTHNAMES[month]} #{year}
#{curdate.strftime("%a, %d")}