aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-23 15:58:49 +0100
committerBenjamin Kellermann <Benjamin.Kellermann@gmx.de>2009-11-23 15:58:49 +0100
commit19409f822c901b4935b07493d741d479fbc119a0 (patch)
treec971ca940ebf21d0fe103a1be9276e88f85396f3
parentfc936f76f65db94469959883c8ef2926ff0e779b (diff)
started to implement undo, added flatten option
-rwxr-xr-xedit_columns.rb57
-rwxr-xr-xhistory.rb7
-rw-r--r--log.rb23
-rw-r--r--poll.rb8
-rw-r--r--pollhead.rb3
-rw-r--r--timepollhead.rb14
6 files changed, 79 insertions, 33 deletions
diff --git a/edit_columns.rb b/edit_columns.rb
index 0b58fcc..c449928 100755
--- a/edit_columns.rb
+++ b/edit_columns.rb
@@ -44,23 +44,28 @@ end
acusers = {}
-if $cgi.include?("revision")
- REVISION=$cgi["revision"].to_i
- table = YAML::load(VCS.cat(REVISION, "data.yaml"))
+revbeforeedit = VCS.revno
+
+if $cgi.include?("undo_revision") && $cgi["undo_revision"].to_i < revbeforeedit
+ undorevision = $cgi["undo_revision"].to_i
+ table = YAML::load(VCS.cat(undorevision, "data.yaml"))
+ table.store("Reverted Poll to version #{undorevision}")
else
table = YAML::load_file("data.yaml")
+end
- if $cgi.include?("add_participant")
- if $cgi.include?("delete_participant")
- table.delete($cgi["olduser"])
- else
- table.add_participant($cgi["olduser"],$cgi["add_participant"],{})
- end
- end
- table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname")
- table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn")
+# TODO: move to own tab
+#if $cgi.include?("add_participant")
+# if $cgi.include?("delete_participant")
+# table.delete($cgi["olduser"])
+# else
+# table.add_participant($cgi["olduser"],$cgi["add_participant"],{})
+# end
+#end
+table.edit_column($cgi["columnid"],$cgi["new_columnname"],$cgi) if $cgi.include?("new_columnname")
+table.delete_column($cgi["deletecolumn"]) if $cgi.include?("deletecolumn")
-end
+revno = VCS.revno
$html = HTML.new("dudle - #{table.name} - Edit Columns")
$html.header["Cache-Control"] = "no-cache"
@@ -77,13 +82,33 @@ $html << <<TABLE
TABLE
# ADD/REMOVE COLUMN
+$html << table.edit_column_htmlform($cgi["editcolumn"],revno)
+
+h = VCS.history.flatten
+
+#undo = h.size -1
+
+#h.collect{|e|
+#
+#}
+
+
+
+# This Revision: #{revno}<br />
+# Hidden undo Revision: #{undorevision -1}<br />
+# Last Action: #{h[0]["commit message"]}
+
$html << <<ADD_EDIT
- <div id='edit_column'>
- #{table.edit_column_htmlform($cgi["editcolumn"])}
+<form method='post' action=''>
+ <div>
+ <input type='submit' value='Undo' />
+ <input type='hidden' name='undo_revision' value='#{-1}' />
</div>
+</form>
+#{h[216..234].to_html(220)}
ADD_EDIT
-$html << "</body>"
+$html << "</div></body>"
$html.out($cgi)
end
diff --git a/history.rb b/history.rb
index 43c5264..46ab5ec 100755
--- a/history.rb
+++ b/history.rb
@@ -33,13 +33,12 @@ require "poll"
load "config.rb"
Dir.chdir(olddir)
-maxrev = VCS.revno
if $cgi.include?("revision")
revno=$cgi["revision"].to_i
versiontitle = "Poll of Version #{revno}"
table = YAML::load(VCS.cat(revno, "data.yaml"))
else
- revno = maxrev
+ revno = VCS.revno
versiontitle = "Current Poll"
table = YAML::load_file("data.yaml")
end
@@ -65,8 +64,8 @@ $html << table.to_html("",false)
$html << "<h2>History</h2>"
$html << "<div id='history'>"
historyselect = $cgi.include?("history") ? $cgi["history"] : nil
-$html << table.history_selectform(revno == maxrev ? nil : revno, historyselect)
-$html << table.history_to_html(maxrev, revno, historyselect)
+$html << table.history_selectform($cgi.include?("revision") ? nil : revno, historyselect)
+$html << table.history_to_html(revno, historyselect)
$html << "</div>"
$html << "</div></body>"
diff --git a/log.rb b/log.rb
index fe0d4f5..ca08b9c 100644
--- a/log.rb
+++ b/log.rb
@@ -78,10 +78,10 @@ class Log
@log << LogEntry.new(revision,timestamp,comment)
@log.sort!{|a,b| a.rev <=> b.rev}
end
- def to_html(maxrev, middlerevision)
+ def to_html(notlinkrevision)
ret = "<table><tr><th>Version</th><th>Date</th><th>Comment</th></tr>"
- self[((middlerevision-5)..(middlerevision+5))].each do |l|
- ret += l.to_html(middlerevision != l.rev)
+ self.each do |l|
+ ret += l.to_html(notlinkrevision != l.rev)
end
ret += "</table>"
ret
@@ -95,6 +95,23 @@ class Log
def comment_matches(regex)
Log.new(@log.collect{|e| e if e.comment =~ regex}.compact)
end
+ def flatten
+ h = []
+ minrev = min.rev
+ rev = max.rev
+ while rev > minrev
+ elem = self[rev]
+ prevrev = elem.comment.scan(/^Reverted Poll to revision (\d*)$/).flatten[0]
+ if prevrev
+ rev = prevrev.to_i
+ else
+ h << elem
+ rev += -1
+ end
+ end
+ h.sort!{|a,b| a.rev <=> b.rev}
+ Log.new(h)
+ end
end
if __FILE__ == $0
diff --git a/poll.rb b/poll.rb
index 66e2d5f..cf47f20 100644
--- a/poll.rb
+++ b/poll.rb
@@ -247,7 +247,7 @@ FORM
ret
end
- def history_to_html(maxrev, middlerevision,only)
+ def history_to_html(middlerevision,only)
log = VCS.history
if only
case only
@@ -262,7 +262,7 @@ FORM
end
log = log.comment_matches(match)
end
- log[((middlerevision-5)..(middlerevision+5))].to_html(maxrev, middlerevision)
+ log[((middlerevision-5)..(middlerevision+5))].to_html(middlerevision)
end
def add_participant(olduser, name, agreed)
@@ -328,8 +328,8 @@ FORM
store "Column #{parsedtitle} edited" if parsedtitle
end
- def edit_column_htmlform(activecolumn)
- @head.edit_column_htmlform(activecolumn)
+ def edit_column_htmlform(activecolumn, revision)
+ @head.edit_column_htmlform(activecolumn, revision)
end
end
diff --git a/pollhead.rb b/pollhead.rb
index f062b13..d3aa14c 100644
--- a/pollhead.rb
+++ b/pollhead.rb
@@ -105,7 +105,7 @@ EDITDELETE
ret
end
- def edit_column_htmlform(activecolumn)
+ def edit_column_htmlform(activecolumn, revision)
if activecolumn != ""
title = activecolumn
description = @data[title]
@@ -119,6 +119,7 @@ EDITDELETE
<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='undo_revision' value='#{revision}' />
#{hiddeninput}
<input type='submit' value='Add/Edit Column' />
</div>
diff --git a/timepollhead.rb b/timepollhead.rb
index 25af201..37202af 100644
--- a/timepollhead.rb
+++ b/timepollhead.rb
@@ -191,7 +191,7 @@ class TimePollHead
ret
end
- def edit_column_htmlform(activecolumn)
+ def edit_column_htmlform(activecolumn, revision)
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")
@@ -215,24 +215,25 @@ class TimePollHead
startdate = Date.parse("#{Date.today.year}-#{Date.today.month}-1")
end
ret = <<END
-<table><tr><td style="vertical-align:top">
+<table summary='edit column'><tr><td style="vertical-align:top">
<table class='calendarday' summary='The day to vote for.'><tr>
END
- def navi val,curmonth
+ def navi val,curmonth,revision
return <<END
<th style='padding:0px'>
<form method='post' action=''>
<div>
<input class='navigation' type='submit' name='add_remove_column_month' value='#{val}' />
<input type='hidden' name='add_remove_column_month' value='#{curmonth.strftime("%Y-%m")}' />
+ <input type='hidden' name='undo_revision' value='#{revision}' />
</div>
</form>
</th>
END
end
- [YEARBACK,MONTHBACK].each{|val| ret += navi(val,startdate)}
+ [YEARBACK,MONTHBACK].each{|val| ret += navi(val,startdate,revision)}
ret += "<th colspan='3'>#{startdate.strftime("%b %Y")}</th>"
- [MONTHFORWARD, YEARFORWARD].each{|val| ret += navi(val,startdate)}
+ [MONTHFORWARD, YEARFORWARD].each{|val| ret += navi(val,startdate,revision)}
ret += "</tr><tr>\n"
@@ -258,6 +259,7 @@ END
<input class='#{klasse}' type='submit' value='#{d.day}' />
<input type='hidden' name='#{varname}' value='#{startdate.strftime("%Y-%m")}-#{d.day}' />
<input type='hidden' name='add_remove_column_month' value='#{startdate.strftime("%Y-%m")}' />
+ <input type='hidden' name='undo_revision' value='#{revision}' />
</div>
</form>
</td>
@@ -319,6 +321,7 @@ END
ret += <<END
<input title='#{timestamp}' class='#{klasse}' type='submit' name='columntime' value='#{timestamp.time_to_s}' />
<input type='hidden' name='add_remove_column_month' value='#{timestamp.date.strftime("%Y-%m")}' />
+ <input type='hidden' name='undo_revision' value='#{revision}' />
</div>
</form>
</td>
@@ -335,6 +338,7 @@ END
<div>
<input type='hidden' name='new_columnname' value='#{d.strftime("%Y-%m-%d")}' />
<input type='hidden' name='add_remove_column_month' value='#{d.strftime("%Y-%m")}' />
+ <input type='hidden' name='undo_revision' value='#{revision}' />
END
if @data.include?(TimeString.new(d,nil))
ret += "<input type='hidden' name='columnid' value='#{TimeString.new(d,nil).to_s}' />"