浏览代码

Improved calendar descriptions

Maarten van den Berg 6 年之前
父节点
当前提交
5f2e656ec8
共有 1 个文件被更改,包括 43 次插入6 次删除
  1. 43 6
      app/controllers/people_controller.rb

+ 43 - 6
app/controllers/people_controller.rb

92
   # GET /c/:calendar_token
92
   # GET /c/:calendar_token
93
   def calendar
93
   def calendar
94
     cal = Icalendar::Calendar.new
94
     cal = Icalendar::Calendar.new
95
+    cal.x_wr_calname = 'Aardbei'
95
 
96
 
96
-    @person.participants.joins(:activity).where('"end" > ?', 3.months.ago).each do |p|
97
-      next if !p.attending && params[:skipcancel]
97
+    response.content_type = 'text/calendar'
98
 
98
 
99
+    selection = @person
100
+      .participants
101
+      .joins(:activity)
102
+      .where('"end" > ?', 3.months.ago)
103
+
104
+    if params[:skipcancel]
105
+      selection = selection
106
+        .where.not(attending: false)
107
+    end
108
+
109
+    selection.each do |p|
99
       a = p.activity
110
       a = p.activity
100
-      description_items = [a.description]
111
+
112
+      description_items = []
113
+      # The description consists of the following parts:
114
+      #  - The Participant's response and notes (if set),
115
+      #  - The Activity's description (if not empty),
116
+      #  - The names of the organizers,
117
+      #  - Subgroup information, if applicable,
118
+      #  - The URL.
119
+
120
+      # Response
121
+      yourresponse = "#{I18n.t 'activities.participant.yourresponse'}: #{p.human_attending}"
122
+
123
+      if p.notes.present?
124
+        yourresponse << " (#{p.notes})"
125
+      end
126
+
127
+      description_items << yourresponse
128
+
129
+      # Description
130
+      description_items << a.description if a.description.present?
131
+
132
+      # Organizers
101
       orgi = a.organizer_names
133
       orgi = a.organizer_names
102
       orgi_names = orgi.join ', '
134
       orgi_names = orgi.join ', '
103
       orgi_line = case orgi.count
135
       orgi_line = case orgi.count
108
 
140
 
109
       description_items << orgi_line
141
       description_items << orgi_line
110
 
142
 
143
+      # Subgroups
111
       if a.subgroups.any?
144
       if a.subgroups.any?
112
         if p.subgroup
145
         if p.subgroup
113
           description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}"
146
           description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}"
118
 
151
 
119
       end
152
       end
120
 
153
 
154
+      # URL
155
+      a_url = group_activity_url a.group, a
156
+      description_items << a_url
157
+
121
       cal.event do |e|
158
       cal.event do |e|
122
-        e.uid = group_activity_url a.group, a
123
-        e.ip_class = "PRIVATE"
159
+        e.uid = a_url
124
         e.dtstart = a.start
160
         e.dtstart = a.start
125
         e.dtend = a.end
161
         e.dtend = a.end
126
 
162
 
131
 
167
 
132
         e.description = description_items.join "\n"
168
         e.description = description_items.join "\n"
133
 
169
 
134
-        e.url = group_activity_url a.group, a
170
+        e.url = a_url
135
       end
171
       end
136
     end
172
     end
137
 
173
 
174
+    cal.publish
138
     render plain: cal.to_ical
175
     render plain: cal.to_ical
139
   end
176
   end
140
 
177