Browse Source

Make 'no response action' configurable per activity

Maarten van den Berg 7 years ago
parent
commit
5dc36f7b77

+ 1 - 1
app/controllers/activities_controller.rb

@@ -317,7 +317,7 @@ class ActivitiesController < ApplicationController
317 317
 
318 318
     # Never trust parameters from the scary internet, only allow the white list through.
319 319
     def activity_params
320
-      params.require(:activity).permit(:name, :description, :location, :start, :end, :deadline, :reminder_at, :subgroup_division_enabled)
320
+      params.require(:activity).permit(:name, :description, :location, :start, :end, :deadline, :reminder_at, :subgroup_division_enabled, :no_response_action)
321 321
     end
322 322
 
323 323
     def subgroup_params

+ 7 - 1
app/mailers/participant_mailer.rb

@@ -3,7 +3,13 @@ class ParticipantMailer < ApplicationMailer
3 3
     @person = person
4 4
     @activity = activity
5 5
 
6
-    subject = I18n.t('activities.emails.attendance_reminder.subject', activity: @activity.name)
6
+    if activity.no_response_action # is true
7
+      key = 'activities.emails.attendance_reminder.subject_present'
8
+    else
9
+      key = 'activities.emails.attendance_reminder.subject_absent'
10
+    end
11
+
12
+    subject = I18n.t(key, activity: @activity.name)
7 13
 
8 14
     mail(to: @person.email, subject: subject)
9 15
   end

+ 6 - 0
app/models/activity.rb

@@ -46,6 +46,12 @@ class Activity < ApplicationRecord
46 46
   # @!attribute subgroup_division_done
47 47
   #   @return [Boolean]
48 48
   #     whether subgroup division has been performed.
49
+  #
50
+  # @!attribute no_response_action
51
+  #   @return [Boolean]
52
+  #     what action to take when a participant has not responded and the
53
+  #     reminder is being sent. True to set the participant to attending, false
54
+  #     to set to absent.
49 55
 
50 56
   belongs_to :group
51 57
 

+ 1 - 1
app/models/participant.rb

@@ -61,7 +61,7 @@ class Participant < ApplicationRecord
61 61
   def send_reminder
62 62
     return unless self.attending.nil?
63 63
 
64
-    self.attending = true
64
+    self.attending = self.activity.no_response_action
65 65
     notes = self.notes || ""
66 66
     notes << '[auto]'
67 67
     self.notes = notes

+ 13 - 3
app/views/activities/_form.html.erb

@@ -40,15 +40,25 @@
40 40
       <%= f.label :deadline %>
41 41
       <%= f.datetime_field :deadline, class: 'form-control' %>
42 42
     </div>
43
-    <div class="form-group">
44
-      <%= f.label :reminder_at %>
45
-      <%= f.datetime_field :reminder_at, class: 'form-control' %>
43
+    <div class="form-group row">
44
+      <div class="col-md-6">
45
+        <%= f.label :reminder_at %>
46
+        <%= f.datetime_field :reminder_at, class: 'form-control' %>
47
+      </div>
48
+      <div class="col-md-6">
49
+        <%= f.label :no_response_action %>
50
+        <%= f.select(:no_response_action, options_for_select([
51
+          [I18n.t('activities.no_response_action.auto_present'), 'true'],
52
+          [I18n.t('activities.no_response_action.auto_absent'), 'false']
53
+        ], selected: @activity.no_response_action.to_s), {}, {class: 'form-control'}) %>
54
+      </div>
46 55
     </div>
47 56
     <div class="form-group">
48 57
       <div class="check-box">
49 58
         <%= f.check_box(:subgroup_division_enabled) %>
50 59
         <%= t 'activerecord.attributes.activity.subgroup_division_enabled' %>
51 60
       </div>
61
+    </div>
52 62
     <div class="form-group btn-group">
53 63
       <%= f.submit class: 'btn btn-primary' %>
54 64
       <% unless activity.new_record? %>

+ 4 - 1
app/views/participant_mailer/attendance_reminder.html.haml

@@ -1,6 +1,9 @@
1 1
 %p= t 'authentication.emails.greeting', name: @person.first_name
2 2
 
3
-%p= t 'activities.emails.attendance_reminder.havenot_responded', activity: @activity.name
3
+- if @activity.no_response_action
4
+  %p= t 'activities.emails.attendance_reminder.set_to_present', activity: @activity.name
5
+- else
6
+  %p= t 'activities.emails.attendance_reminder.set_to_absent', activity: @activity.name
4 7
 
5 8
 %p= t 'activities.emails.attendance_reminder.if_cannot', deadline: l(@activity.deadline, format: :short)
6 9
 

+ 5 - 1
app/views/participant_mailer/attendance_reminder.text.erb

@@ -1,6 +1,10 @@
1 1
 <%= t 'authentication.emails.greeting', name: @person.first_name %>
2 2
 
3
-<%= t 'activities.emails.attendance_reminder.havenot_responded', activity: @activity.name %>
3
+<% if @activity.no_response_action %>
4
+<%= t 'activities.emails.attendance_reminder.set_to_present', activity: @activity.name %>
5
+<% else %>
6
+<%= t 'activities.emails.attendance_reminder.set_to_absent', activity: @activity.name %>
7
+<% end %>
4 8
 
5 9
 <%= t 'activities.emails.attendance_reminder.if_cannot', deadline: l(@activity.deadline, format: :short) %>
6 10
 

+ 1 - 0
config/locales/aardbei_en.yml

@@ -83,3 +83,4 @@ en:
83 83
         end: "End"
84 84
         description: "Description"
85 85
         deadline: "Deadline"
86
+        no_response_action: "Action when no response"

+ 2 - 1
config/locales/activities/en.yml

@@ -75,7 +75,8 @@ en:
75 75
         - "Cheers,"
76 76
       attendance_reminder:
77 77
         subject: "You are now listed as 'attending' for %{activity}"
78
-        havenot_responded: "You have not yet indicated if you will be at %{activity}. Because we assume that you're present if you don't respond, your response has been set to 'attending'."
78
+        set_to_present: "You have not yet indicated if you will be at %{activity}. Because we assume that you're present if you don't respond, your response has been set to 'attending'."
79
+        set_to_absent: "You have not yet indicated if you will be at %{activity}. This activity is set to assume to set you to absent if you don't respond, so your response has been set to 'absent'."
79 80
         if_cannot: "If you wish to change this, you can change your response until %{deadline} using the following link:"
80 81
 
81 82
       subgroup_notification:

+ 9 - 3
config/locales/activities/nl.yml

@@ -67,6 +67,10 @@ nl:
67 67
       description: "Omschrijving"
68 68
       deadline: "Deadline"
69 69
 
70
+    no_response_action:
71
+      auto_present: 'Automatisch aanmelden'
72
+      auto_absent: 'Automatisch afmelden'
73
+
70 74
     emails:
71 75
       open_activity: "Activiteit openen"
72 76
       open_settings: "Instellingen"
@@ -81,9 +85,11 @@ nl:
81 85
         - "Doi,"
82 86
         - "Talla,"
83 87
       attendance_reminder:
84
-        subject: "Je bent automatisch aangemeld voor %{activity}"
85
-        havenot_responded: "Je hebt nog niet aangegeven of je bij %{activity} kunt zijn. Omdat we ervan uitgaan dat je er bent als je niks aangeeft, is je reactie automatisch op 'aanwezig' gezet."
86
-        if_cannot: "Als je toch niet aanwezig kunt zijn, kan je dit tot %{deadline} aangeven via de volgende link:"
88
+        subject_present: "Je bent automatisch aangemeld voor %{activity}"
89
+        subject_absent: "Je bent automatisch afgemeld voor %{activity}"
90
+        set_to_present: "Je hebt nog niet aangegeven of je bij %{activity} kunt zijn. De organisatoreen van deze activiteit gaan ervan uit dat je er wel bent als je niets aangeeft,  dus je reactie is op 'aanwezig' gezet."
91
+        set_to_absent: "Je hebt nog niet aangegeven of je bij %{activity} kan zijn. De organisatoren van deze activiteit gaan ervan uit dat je er niet bent als je niets aangeeft, dus je reactie is op 'afwezig' gezet."
92
+        if_cannot: "Als je dit nog wilt veranderen kan je dit tot %{deadline} aangeven via de volgende link:"
87 93
 
88 94
       subgroup_notification:
89 95
         subject: "Je bent ingedeeld in subgroep %{subgroup} voor %{activity}"

+ 1 - 0
config/locales/translation_nl.yml

@@ -48,6 +48,7 @@ nl:
48 48
         subgroups: :activerecord.models.subgroup.other
49 49
         subgroup_division_enabled: Subgroepen indelen
50 50
         subgroup_division_done: Subgroepen ingedeeld
51
+        no_response_action: Actie bij geen reactie
51 52
 
52 53
       group:
53 54
         activities: Activiteiten  #g

+ 5 - 0
db/migrate/20180206181016_add_no_response_action_to_activities.rb

@@ -0,0 +1,5 @@
1
+class AddNoResponseActionToActivities < ActiveRecord::Migration[5.0]
2
+  def change
3
+    add_column :activities, :no_response_action, :boolean, default: true
4
+  end
5
+end

+ 4 - 3
db/schema.rb

@@ -10,7 +10,7 @@
10 10
 #
11 11
 # It's strongly recommended that you check this file into your version control system.
12 12
 
13
-ActiveRecord::Schema.define(version: 20171023080215) do
13
+ActiveRecord::Schema.define(version: 20180206181016) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "name"
@@ -20,12 +20,13 @@ ActiveRecord::Schema.define(version: 20171023080215) do
20 20
     t.datetime "end"
21 21
     t.datetime "deadline"
22 22
     t.integer  "group_id"
23
-    t.datetime "created_at",                null: false
24
-    t.datetime "updated_at",                null: false
23
+    t.datetime "created_at",                               null: false
24
+    t.datetime "updated_at",                               null: false
25 25
     t.datetime "reminder_at"
26 26
     t.boolean  "reminder_done"
27 27
     t.boolean  "subgroup_division_enabled"
28 28
     t.boolean  "subgroup_division_done"
29
+    t.boolean  "no_response_action",        default: true
29 30
     t.index ["group_id"], name: "index_activities_on_group_id"
30 31
   end
31 32