[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
calendar patch 0.2
From: |
boud |
Subject: |
calendar patch 0.2 |
Date: |
Tue, 6 Mar 2007 02:53:57 +0100 (CET) |
hi samizdat-devel,
Here's calendar patch 0.2, an update for bugs in calendar patch 0.1
related to what happens if someone edits a date focus. In version 0.2,
the new link when adding a calendar item is made correctly (i think)
and the content of the date focus is appended with a link to the new
article.
cheers
boud
--- /tmp/tmp_snapshot/samizdat/lib/samizdat/engine/message.rb 2007-02-18
18:24:29.000000000 +0100
+++ /usr/lib/ruby/1.8/samizdat/engine/message.rb 2007-02-25
01:37:24.000000000 +0100
@@ -554,7 +567,8 @@
]
# select focus for new message
- form.push(*t.focus_fields(nil, nil, false)) if
+# form.push(*t.focus_fields(nil, nil, false)) if
+ form.push(*t.focus_fields(nil, nil, false, false)) if
@session.access('vote') and @parent.nil?
# advanced parameters
--- /tmp/tmp_snapshot/samizdat/lib/samizdat/engine/template.rb 2007-02-18
18:51:31.000000000 +0100
+++ /usr/lib/ruby/1.8/samizdat/engine/template.rb 2007-02-24
01:28:58.000000000 +0100
@@ -32,6 +32,31 @@
# document navigation links (made, start, next, ...)
attr_accessor :link
+
+ # some calendar constants
+ days_s = [ [0, _("SELECT DAY")] ]
+ for i in 1..31
+ days_s += [ [i, i.to_s] ]
+ end
+ Days_s = days_s
+
+ months_s = []
+ Months_inv = Date::MONTHS.invert
+ for i in 1..12
+# months_s += [ [i, Months_inv[i] ] ] # needs l10n
+ months_s += [ [i, i.to_s ] ]
+ end
+ Months_s = months_s
+
+ years_s = []
+ thisyear= Time.now.year
+
+ for i in 0..3 # default 4 years' calendar
+ years_s += [ [thisyear+i, (thisyear+i).to_s] ]
+ end
+ Years_s = years_s
+
+
# HTML header, title, and style settings
#
def head(title='', options={})
@@ -276,6 +301,14 @@
fbox += box(nil,
'<p><a title="'+_('Click to relate this resource to another focus')+%{"
href="resource.rb?id=#{related.id}&focus=select">}+_('Add another focus')+'</a></p>'
)
+ if config['calendar']
+ fbox += box(nil,
+ '<p><a title="'+
+ _('Click to put this resource in the calendar')+
+
%{"href="resource.rb?id=#{related.id}&focus=select&calendar=start">}+
+ _('Put this in the calendar')+ '</a></p>'
+ )
+ end # if config['calendar']
end
fbox
end
@@ -291,7 +324,18 @@
# form fields for vote on focus rating
#
- def focus_fields(id, focus, advanced=('advanced' == @session.cookie('ui')))
+ def focus_fields(id, focus, calendar, advanced=('advanced' ==
@session.cookie('ui')))
+ if 'start' == calendar
+ fields =
+ [ [:hidden, 'id', id],
+ [:label, 'calendar_date', _('Select the date at which this event is
planned for')],
+ [:select, 'cal_year', Years_s, Time.now.year],
+ [:select, 'cal_month', Months_s, Time.now.month],
+ [:select, 'cal_day', Days_s, 0], # default day is invalid day
+ [:hidden, 'rating', 1],
+ [:hidden, 'calendar', 'send'],
+ ]
+ else
focuses = Focus.collect_focuses {|f,|
[f, Resource.new(@session, f).render(:title)]
}
@@ -318,6 +362,7 @@
else
fields.push([:hidden, 'rating', 1])
end
+ end #end if calendar
end
# transform date to a standard string representation
--- /tmp/tmp_snapshot/samizdat/cgi-bin/resource.rb 2007-02-02
22:57:24.000000000 +0100
+++ /usr/share/samizdat/cgi-bin/resource.rb 2007-03-05 01:24:31.000000000
+0100
@@ -11,6 +11,7 @@
# vim: et sw=2 sts=2 ts=8 tw=0
require 'samizdat/engine'
+#require 'date'
# messages that are related to this focus
#
@@ -31,6 +32,25 @@
ORDER BY ?date DESC}, limit_page, limit_page * skip
).collect {|m,| m } # unwrap DBI::Row
end
+
+ if config['calendar'] and id.to_i == config['calendar']
+ # TODO rewrite this using .collect instead of .each
+ list_titles = []
+ today=Time.now.strftime("%Y-%m-%d")
+ list.each do |msg|
+ m_title, = rdf.select_one %{
+SELECT ?title
+WHERE (dc::title #{msg} ?title)}
+ if m_title >= today # ignore old events
+ list_titles += [[m_title, msg]] # add a pair
+ end
+ end
+ list_titles.sort! { |a,b| a[0] <=> b[0] }
+
+
+ list = list_titles.collect { |pair| pair[1] }
+
+ end
list.collect {|msg| yield msg }
end
@@ -81,26 +101,126 @@
body = session.has_key?('skip')? r[:messages] : r.to_s
# vote on focus rating
- if session.has_key?('focus') or session.has_key?('focus_id')
+ if session.has_key?('focus') or session.has_key?('focus_id') or
+ (session.has_key?('calendar') and config['calendar'])
session.access('vote') or raise AuthError,
sprintf(_('Your current access level (%s) does not allow to vote'),
_(session.role))
- focus, focus_id, rating = session.params %w[focus focus_id rating]
+ # focus, focus_id, rating = session.params %w[focus focus_id rating]
+ focus, focus_id, rating, calendar, cal_year, cal_month, cal_day, creator, format, description =
+ session.params %w[focus focus_id rating calendar cal_year cal_month cal_day creator format description]
+
focus = nil if 'select' == focus
+
+ # julian date if date is valid, otherwise set to nil
+ jd= Date::valid_civil?(cal_year.to_i, cal_month.to_i, cal_day.to_i)
+
+ if 'send' == calendar and config['calendar']
+ if jd
+ dd = cal_day.to_s
+ dd = "0" + dd if cal_day.to_i < 10
+ mm = cal_month.to_s
+ mm = "0" + mm if cal_month.to_i < 10
+
+ focus_title= cal_year.to_s + "-" + mm + "-" + dd
+
+ # find out if a message for this date already exists
+ db.transaction do |db|
+ focus_id, = db.select_one 'SELECT id FROM Message
+ WHERE title = ? AND version_of is NULL', focus_title
+ end
+ if focus_id
+ # do nothing
+ else
+ # calendar focus is created as open for editing by members
+ if config['locale']['languages'][0]
+ lang= config['locale']['languages'][0]
+ else
+ lang= NULL
+ end
+
+ message = PublishMessage.new(session)
+
+ db.transaction do |db|
+ focus_id, = rdf.assert( %{
+INSERT ?msg
+WHERE (dc::creator ?msg :creator)
+ (dc::title ?msg :title)
+ (dc::language ?msg :language)
+ (dc::format ?msg :format)
+ (dc::description ?msg :desc)
+ (s::content ?msg :content)
+ (s::openForAll ?msg :open)
+ (s::inReplyTo ?msg :parent)
+},
+ {
+ :creator => creator,
+ :title => focus_title,
+ :language => lang,
+ :format => 'text/textile',
+ :desc => description,
+ :content => ' ',
+ :open => true,
+ :parent => nil
+ } )
+ end # db.transaction
+ end # if focus_id
+
+ # add link (editing is open, so this is not hardwiring)
+ db.transaction do |db|
+ f_content, = db.select_one 'SELECT content FROM Message
+ WHERE id = ? ', focus_id
+ m_title, = db.select_one 'SELECT title FROM Message
+ WHERE id = ? ', id
+ db.do 'UPDATE Message SET content = ? WHERE id = ? ',
+ f_content + %{\n"} + m_title + %{":/} + id.to_s + %{\n},
+ focus_id
+ db.do 'UPDATE Message SET format = ? WHERE id = ? ',
+ "text/textile", focus_id
+ db.do 'UPDATE Message SET html_full = NULL WHERE id = ? ',
+ focus_id
+ db.do 'UPDATE Message SET html_short = NULL WHERE id = ? ',
+ focus_id
+ MessageContent.regenerate_html(focus_id)
+ end # db.transaction do |db|
+
+ calendar_superfocus = config['calendar']
+ else # invalid date - try again
+ calendar = 'start'
+ end
+ end # if 'send' == calendar
+
+
if focus_id = Resource.validate_id(focus_id)
# manual entry overrides selection
focus = focus_id
end
+ focus_id = focus # needed for Resource.new
+# old_id = id # needed for session.redirect
focus = Focus.new(session, focus, resource) if focus
if focus.kind_of?(Focus) and rating # commit vote
# rating is validated by Focus#rating=
db.transaction {|db| focus.rating = rating }
- session.redirect(id.to_s)
+
+ if Resource.validate_id(calendar_superfocus)
+ focus_r = Resource.new(session, focus_id) # focus as Resource object
+ calendar_superfocus = Focus.new(session, calendar_superfocus, focus_r)
+ if calendar_superfocus.kind_of?(Focus)
+ db.transaction {|db| calendar_superfocus.rating = rating }
+ end
+ session.redirect(focus_id.to_s) # otherwise session may be confused
+ else
+ session.redirect(id.to_s)
+ end
+
+
+# session.redirect(old_id.to_s)
else # display vote form
vote_form = t.form( 'resource.rb',
- *t.focus_fields(id, focus) +
+# *t.focus_fields(id, focus) +
+ *t.focus_fields(id, focus, calendar) +
[ [:br], [:submit, nil, _('Submit')] ]
)
next t.page(_('Vote') + ': ' + r[:head],
- calendar patch 0.2,
boud <=