aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-18 00:13:11 +0100
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-18 00:13:11 +0100
commit550af3cfe7177a881ce08431ef9789a352885cdf (patch)
tree374cda73c27807a8bc4477058675704c3c7b3698
parentc070e384c317f60974c391052bc11f2519c01bb8 (diff)
restructured datepoll -> timepollhead (not ready yet)
-rwxr-xr-xatom_single.rb2
-rwxr-xr-xconfig_poll.rb6
-rw-r--r--dudle.css9
-rwxr-xr-xindex.cgi9
-rwxr-xr-xparticipate.rb2
-rw-r--r--poll.rb128
-rw-r--r--pollhead.rb116
-rw-r--r--timepoll.rb205
-rw-r--r--timepollhead.rb (renamed from datepoll.rb)115
9 files changed, 236 insertions, 356 deletions
diff --git a/atom_single.rb b/atom_single.rb
index 048b1d6..b07faa1 100755
--- a/atom_single.rb
+++ b/atom_single.rb
@@ -20,8 +20,6 @@ olddir = File.expand_path(".")
Dir.chdir("..")
load "config.rb"
require "poll"
-require "datepoll"
-require "timepoll"
Dir.chdir(olddir)
poll = YAML::load_file("data.yaml")
diff --git a/config_poll.rb b/config_poll.rb
index 9a016b3..ba3060f 100755
--- a/config_poll.rb
+++ b/config_poll.rb
@@ -30,8 +30,6 @@ Dir.chdir("..")
load "charset.rb"
load "config.rb"
require "poll"
-require "datepoll"
-require "timepoll"
Dir.chdir(olddir)
# BUGFIX for Time.parse, which handles the zone indeterministically
class << Time
@@ -65,8 +63,8 @@ else
table.add_participant($cgi["olduser"],$cgi["add_participant"],{})
end
end
- table.edit_column($cgi["new_columnname"],$cgi["columndescription"],$cgi["old_columnname"]) if $cgi.include?("new_columnname")
- table.delete_column($cgi["delete_column"]) if $cgi.include?("delete_column")
+ table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname")
+ table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn")
def writehtaccess(acusers)
File.open(".htaccess","w"){|htaccess|
diff --git a/dudle.css b/dudle.css
index 73feb93..45cedc2 100644
--- a/dudle.css
+++ b/dudle.css
@@ -23,15 +23,6 @@ td.name {
span.edituser a{ text-decoration: none }
-input.deletebutton{
- border-width: 0px;
- border-style: solid;
- padding: 0px;
- cursor: pointer;
- background-color: black;
- color: white;
-}
-
th.weekday{
width: 2.5em;
}
diff --git a/index.cgi b/index.cgi
index 1bb3c05..6d8b982 100755
--- a/index.cgi
+++ b/index.cgi
@@ -33,8 +33,6 @@ else
end
require "poll"
-require "datepoll"
-require "timepoll"
$htmlout += <<HEAD
<head>
@@ -68,12 +66,7 @@ if $cgi.include?("create_poll")
File.open(f,"w").close
VCS.add(f)
}
- case $cgi["poll_type"]
- when "normal"
- Poll.new SITE
- when "time"
- TimePoll.new SITE
- end
+ Poll.new(SITE,$cgi["poll_type"])
Dir.chdir("..")
escapedsite = SITEURL + CGI.escapeHTML(CGI.escape(SITE)) + "/"
escapedsite.gsub!("+"," ")
diff --git a/participate.rb b/participate.rb
index c3d2884..d13ea7d 100755
--- a/participate.rb
+++ b/participate.rb
@@ -28,8 +28,6 @@ HEAD
olddir = File.expand_path(".")
Dir.chdir("..")
require "poll"
-require "datepoll"
-require "timepoll"
load "charset.rb"
load "config.rb"
Dir.chdir(olddir)
diff --git a/poll.rb b/poll.rb
index 9704161..8aab599 100644
--- a/poll.rb
+++ b/poll.rb
@@ -7,64 +7,50 @@
require "hash"
require "yaml"
require "time"
+require "pollhead"
+require "timepollhead"
class Poll
attr_reader :head, :name
YESVAL = "ayes"
MAYBEVAL = "bmaybe"
NOVAL = "cno"
- def initialize name
+ def initialize name,type
@name = name
- @head = {}
+
+ case type
+ when "normal"
+ @head = PollHead.new
+ when "time"
+ @head = TimePollHead.new
+ else
+ raise("unknown poll type: #{type}")
+ end
@data = {}
@comment = []
store "Poll #{name} created"
end
def sort_data fields
- if fields.include?("name")
- until fields.pop == "name"
+ parsedfields = fields.collect{|field|
+ field == "timestamp" || field == "name" ? field : @head.cgi_to_id(field)
+ }
+ if parsedfields.include?("name")
+ until parsedfields.pop == "name"
end
@data.sort{|x,y|
- cmp = x[1].compare_by_values(y[1],fields)
+ cmp = x[1].compare_by_values(y[1],parsedfields)
cmp == 0 ? x[0] <=> y[0] : cmp
}
else
- @data.sort{|x,y| x[1].compare_by_values(y[1],fields) }
+ @data.sort{|x,y| x[1].compare_by_values(y[1],parsedfields) }
end
end
- def head_to_html(config = false,activecolumn = nil)
- ret = "<tr><th><a href='?sort=name'>Name</a></th>\n"
- @head.sort.each{|columntitle,columndescription|
- ret += "<th"
- ret += " id='active' " if activecolumn == columntitle
- ret += "><a title=\"#{columndescription}\" href=\"?sort=#{CGI.escapeHTML(CGI.escape(columntitle))}\">#{CGI.escapeHTML(columntitle)}</a>"
- if config
- ret += <<EDITDELETE
-<form method='post' action=''>
- <div>
- <small>
- <a href="?editcolumn=#{CGI.escapeHTML(CGI.escape(columntitle))}" title="edit">
- #{EDIT}
- </a>|
- <input type='hidden' name='delete_column' value="#{CGI.escapeHTML(columntitle)}" />
- <input type="submit" value="#{DELETE}" title="delete" class="deletebutton" #{activecolumn == columntitle ? 'id="activedeletebutton"' : ''} />
- </small>
- </div>
-</form>
-EDITDELETE
- end
- ret += "</th>"
- }
- ret += "<th><a href='.'>Last Edit</a></th>\n"
- ret += "</tr>\n"
- ret
- end
def to_html(edituser = "", config = false,activecolumn = nil)
ret = "<table border='1'>\n"
- ret += head_to_html(config, activecolumn)
+ ret += @head.to_html(config, activecolumn)
sort_data($cgi.include?("sort") ? $cgi.params["sort"] : ["timestamp"]).each{|participant,poll|
if edituser == participant
ret += participate_to_html(edituser, config)
@@ -74,8 +60,8 @@ EDITDELETE
ret += participant
ret += "<span class='edituser'> <sup><a href=\"?edituser=#{CGI.escapeHTML(CGI.escape(participant))}\">#{EDIT}</a></sup></span>"
ret += "</td>\n"
- @head.sort.each{|columntitle,columndescription|
- klasse = poll[columntitle]
+ @head.each_column{|columnid,columntitle|
+ klasse = poll[columnid]
case klasse
when nil
value = UNKNOWN
@@ -99,13 +85,13 @@ EDITDELETE
# SUMMARY
ret += "<tr id='summary'><td class='name'>total</td>\n"
- @head.sort.each{|columntitle,columndescription|
+ @head.each_columnid{|columnid|
yes = 0
undecided = 0
@data.each_value{|participant|
- if participant[columntitle] == YESVAL
+ if participant[columnid] == YESVAL
yes += 1
- elsif !participant.has_key?(columntitle) or participant[columntitle] == MAYBEVAL
+ elsif !participant.has_key?(columnid) or participant[columnid] == MAYBEVAL
undecided += 1
end
}
@@ -141,9 +127,9 @@ EDITDELETE
def participate_to_html(edituser, config)
checked = {}
if @data.include?(edituser)
- @head.each_key{|k| checked[k] = @data[edituser][k]}
+ @head.each_columnid{|k| checked[k] = @data[edituser][k]}
else
- @head.each_key{|k| checked[k] = NOVAL}
+ @head.each_columnid{|k| checked[k] = NOVAL}
end
ret = "<tr id='add_participant'>\n"
ret += "<td class='name'>
@@ -154,19 +140,19 @@ EDITDELETE
value=\"#{edituser}\"/>"
ret += "</td>\n"
unless config
- @head.sort.each{|columntitle,columndescription|
+ @head.each_column{|columnid,columntitle|
ret += "<td class='checkboxes'><table>"
[[YES, YESVAL],[NO, NOVAL],[MAYBE, MAYBEVAL]].each{|valhuman, valbinary|
ret += "<tr>
<td>
<input type='radio'
value='#{valbinary}'
- id=\"add_participant_checked_#{CGI.escapeHTML(columntitle.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\"
- name=\"add_participant_checked_#{CGI.escapeHTML(columntitle.to_s)}\"
- title=\"#{CGI.escapeHTML(columntitle.to_s)}\" #{checked[columntitle] == valbinary ? "checked='checked'":""}/>
+ id=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\"
+ name=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s)}\"
+ title=\"#{CGI.escapeHTML(columntitle.to_s)}\" #{checked[columnid] == valbinary ? "checked='checked'":""}/>
</td>
<td class='input-#{valbinary}'>
- <label for=\"add_participant_checked_#{CGI.escapeHTML(columntitle.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\">#{valhuman}</label>
+ <label for=\"add_participant_checked_#{CGI.escapeHTML(columnid.to_s.gsub(" ","_").gsub("+","_"))}_#{valbinary}\">#{valhuman}</label>
</td>
</tr>"
}
@@ -174,7 +160,7 @@ EDITDELETE
}
ret += "<td class='checkboxes'>"
else
- ret += "<td class='checkboxes' colspan='#{@head.size + 1}'>"
+ ret += "<td class='checkboxes' colspan='#{@head.col_size + 1}'>"
end
if @data.include?(edituser)
ret += "<input type='submit' value='edit user' />"
@@ -263,8 +249,8 @@ ADDCOMMENT
htmlname = CGI.escapeHTML(name)
@data.delete(CGI.escapeHTML(olduser))
@data[htmlname] = {"timestamp" => Time.now }
- @head.each_key{|columntitle|
- @data[htmlname][columntitle] = agreed[columntitle.to_s]
+ @head.each_columnid{|columnid|
+ @data[htmlname][columnid] = agreed[columnid.to_s]
}
store "Participant #{name.strip} edited"
end
@@ -301,51 +287,23 @@ ADDCOMMENT
###############################
# column related functions
###############################
- def parsecolumntitle title
- title.strip
- end
-
- def delete_column title
- parsedtitle = parsecolumntitle(title)
- if @head.include?(parsedtitle)
- @head.delete(parsedtitle)
- store "Column #{parsedtitle} deleted"
+ def delete_column columnid
+ title = @head.get_title(columnid)
+ if @head.delete_column(columnid)
+ store "Column #{title} deleted"
return true
else
return false
end
end
- def edit_column(newtitle, description, oldtitle = nil)
- @head.delete(oldtitle) if oldtitle
- parsedtitle = parsecolumntitle(newtitle)
-
- @head[parsedtitle] = CGI.escapeHTML(description.strip)
- store "Column #{parsedtitle} edited"
- true
+ def edit_column(oldcolumnid, newtitle, cgi)
+ parsedtitle = @head.edit_column(oldcolumnid, newtitle, cgi)
+ store "Column #{parsedtitle} edited" if parsedtitle
end
def edit_column_htmlform(activecolumn)
- if activecolumn
- title = activecolumn
- description = @head[title]
- title = CGI.escapeHTML(title)
- end
- return <<END
-<fieldset><legend>Add/Edit Column</legend>
-<form method='post' action='config.cgi'>
- <div>
- <label for='columntitle'>Columntitle: </label>
- <input id='columntitle' size='16' type='text' value="#{title}" name='new_columnname' />
- <label for='columndescription'>Description: </label>
- <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' />
- <input type='hidden' name='old_columnname' value="#{title}" />
- <input type='submit' value='add/edit column' />
- </div>
-</form>
-</fieldset>
-END
+ @head.edit_column_htmlform(activecolumn)
end
-
end
diff --git a/pollhead.rb b/pollhead.rb
new file mode 100644
index 0000000..339498a
--- /dev/null
+++ b/pollhead.rb
@@ -0,0 +1,116 @@
+################################
+# Author: Benjamin Kellermann #
+# License: CC-by-sa 3.0 #
+# see License #
+################################
+require "digest/sha2"
+
+class PollHead
+ def initialize
+ @data = {}
+ end
+ def col_size
+ @data.size
+ end
+
+ def get_id(columntitle)
+ if @data.include?(columntitle)
+ return Digest::SHA2.hexdigest("#{columntitle}#{@data[columntitle]}" + columntitle)
+ else
+ raise("no such column found: #{columntitle}")
+ end
+ end
+ def get_title(columnid)
+ @data.each_key{|k| return k if get_id(k) == columnid}
+ raise("no such id found: #{columnid}")
+ end
+ def each_columntitle
+ @data.sort.each{|k,v|
+ yield(k)
+ }
+ end
+ def each_columnid
+ @data.sort.each{|k,v|
+ yield(get_id(k))
+ }
+ end
+ def each_column
+ @data.sort.each{|k,v|
+ yield(get_id(k),k)
+ }
+ end
+
+ # returns internal representation of cgi-string
+ def cgi_to_id(field)
+ field
+ end
+
+ # returns true if deletion sucessfull
+ def delete_column(columnid)
+ @data.delete(get_title(columnid)) != nil
+ end
+
+ # add new column if columnid = ""
+ # returns parsed title or false if parsed title == ""
+ def edit_column(columnid, newtitle, cgi)
+ delete_column(columnid) if columnid != ""
+ parsedtitle = newtitle.strip
+
+ if parsedtitle != ""
+ @data[parsedtitle] = CGI.escapeHTML(cgi["columndescription"].strip)
+ return parsedtitle
+ else
+ return false
+ end
+ end
+
+ def to_html(config = false,activecolumn = nil)
+ ret = "<tr><th><a href='?sort=name'>Name</a></th>\n"
+ @data.each{|columntitle,columndescription|
+ ret += "<th"
+ ret += " id='active' " if activecolumn == columntitle
+ ret += "><a title=\"#{columndescription}\" href=\"?sort=#{CGI.escapeHTML(CGI.escape(columntitle))}\">#{CGI.escapeHTML(columntitle)}</a>"
+ if config
+ ret += <<EDITDELETE
+ <div>
+ <small>
+ <a href="?editcolumn=#{CGI.escapeHTML(CGI.escape(columntitle))}" title="edit">
+ #{EDIT}
+ </a>|
+ <a href="?deletecolumn=#{CGI.escapeHTML(CGI.escape(get_id(columntitle)))}" title="delete">
+ #{DELETE}
+ </a>
+ </small>
+ </div>
+EDITDELETE
+ end
+ ret += "</th>"
+ }
+ ret += "<th><a href='.'>Last Edit</a></th>\n"
+ ret += "</tr>\n"
+ ret
+ end
+
+ def edit_column_htmlform(activecolumn)
+ if activecolumn != ""
+ title = activecolumn
+ description = @data[title]
+ title = CGI.escapeHTML(title)
+ hiddeninput = "<input type='hidden' name='columnid' value=\"#{get_id(title)}\" />"
+ end
+ return <<END
+<fieldset><legend>Add/Edit Column</legend>
+<form method='post' action='config.cgi'>
+ <div>
+ <label for='columntitle'>Columntitle: </label>
+ <input id='columntitle' size='16' type='text' value="#{title}" name='new_columnname' />
+ <label for='columndescription'>Description: </label>
+ <input id='columndescription' size='30' type='text' value="#{description}" name='columndescription' />
+ #{hiddeninput}
+ <input type='submit' value='add/edit column' />
+ </div>
+</form>
+</fieldset>
+END
+ end
+end
diff --git a/timepoll.rb b/timepoll.rb
deleted file mode 100644
index d968072..0000000
--- a/timepoll.rb
+++ /dev/null
@@ -1,205 +0,0 @@
-################################
-# Author: Benjamin Kellermann #
-# License: CC-by-sa 3.0 #
-# see License #
-################################
-
-require "date"
-require "poll"
-require "time"
-
-class TimePoll < Poll
- def sort_data fields
- datefields = fields.collect{|field|
- field == "timestamp" || field == "name" ? field : Time.parse(field)
- }
- super datefields
- end
-
- # 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|
- Time.parse(curdate.strftime(big + small))
- }.uniq.each{|day|
- ret[day.strftime(big)] += 1
- }
- ret.sort
- end
-
- def head_to_html(config = false, activecolumn = nil)
- 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><td></td>"
- head_count("%Y-%m-%d", " %H:%M%Z").each{|title,count|
- ret += "<th colspan='#{count}'>#{Date.parse(title).strftime("%a, %d")}</th>\n"
- }
-
- ret += "</tr><tr><th><a href='?sort=name'>Name</a></th>"
- @head.keys.sort.each{|curdate|
- ret += "<th><a title='#{curdate}' href='?sort=#{CGI.escapeHTML(CGI.escape(curdate.to_s))}'>#{curdate.strftime("%H:%M")}</a></th>\n"
- }
- ret += "<th><a href='.'>Last Edit</a></th>\n</tr>\n"
- ret
- end
-
- def edit_column_htmlform(activecolumn)
- if $cgi.include?("add_remove_column_month")
- if $cgi.params["add_remove_column_month"].size == 1
- startdate = Date.parse("#{$cgi["add_remove_column_month"]}-1")
- else
- olddate = $cgi.params["add_remove_column_month"][1]
- case $cgi["add_remove_column_month"]
- when CGI.unescapeHTML(YEARBACK)
- startdate = Date.parse("#{olddate}-1")-365
- when CGI.unescapeHTML(MONTHBACK)
- startdate = Date.parse("#{olddate}-1")-1
- when CGI.unescapeHTML(MONTHFORWARD)
- startdate = Date.parse("#{olddate}-1")+31
- when CGI.unescapeHTML(YEARFORWARD)
- startdate = Date.parse("#{olddate}-1")+366
- else
- exit
- end
- startdate = Date.parse("#{startdate.year}-#{startdate.month}-1")
- end
- else
- startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1")
- end
- ret = <<END
-<fieldset><legend>Add/Remove Column</legend>
-<form method='post' action=''>
-<div style="float: left; margin-right: 20px">
-<table><tr>
-END
- def navi val
- "<th style='padding:0px'>" +
- "<input class='navigation' type='submit' name='add_remove_column_month' value='#{val}' />" +
- "</th>"
- end
- [YEARBACK,MONTHBACK].each{|val| ret += navi(val)}
- ret += "<th colspan='3'>#{Date::ABBR_MONTHNAMES[startdate.month]} #{startdate.year}</th>"
- [MONTHFORWARD, YEARFORWARD].each{|val| ret += navi(val)}
-
- ret += "</tr><tr>\n"
-
- 7.times{|i| ret += "<th class='weekday'>#{Date::ABBR_DAYNAMES[(i+1)%7]}</th>" }
- ret += "</tr><tr>\n"
-
- ((startdate.wday+7-1)%7).times{
- ret += "<td></td>"
- }
- d = startdate
- while (d.month == startdate.month) do
- klasse = "notchoosen"
- klasse = "disabled" if d < Date.today
- klasse = "choosen" if @head.keys.collect{|t|t.strftime("%Y-%m-%d")}.include?(d.strftime("%Y-%m-%d"))
- ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='new_columnname' value='#{d.day}' /></td>\n"
- ret += "</tr><tr>\n" if d.wday == 0
- d = d.next
- end
- ret += <<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|
- ret += "<th>#{Date.parse(title).strftime("%a, %d")}</th>\n"
- }
-
- ret += "</tr>"
-
-
- days = @head.sort.collect{|day,descr|
- Date.parse(day.strftime("%Y-%m-%d"))
- }.uniq
-
- @head.keys.collect{|time|
- time.strftime("%H:%M")
- }.uniq.sort.each{|time|
- ret +="<tr>\n"
- days.each{|date|
- timestamp = Time.parse("#{date} #{time}")
- klasse = "notchoosen"
- klasse = "disabled" if timestamp < Time.now
- klasse = "choosen" if @head.include?(timestamp)
- ret += <<END
-<td class='calendarday'>
- <form method='post' action="">
- <div>
- <!--Timestamp: #{timestamp} -->
- <input title='#{timestamp}' class='#{klasse}' type='submit' name='new_columnname' 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 += "<tr>"
- days.each{|d|
- ret += <<END
- <td>
- <form method='post' action=''>
- <div>
- <input type='hidden' name='add_remove_column_day' value='#{d.day}' />
- <input type='hidden' name='add_remove_column_month' value='#{d.strftime("%Y-%m")}' />
- <input name='new_columnname' type="text" maxlength="7" style="width: 7ex" /><br />
- <input type="submit" value="Add" style="width: 100%" />
- </div>
- </form>
- </td>
-END
- }
-
- ret += <<END
- </tr>
- </table>
-</div>
-</fieldset>
-END
- ret
- end
-
- def parsecolumntitle(title)
- if $cgi.include?("add_remove_column_day")
- parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{$cgi["add_remove_column_day"]} #{title}").to_yaml)
- else
- earlytime = @head.keys.collect{|t|t.strftime("%H:%M")}.sort[0]
- parsed_date = YAML::load(Time.parse("#{$cgi["add_remove_column_month"]}-#{title} #{earlytime}").to_yaml)
- end
- parsed_date
- end
-
- def edit_column(newtitle, description, oldtitle = nil)
- parsed_date = parsecolumntitle(newtitle)
- if @head.include?(parsed_date)
- delete_column(newtitle)
- else
- @head[parsed_date] = ""
- store "Column #{parsed_date} added"
- end
- true
- end
-end
-
diff --git a/datepoll.rb b/timepollhead.rb
index dcb2810..c945824 100644
--- a/datepoll.rb
+++ b/timepollhead.rb
@@ -3,33 +3,78 @@
# License: CC-by-sa 3.0 #
# see License #
################################
+require "digest/sha2"
-require "date"
-require "poll"
-require "time"
+class TimePollHead
+ def initialize
+ @data = {}
+ end
+ def col_size
+ @data.size
+ end
-class DatePoll < Poll
- def sort_data fields
- datefields = fields.collect{|field|
- field == "timestamp" || field == "name" ? field : Date.parse(field)
+ def get_id(columntitle)
+ if @data.include?(columntitle)
+ return Digest::SHA2.hexdigest("#{columntitle}#{@data[columntitle]}" + columntitle.to_s)
+ else
+ raise("no such column found: #{columntitle}")
+ end
+ end
+ def get_title(columnid)
+ @data.each_key{|k| return k if get_id(k) == columnid}
+ raise("no such id found: #{columnid}")
+ end
+ def each_columntitle
+ @data.sort.each{|k,v|
+ yield(k)
}
- super datefields
- end
-
- # 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|
- Time.parse(curdate.strftime(big + small))
- }.uniq.each{|day|
- ret[day.strftime(big)] += 1
+ end
+ def each_columnid
+ @data.sort.each{|k,v|
+ yield(get_id(k))
+ }
+ end
+ def each_column
+ @data.sort.each{|k,v|
+ yield(get_id(k),k)
}
- ret.sort
end
- def head_to_html(config = false, activecolumn = nil)
+ # returns internal representation of cgi-string
+ def cgi_to_id(field)
+ Date.parse(field)
+ end
+
+ # returns true if deletion sucessfull
+ def delete_column(columnid)
+ raise("this should not be called currently")
+ end
+
+ # columnid should be never used as changing title is not usefull here
+ # returns parsed title
+ def edit_column(columnid, newtitle, cgi)
+ parsed_date = Date.parse("#{cgi["add_remove_column_month"]}-#{newtitle}")
+ if @data.include?(parsed_date)
+ @data.delete(newtitle)
+ else
+ @data[parsed_date] = ""
+ end
+ parsed_date.to_s
+ end
+
+ def to_html(config = false,activecolumn = nil)
+ # 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)
+ @data.keys.collect{|curdate|
+ Time.parse(curdate.strftime(big + small))
+ }.uniq.each{|day|
+ ret[day.strftime(big)] += 1
+ }
+ ret.sort
+ end
ret = "<tr><td></td>"
head_count("%Y-%m","-%d %H:%M%Z").each{|title,count|
year, month = title.split("-").collect{|e| e.to_i}
@@ -37,13 +82,13 @@ class DatePoll < Poll
}
ret += "</tr><tr><th><a href='?sort=name'>Name</a></th>"
- @head.keys.sort.each{|curdate|
+ @data.keys.sort.each{|curdate|
ret += "<th><a title='#{curdate}' href='?sort=#{curdate.to_s}'>#{curdate.strftime("%a, %d")}</a></th>\n"
}
ret += "<th><a href='.'>Last Edit</a></th>\n</tr>\n"
ret
end
-
+
def edit_column_htmlform(activecolumn)
if $cgi.include?("add_remove_column_month")
if $cgi.params["add_remove_column_month"].size == 1
@@ -93,9 +138,13 @@ END
d = startdate
while (d.month == startdate.month) do
klasse = "notchoosen"
+ type = "new_columnname"
klasse = "disabled" if d < Date.today
- klasse = "choosen" if @head.include?(d)
- ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='new_columnname' value='#{d.day}' /></td>\n"
+ if @data.include?(d)
+ klasse = "choosen"
+ type = "deletecolumn"
+ end
+ ret += "<td class='calendarday'><input class='#{klasse}' type='submit' name='#{type}' value='#{d.day}' /></td>\n"
ret += "</tr><tr>\n" if d.wday == 0
d = d.next
end
@@ -108,20 +157,4 @@ END
END
ret
end
-
- def parsecolumntitle(title)
- Date.parse("#{$cgi["add_remove_column_month"]}-#{title}")
- end
-
- def edit_column(newtitle, description, oldtitle = nil)
- parsed_date = parsecolumntitle(newtitle)
- if @head.include?(parsed_date)
- delete_column(newtitle)
- else
- @head[parsed_date] = ""
- store "Column #{parsed_date} added"
- end
- true
- end
end
-