Browse Source

Improved calendar descriptions

Maarten van den Berg 6 years ago
parent
commit
5f2e656ec8
1 changed files with 43 additions and 6 deletions
  1. 43 6
      app/controllers/people_controller.rb

+ 43 - 6
app/controllers/people_controller.rb

@@ -92,12 +92,44 @@ class PeopleController < ApplicationController
92 92
   # GET /c/:calendar_token
93 93
   def calendar
94 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 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 133
       orgi = a.organizer_names
102 134
       orgi_names = orgi.join ', '
103 135
       orgi_line = case orgi.count
@@ -108,6 +140,7 @@ class PeopleController < ApplicationController
108 140
 
109 141
       description_items << orgi_line
110 142
 
143
+      # Subgroups
111 144
       if a.subgroups.any?
112 145
         if p.subgroup
113 146
           description_items << "#{I18n.t 'activities.participant.yoursubgroup'}: #{p.subgroup}"
@@ -118,9 +151,12 @@ class PeopleController < ApplicationController
118 151
 
119 152
       end
120 153
 
154
+      # URL
155
+      a_url = group_activity_url a.group, a
156
+      description_items << a_url
157
+
121 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 160
         e.dtstart = a.start
125 161
         e.dtend = a.end
126 162
 
@@ -131,10 +167,11 @@ class PeopleController < ApplicationController
131 167
 
132 168
         e.description = description_items.join "\n"
133 169
 
134
-        e.url = group_activity_url a.group, a
170
+        e.url = a_url
135 171
       end
136 172
     end
137 173
 
174
+    cal.publish
138 175
     render plain: cal.to_ical
139 176
   end
140 177