Sfoglia il codice sorgente

Add Settings and respect them

Maarten van den Berg 7 anni fa
parent
commit
d3c0a229e7

+ 14 - 0
app/controllers/dashboard_controller.rb

@@ -15,4 +15,18 @@ class DashboardController < ApplicationController
15 15
       .where(attending: nil)
16 16
       .paginate(page: params[:nrpage], per_page: 5)
17 17
   end
18
+
19
+  def settings
20
+    @person = current_person
21
+    @send_attendance_reminder = @person.send_attendance_reminder
22
+  end
23
+
24
+  def update_email_settings
25
+    p = current_person
26
+    p.send_attendance_reminder = params[:send_attendance_reminder]
27
+    p.save
28
+
29
+    flash_message(:success, t('settings.saved'))
30
+    redirect_to root_path
31
+  end
18 32
 end

+ 1 - 0
app/models/participant.rb

@@ -52,6 +52,7 @@ class Participant < ApplicationRecord
52 52
     self.notes = notes
53 53
     self.save
54 54
 
55
+    return unless self.person.send_attendance_reminder
55 56
     ParticipantMailer.attendance_reminder(self.person, self.activity).deliver_later
56 57
   end
57 58
 

+ 18 - 0
app/views/dashboard/settings.html.haml

@@ -0,0 +1,18 @@
1
+%h1
2
+  = t 'settings.settings'
3
+
4
+%h2
5
+  = t 'settings.email_settings'
6
+
7
+= form_tag(update_email_settings_path, method: "post", class: "form") do
8
+  .row
9
+    .col-md-4
10
+      -#= hidden_field_tag(:send_attendance_reminder, "off")
11
+      %label
12
+        = check_box_tag(:send_attendance_reminder, 'send_attendance_reminder', @send_attendance_reminder)
13
+        = t('settings.names.send_attendance_reminder')
14
+    .col-md-6
15
+      %p
16
+        %em= t 'settings.descriptions.send_attendance_reminder'
17
+
18
+  = submit_tag t('helpers.submit.submit', model: t('settings.settings'))

+ 1 - 0
app/views/people/show.html.erb

@@ -2,6 +2,7 @@
2 2
 <ul>
3 3
   <li><%= @person.birth_date %></li>
4 4
   <li><%= @person.email %></li>
5
+  <li>AttendanceReminder: <%= @person.send_attendance_reminder.to_i %></li>
5 6
 </ul>
6 7
 <%= link_to t(:edit), edit_person_path(@person) %> |
7 8
 <%= link_to t(:back), people_path %>

+ 3 - 2
app/views/shared/_menu.html.haml

@@ -35,8 +35,9 @@
35 35
 
36 36
       %ul.nav.navbar-nav.navbar-right
37 37
         %li
38
-          = link_to current_person do
39
-            = current_person.full_name
38
+          = link_to settings_path do
39
+            %i.fa.fa-cogs{'aria-hidden': true}
40
+            = t 'settings.settings'
40 41
         %li
41 42
           = link_to logout_path, confirm: "Really log out?", method: :delete do
42 43
             %i.fa.fa-sign-out{'aria-hidden': true}

+ 11 - 0
config/locales/settings_en.yml

@@ -0,0 +1,11 @@
1
+en:
2
+  settings:
3
+    settings: "Preferences"
4
+    saved: "Preferences saved!"
5
+    email_settings: "Email notifications"
6
+
7
+    names:
8
+      send_attendance_reminder: "Send notification on auto-respond"
9
+
10
+    descriptions:
11
+      send_attendance_reminder: "Receive an email if you haven't responded to an activity and your response is automatically set to 'attending'. When youreceive this reminder, you still have the possibility to change your response."

+ 11 - 0
config/locales/settings_nl.yml

@@ -0,0 +1,11 @@
1
+nl:
2
+  settings:
3
+    settings: "Instellingen"
4
+    saved: "Instellingen opgeslagen!"
5
+    email_settings: "Emailnotificaties"
6
+
7
+    names:
8
+      send_attendance_reminder: "Stuur een herinnering bij niet gereageerd"
9
+
10
+    descriptions:
11
+      send_attendance_reminder: "Ontvang een email als je niet hebt gereageerd op een activiteit en je reactie automatisch op 'aanwezig' wordt gezet. Wanneer je deze herinnering ontvangt is het nog mogelijk om je reactie aan te passen."

+ 2 - 0
config/routes.rb

@@ -2,6 +2,8 @@ Rails.application.routes.draw do
2 2
   get 'dashboard/home'
3 3
 
4 4
   root to: 'dashboard#home'
5
+  get 'settings', to: 'dashboard#settings', as: :settings
6
+  post 'settings', to: 'dashboard#update_email_settings', as: :update_email_settings
5 7
 
6 8
   get  'login', to: 'authentication#login_form', as: :login
7 9
   post 'login', to: 'authentication#login'

+ 5 - 0
db/migrate/20170917140643_add_send_attendance_reminder_to_person.rb

@@ -0,0 +1,5 @@
1
+class AddSendAttendanceReminderToPerson < ActiveRecord::Migration[5.0]
2
+  def change
3
+    add_column :people, :send_attendance_reminder, :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: 20170917093221) do
13
+ActiveRecord::Schema.define(version: 20170917140643) do
14 14
 
15 15
   create_table "activities", force: :cascade do |t|
16 16
     t.string   "name"
@@ -79,8 +79,9 @@ ActiveRecord::Schema.define(version: 20170917093221) do
79 79
     t.date     "birth_date"
80 80
     t.string   "email"
81 81
     t.boolean  "is_admin"
82
-    t.datetime "created_at", null: false
83
-    t.datetime "updated_at", null: false
82
+    t.datetime "created_at",                              null: false
83
+    t.datetime "updated_at",                              null: false
84
+    t.boolean  "send_attendance_reminder", default: true
84 85
     t.index ["email"], name: "index_people_on_email", unique: true
85 86
   end
86 87