Maarten van den Berg 7 lat temu
rodzic
commit
ee74e154cf

+ 1 - 1
Gemfile.lock

@@ -243,4 +243,4 @@ DEPENDENCIES
243 243
   yard
244 244
 
245 245
 BUNDLED WITH
246
-   1.13.6
246
+   1.16.0

+ 76 - 4
app/controllers/activities_controller.rb

@@ -1,12 +1,24 @@
1 1
 class ActivitiesController < ApplicationController
2 2
   include GroupsHelper
3 3
   include ActivitiesHelper
4
-  before_action :set_activity_and_group, only: [:show, :edit, :update, :destroy, :presence, :change_organizer, :create_subgroup, :update_subgroup, :destroy_subgroup]
5
-  before_action :set_group,            except: [:show, :edit, :update, :destroy, :presence, :change_organizer, :create_subgroup, :update_subgroup, :destroy_subgroup]
4
+
5
+  has_activity_id = [
6
+    :show, :edit, :edit_subgroups, :update, :update_subgroups, :destroy,
7
+    :presence, :change_organizer, :create_subgroup, :update_subgroup,
8
+    :destroy_subgroup
9
+  ]
10
+  before_action :set_activity_and_group, only: has_activity_id
11
+  before_action :set_group,            except: has_activity_id
12
+
6 13
   before_action :set_subgroup, only: [:update_subgroup, :destroy_subgroup]
7 14
   before_action :require_membership!
8
-  before_action :require_leader!, only: [:mass_new, :mass_create, :new, :create, :destroy]
9
-  before_action :require_organizer!, only: [:edit, :update, :change_organizer, :create_subgroup, :update_subgroup, :destroy_subgroup]
15
+  before_action :require_leader!, only: [
16
+    :mass_new, :mass_create, :new, :create, :destroy
17
+  ]
18
+  before_action :require_organizer!, only: [
19
+    :edit, :update, :change_organizer, :create_subgroup, :update_subgroup,
20
+    :destroy_subgroup, :edit_subgroups, :update_subgroups
21
+  ]
10 22
 
11 23
   # GET /groups/:id/activities
12 24
   # GET /activities.json
@@ -54,6 +66,66 @@ class ActivitiesController < ApplicationController
54 66
     set_edit_parameters!
55 67
   end
56 68
 
69
+  # GET /activities/1/edit_subgroups
70
+  def edit_subgroups
71
+    @subgroups = @activity.subgroups.order(is_assignable: :desc, name: :asc)
72
+
73
+    if @subgroups.none?
74
+      flash_message(:error, I18n.t('activities.errors.cannot_subgroup_without_subgroups'))
75
+      redirect_to group_activity_edit(@group, @activity)
76
+    end
77
+
78
+    @subgroup_options = @subgroups.map { |sg| [sg.name, sg.id] }
79
+    @subgroup_options.prepend(['--', 'nil'])
80
+
81
+    @participants = @activity.participants
82
+      .joins(:person)
83
+      .where.not(attending: false)
84
+      .order(:subgroup_id)
85
+      .order('people.first_name', 'people.last_name')
86
+  end
87
+
88
+  # POST /activities/1/update_subgroups
89
+  def update_subgroups
90
+    # TODO:
91
+    # voor elke key in participant_subgroups
92
+    # pak participant, subgroup
93
+    # verifieer participant hoort bij activiteit
94
+    # verifieer subgroup hoort bij activiteit
95
+    # (impl dat editen mogen al gecheckt is, check of dit zo is!)
96
+    # doe veranderen
97
+    # knikker alles in een transactie want dan atomisch enzo cool en leuk
98
+    # S: on error netjes bleren maar wat er mis kan gaan is bijna alleen gekut dus meh
99
+    kappen = false
100
+
101
+    Participant.transaction do
102
+      params[:participant_subgroups].each do |k, v|
103
+        p = Participant.find_by id: k
104
+        sg = Subgroup.find_by id: v unless v == 'nil'
105
+
106
+        if !p || p.activity != @activity || (!sg && v != 'nil') || (sg && sg.activity != @activity)
107
+          flash_message(:danger, I18n.t(:somethingbroke))
108
+          redirect_to group_activity_edit_subgroups_path(@group, @activity)
109
+          kappen = true
110
+          raise ActiveRecord::Rollback
111
+        end
112
+
113
+        if v != 'nil'
114
+          p.subgroup = sg
115
+        else
116
+          p.subgroup = nil
117
+        end
118
+
119
+        p.save
120
+      end
121
+    end
122
+
123
+    unless kappen
124
+      flash_message(:success, I18n.t('activities.subgroups.edited'))
125
+      redirect_to edit_group_activity_path(@group, @activity)
126
+    end
127
+  end
128
+
57 129
   # Shared lookups for rendering the edit-view
58 130
   def set_edit_parameters!
59 131
     @non_organizers = @activity.participants.where(is_organizer: [false, nil])

+ 12 - 0
app/models/participant.rb

@@ -25,6 +25,18 @@ class Participant < ApplicationRecord
25 25
       message: I18n.t('activities.errors.already_in')
26 26
     }
27 27
 
28
+  HUMAN_ATTENDING = {
29
+    true => I18n.t('activities.state.present'),
30
+    false => I18n.t('activities.state.absent'),
31
+    nil => I18n.t('activities.state.unknown')
32
+  }
33
+
34
+  # @return [String]
35
+  #   the name for the Participant's current state in the current locale.
36
+  def human_attending
37
+    HUMAN_ATTENDING[self.attending]
38
+  end
39
+
28 40
   # TODO: Move to a more appropriate place
29 41
   # @return [String]
30 42
   #   the class for a row containing this activity.

+ 5 - 0
app/views/activities/edit.html.haml

@@ -98,6 +98,11 @@
98 98
               = link_to group_activity_destroy_subgroup_path(@group, @activity, sg.id), method: :delete, class: 'btn btn-danger btn-xs' do
99 99
                 %i.fa.fa-trash
100 100
 
101
+      = link_to(group_activity_edit_subgroups_path(@group, @activity), class: 'btn btn-default') do
102
+        %i.fa.fa-edit
103
+        = t 'activities.subgroups.edit'
104
+
105
+
101 106
 .btn-group
102 107
   = link_to t(:back), group_activity_path(@group, @activity), class: 'btn btn-default'
103 108
   = link_to t(:overview), group_activities_path(@group), class: 'btn btn-default'

+ 31 - 0
app/views/activities/edit_subgroups.html.haml

@@ -0,0 +1,31 @@
1
+.row
2
+  .alert.alert-info
3
+    = t 'activities.subgroups.only_present_people'
4
+.row
5
+  .col-md-12
6
+    = form_tag(group_activity_update_subgroups_path(@group, @activity)) do
7
+      %table.table
8
+        %tr
9
+          %th
10
+            Naam
11
+
12
+          %th
13
+            Huidig
14
+
15
+          %th
16
+            Nieuw
17
+
18
+        - @participants.each do |p|
19
+          %tr
20
+            %td
21
+              = p.person.full_name
22
+
23
+            %td
24
+              = p.subgroup&.name || '--'
25
+
26
+            %td
27
+              = select_tag("participant_subgroups[#{p.id}]", options_for_select(@subgroup_options, p.subgroup_id || 'nil'), class: 'form-control input-sm')
28
+
29
+      = submit_tag("Opslaan", class: 'btn btn-primary')
30
+      = link_to(edit_group_activity_path(@group, @activity), class: 'btn btn-default') do
31
+        = t :back

+ 28 - 0
app/views/activities/subgroup_editor.html.haml

@@ -0,0 +1,28 @@
1
+.row
2
+  .col-md-12
3
+    %table.table
4
+      %tr
5
+        %th
6
+          Naam
7
+
8
+        %th
9
+          Status
10
+
11
+        %th
12
+          Huidig
13
+
14
+        %th
15
+          Nieuw
16
+
17
+      - @participants.each do |p|
18
+        %td
19
+          = p.person.full_name
20
+
21
+        %td
22
+          = p.attending
23
+
24
+        %td
25
+          = p.subgroup.name
26
+
27
+        %td
28
+          TODO

+ 1 - 1
config/locales/aardbei_nl.yml

@@ -19,7 +19,7 @@ nl:
19 19
 
20 20
   areyousure: "Weet je het zeker?"
21 21
 
22
-  somethingbroke: "Er is iets misgegaan!"
22
+  somethingbroke: "Er is iets misgegaan! Neem contact op als dit blijft gebeuren."
23 23
 
24 24
   value_required: "Een verplichte vraag was leeg."
25 25
 

+ 5 - 0
config/locales/activities/nl.yml

@@ -98,6 +98,9 @@ nl:
98 98
       created: 'Subgroep aangemaakt.'
99 99
       create_failed: 'Kon subgroep niet opslaan!'
100 100
 
101
+      edit: 'Subgroepindeling bewerken'
102
+      edited: 'Subgroepindeling bijgewerkt.'
103
+
101 104
       update: 'Subgroep bijwerken'
102 105
       updated: 'Subgroep bijgewerkt.'
103 106
       update_failed: 'Kon subgroep niet bijwerken!'
@@ -105,3 +108,5 @@ nl:
105 108
       destroy: 'Subgroep verwijderen'
106 109
       destroyed: 'Subgroep verwijderd.'
107 110
       none: 'Er zijn geen subgroepen.'
111
+
112
+      only_present_people: 'Je ziet alleen maar mensen die zijn aangemeld in dit overzicht, omdat mensen die zijn afgemeld niet in een subgroep kunnen zitten.'

+ 3 - 0
config/routes.rb

@@ -56,6 +56,9 @@ Rails.application.routes.draw do
56 56
       post 'subgroups', to: 'activities#create_subgroup', as: 'create_subgroup'
57 57
       patch 'subgroups/:subgroup_id', to: 'activities#update_subgroup', as: 'update_subgroup'
58 58
       delete 'subgroups(/:subgroup_id)', to: 'activities#destroy_subgroup', as: 'destroy_subgroup'
59
+
60
+      get 'edit_subgroups', to: 'activities#edit_subgroups'
61
+      post 'update_subgroups', to: 'activities#update_subgroups'
59 62
     end
60 63
   end
61 64
   get 'my_groups', to: 'groups#user_groups', as: :user_groups